Skip to content

Commit

Permalink
Merge pull request #100 from TNG/pending-annotation
Browse files Browse the repository at this point in the history
Pending annotation
  • Loading branch information
janschaefer committed Aug 2, 2015
2 parents 477ded1 + 8609865 commit e7cadcd
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 105 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public @interface FeatureHtml5Report { }
## New Annotations

* Introduced the `@As` annotation that replaces the `@Description` annotation when used on step methods and test methods. The `@Description` annotation should only be used for descriptions of test classes.
* Added `@Pending` annotation to replace the `@NotImplementedYet` annotation.

## Backwards incompatible JSON Model Changes

* The field `notImplementedYet` of the `ScenarioModel` was renamed to `pending`
* The `StepStatus` `NOT_IMPLEMENTED_YET` was renamed to `PENDING`.

Note: in general, backwards incompatible model changes should be no problem, as long as you use the same version for all JGiven modules (core, html5-report, maven-plugin).

# v0.7.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Whether values should be ignored.
* If true only a single tag is created for the annotation and the value does not appear in the report.
* This is useful if the value is used as an internal comment
* @see NotImplementedYet
* @see Pending
*/
boolean ignoreValue() default false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
* }
* </pre>
*
* @deprecated use {@link Pending} instead
*/
@Deprecated
@Documented
@Inherited
@Retention( RUNTIME )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Marks methods of step definitions as not implemented yet.
* Such steps will not be executed, but will appear in
* the report as not implemented yet.
* the report as pending.
* <p>
* This is useful if one already wants to define the scenario without
* already implementing all steps, for example, to verify that
Expand All @@ -29,12 +29,13 @@
*
* <h2>Example</h2>
* <pre>
* {@literal @}NotImplementedYet
* {@literal @}Pending
* public void my_cool_new_feature() {
*
* }
* </pre>
*
* @since 0.8.0
*/
@Documented
@Inherited
Expand All @@ -48,7 +49,7 @@
String value() default "";

/**
* Instead of only reporting not implemented yet steps,
* Instead of only reporting pending steps,
* the steps are actually executed.
* This is useful to see whether some steps fail, for example.
* Failing steps, however, have no influence on the overall test result.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tngtech.jgiven.exception;

/**
* @see com.tngtech.jgiven.annotation.NotImplementedYet
* @see com.tngtech.jgiven.annotation.Pending
*/
public class FailIfPassedException extends RuntimeException {
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,28 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import net.sf.cglib.proxy.Enhancer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.tngtech.jgiven.CurrentStep;
import com.tngtech.jgiven.annotation.AfterScenario;
import com.tngtech.jgiven.annotation.AfterStage;
import com.tngtech.jgiven.annotation.BeforeScenario;
import com.tngtech.jgiven.annotation.BeforeStage;
import com.tngtech.jgiven.annotation.Hidden;
import com.tngtech.jgiven.annotation.NotImplementedYet;
import com.tngtech.jgiven.annotation.ScenarioRule;
import com.tngtech.jgiven.annotation.ScenarioStage;
import com.tngtech.jgiven.annotation.*;
import com.tngtech.jgiven.attachment.Attachment;
import com.tngtech.jgiven.exception.FailIfPassedException;
import com.tngtech.jgiven.exception.JGivenUserException;
import com.tngtech.jgiven.impl.inject.ValueInjector;
import com.tngtech.jgiven.impl.intercept.InvocationMode;
import com.tngtech.jgiven.impl.intercept.NoOpScenarioListener;
import com.tngtech.jgiven.impl.intercept.ScenarioListener;
import com.tngtech.jgiven.impl.intercept.StandaloneStepMethodInterceptor;
import com.tngtech.jgiven.impl.intercept.StepMethodHandler;
import com.tngtech.jgiven.impl.intercept.*;
import com.tngtech.jgiven.impl.util.FieldCache;
import com.tngtech.jgiven.impl.util.ParameterNameUtil;
import com.tngtech.jgiven.impl.util.ReflectionUtil;
import com.tngtech.jgiven.impl.util.ReflectionUtil.MethodAction;
import com.tngtech.jgiven.integration.CanWire;
import com.tngtech.jgiven.report.model.NamedArgument;

import net.sf.cglib.proxy.Enhancer;

/**
* Main class of JGiven for executing scenarios.
*/
Expand Down Expand Up @@ -447,7 +436,17 @@ public void startScenario( String description ) {
public void startScenario( Method method, List<NamedArgument> arguments ) {
listener.scenarioStarted( method, arguments );

if( method.isAnnotationPresent( NotImplementedYet.class ) ) {
if( method.isAnnotationPresent( Pending.class ) ) {
Pending annotation = method.getAnnotation( Pending.class );

if( annotation.failIfPass() ) {
failIfPass();
} else if( !annotation.executeSteps() ) {
methodInterceptor.disableMethodExecution();
executeLifeCycleMethods = false;
}
suppressExceptions = true;
} else if( method.isAnnotationPresent( NotImplementedYet.class ) ) {
NotImplementedYet annotation = method.getAnnotation( NotImplementedYet.class );

if( annotation.failIfPass() ) {
Expand All @@ -458,6 +457,7 @@ public void startScenario( Method method, List<NamedArgument> arguments ) {
}
suppressExceptions = true;
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ public enum InvocationMode {
NORMAL,
FAILED,
SKIPPED,
NOT_IMPLEMENTED_YET;
PENDING;

public StepStatus toStepStatus() {
switch( this ) {
case NORMAL:
return StepStatus.PASSED;
case FAILED:
return StepStatus.FAILED;
case NOT_IMPLEMENTED_YET:
return StepStatus.NOT_IMPLEMENTED_YET;
case PENDING:
return StepStatus.PENDING;
case SKIPPED:
return StepStatus.SKIPPED;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.tngtech.jgiven.impl.intercept;

import static com.tngtech.jgiven.impl.intercept.InvocationMode.NORMAL;
import static com.tngtech.jgiven.impl.intercept.InvocationMode.NOT_IMPLEMENTED_YET;
import static com.tngtech.jgiven.impl.intercept.InvocationMode.SKIPPED;
import static com.tngtech.jgiven.impl.intercept.InvocationMode.*;

import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -11,8 +9,9 @@
import org.slf4j.LoggerFactory;

import com.tngtech.jgiven.annotation.NotImplementedYet;
import com.tngtech.jgiven.annotation.Pending;

public class StepMethodInterceptor {
public class StepMethodInterceptor {
private static final Logger log = LoggerFactory.getLogger( StepMethodInterceptor.class );

private StepMethodHandler scenarioMethodHandler;
Expand Down Expand Up @@ -41,9 +40,8 @@ public StepMethodInterceptor( StepMethodHandler scenarioMethodHandler, AtomicInt
this.stackDepth = stackDepth;
}


public final Object doIntercept(final Object receiver, Method method,
final Object[] parameters, Invoker invoker) throws Throwable {
public final Object doIntercept( final Object receiver, Method method,
final Object[] parameters, Invoker invoker ) throws Throwable {
long started = System.nanoTime();
InvocationMode mode = getInvocationMode( receiver, method );

Expand All @@ -52,14 +50,14 @@ public final Object doIntercept(final Object receiver, Method method,
scenarioMethodHandler.handleMethod( receiver, method, parameters, mode );
}

if( mode == SKIPPED || mode == NOT_IMPLEMENTED_YET ) {
if( mode == SKIPPED || mode == PENDING) {
return returnReceiverOrNull( receiver, method );
}

try {
stackDepth.incrementAndGet();
return invoker.proceed();
} catch (Exception e) {
} catch( Exception e ) {
return handleThrowable( receiver, method, e, System.nanoTime() - started );
} catch( AssertionError e ) {
return handleThrowable( receiver, method, e, System.nanoTime() - started );
Expand Down Expand Up @@ -107,8 +105,10 @@ protected InvocationMode getInvocationMode( Object receiver, Method method ) {
}

if( method.isAnnotationPresent( NotImplementedYet.class )
|| receiver.getClass().isAnnotationPresent( NotImplementedYet.class ) ) {
return NOT_IMPLEMENTED_YET;
|| receiver.getClass().isAnnotationPresent( NotImplementedYet.class )
|| method.isAnnotationPresent( Pending.class )
|| receiver.getClass().isAnnotationPresent( Pending.class ) ) {
return PENDING;
}

return NORMAL;
Expand All @@ -132,20 +132,16 @@ public StepMethodHandler getScenarioMethodHandler() {
return scenarioMethodHandler;
}


public AtomicInteger getStackDepth() {
return stackDepth;
}


public void setScenarioMethodHandler(StepMethodHandler scenarioMethodHandler) {
public void setScenarioMethodHandler( StepMethodHandler scenarioMethodHandler ) {
this.scenarioMethodHandler = scenarioMethodHandler;
}


public void setStackDepth(AtomicInteger stackDepth) {
public void setStackDepth( AtomicInteger stackDepth ) {
this.stackDepth = stackDepth;
}


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tngtech.jgiven.report.model;

public enum ExecutionStatus {
NONE_IMPLEMENTED,
SCENARIO_PENDING,
SUCCESS,
FAILED,
PARTIALLY_IMPLEMENTED;
SOME_STEPS_PENDING;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

final class ExecutionStatusCalculator extends ReportModelVisitor {
private int failedCount;
private int notImplementedCount;
private int pendingCount;
private int totalCount;
private ExecutionStatus status;

@Override
public void visit( ScenarioModel scenarioModel ) {
if(scenarioModel.isNotImplementedYet()) {
status = ExecutionStatus.NONE_IMPLEMENTED;
if(scenarioModel.isPending()) {
status = ExecutionStatus.SCENARIO_PENDING;
}
}

Expand All @@ -24,8 +24,8 @@ public void visit( ScenarioCaseModel scenarioCase ) {
public void visit( StepModel stepModel ) {
if( stepModel.isFailed() ) {
failedCount++;
} else if( stepModel.isNotImplementedYet() ) {
notImplementedCount++;
} else if( stepModel.isPending() ) {
pendingCount++;
}
totalCount++;
}
Expand All @@ -39,11 +39,11 @@ public ExecutionStatus executionStatus() {
return ExecutionStatus.FAILED;
}

if( notImplementedCount > 0 ) {
if( notImplementedCount < totalCount ) {
return ExecutionStatus.PARTIALLY_IMPLEMENTED;
if( pendingCount > 0 ) {
if( pendingCount < totalCount ) {
return ExecutionStatus.SOME_STEPS_PENDING;
}
return ExecutionStatus.NONE_IMPLEMENTED;
return ExecutionStatus.SCENARIO_PENDING;
}

return ExecutionStatus.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public List<ScenarioModel> getFailedScenarios() {
}

public List<ScenarioModel> getPendingScenarios() {
return getScenariosWithStatus(ExecutionStatus.NONE_IMPLEMENTED, ExecutionStatus.PARTIALLY_IMPLEMENTED);
return getScenariosWithStatus(ExecutionStatus.SCENARIO_PENDING, ExecutionStatus.SOME_STEPS_PENDING);
}

public List<ScenarioModel> getScenariosWithStatus(ExecutionStatus first, ExecutionStatus... rest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ private void readAnnotations( Method method ) {

scenarioStarted( scenarioDescription );

if( method.isAnnotationPresent( NotImplementedYet.class ) ) {
currentScenarioModel.setNotImplementedYet( true );
if( method.isAnnotationPresent( NotImplementedYet.class ) || method.isAnnotationPresent( Pending.class ) ) {
currentScenarioModel.setPending(true);
}

if( currentScenarioCase.getCaseNr() == 1 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ScenarioModel {
* A list of tag ids
*/
private Set<String> tagIds = Sets.newLinkedHashSet();
private boolean notImplementedYet;
private boolean pending;
private List<String> explicitParameters = Lists.newArrayList();
private List<String> derivedParameters = Lists.newArrayList();
private boolean casesAsTable;
Expand Down Expand Up @@ -142,12 +142,12 @@ public void setTagIds(Set<String> tagIds) {
this.tagIds = tagIds;
}

public boolean isNotImplementedYet() {
return notImplementedYet;
public boolean isPending() {
return pending;
}

public void setNotImplementedYet( boolean notImplementedYet ) {
this.notImplementedYet = notImplementedYet;
public void setPending(boolean pending) {
this.pending = pending;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void visit( ScenarioModel scenarioModel ) {
ExecutionStatus executionStatus = scenarioModel.getExecutionStatus();
if( executionStatus == ExecutionStatus.FAILED ) {
statistics.numFailedScenarios += 1;
} else if( executionStatus == ExecutionStatus.NONE_IMPLEMENTED || executionStatus == ExecutionStatus.PARTIALLY_IMPLEMENTED ) {
} else if( executionStatus == ExecutionStatus.SCENARIO_PENDING || executionStatus == ExecutionStatus.SOME_STEPS_PENDING) {
statistics.numPendingScenarios += 1;
} else {
statistics.numSuccessfulScenarios += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public StepModel addWords( Word... words ) {
return this;
}

public boolean isNotImplementedYet() {
return getStatus() == StepStatus.NOT_IMPLEMENTED_YET;
public boolean isPending() {
return getStatus() == StepStatus.PENDING;
}

public boolean isFailed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public enum StepStatus {
PASSED,
FAILED,
SKIPPED,
NOT_IMPLEMENTED_YET;
PENDING;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void visit( StepModel stepModel ) {
}
String rest = joinWords( words.subList( introWord, restSize ) );

if( stepModel.isNotImplementedYet() ) {
rest = withColor( Color.BLACK, true, Attribute.INTENSITY_FAINT, rest + " (not implemented yet)" );
if( stepModel.isPending() ) {
rest = withColor( Color.BLACK, true, Attribute.INTENSITY_FAINT, rest + " (pending)" );
} else if( stepModel.isSkipped() ) {
rest = withColor( Color.BLACK, true, Attribute.INTENSITY_FAINT, rest + " (skipped)" );
} else if( stepModel.isFailed() ) {
Expand Down
Loading

0 comments on commit e7cadcd

Please sign in to comment.