Skip to content

Commit

Permalink
reading of annotation not takes the executed test class into account …
Browse files Browse the repository at this point in the history
…and not the class where the test method is declared (fixes #171)
  • Loading branch information
Jan Schäfer committed Dec 21, 2015
1 parent efd0652 commit 94ca713
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The `@Table` annotation to format step parameters as tables has been extended wi

## Fixed Issues

* Fixed the issue that tags of subclasses would not be visible on scenarios of superclasses [#171](https://github.com/TNG/JGiven/issues/171)
* Fixed the issue that exceptions called within step methods are captured [#173](https://github.com/TNG/JGiven/issues/173)

# v0.9.5
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.10.0-SNAPSHOT
version=0.10.0
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public void wireSteps( CanWire canWire ) {
executor.wireSteps( canWire );
}

public ScenarioBase startScenario( Method method, List<NamedArgument> arguments ) {
public ScenarioBase startScenario( Class<?> testClass, Method method, List<NamedArgument> arguments ) {
performInitialization();
executor.startScenario( method, arguments );
executor.startScenario( testClass, method, arguments );
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum State {
* @param method the method that started the scenario
* @param arguments the test arguments with their parameter names
*/
void startScenario( Method method, List<NamedArgument> arguments );
void startScenario( Class<?> testClass, Method method, List<NamedArgument> arguments );

void setListener( ScenarioListener listener );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ public void scenarioFailed( Throwable e ) {
}

@Override
public void scenarioStarted( Method method, List<NamedArgument> namedArguments ) {
readConfiguration( method.getDeclaringClass() );
readAnnotations( method );
public void scenarioStarted( Class<?> testClass, Method method, List<NamedArgument> namedArguments ) {
readConfiguration( testClass );
readAnnotations( testClass, method );
setParameterNames( getNames( namedArguments ) );

// must come at last
Expand Down Expand Up @@ -328,7 +328,7 @@ private void readConfiguration( Class<?> testClass ) {
configuration = ConfigurationUtil.getConfiguration( testClass );
}

private void readAnnotations( Method method ) {
private void readAnnotations( Class<?> testClass, Method method ) {
String scenarioDescription = method.getName();

if( method.isAnnotationPresent( Description.class ) ) {
Expand All @@ -348,7 +348,7 @@ private void readAnnotations( Method method ) {
}

if( scenarioCaseModel.getCaseNr() == 1 ) {
addTags( method.getDeclaringClass().getAnnotations() );
addTags( testClass.getAnnotations() );
addTags( method.getAnnotations() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ public void startScenario( String description ) {
* @param arguments the test arguments with their parameter names
*/
@Override
public void startScenario( Method method, List<NamedArgument> arguments ) {
listener.scenarioStarted( method, arguments );
public void startScenario( Class<?> testClass, Method method, List<NamedArgument> arguments ) {
listener.scenarioStarted( testClass, method, arguments );

if( method.isAnnotationPresent( Pending.class ) ) {
Pending annotation = method.getAnnotation( Pending.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void scenarioFailed( Throwable e ) {}
public void scenarioStarted( String string ) {}

@Override
public void scenarioStarted( Method method, List<NamedArgument> arguments ) {}
public void scenarioStarted( Class<?> testClass, Method method, List<NamedArgument> arguments ) {}

@Override
public void stepMethodInvoked( Method method, List<NamedArgument> arguments, InvocationMode mode, boolean hasNestedSteps ) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ScenarioListener {

void scenarioStarted( String string );

void scenarioStarted( Method method, List<NamedArgument> arguments );
void scenarioStarted( Class<?> testClass, Method method, List<NamedArgument> arguments );

void stepMethodInvoked( Method method, List<NamedArgument> arguments, InvocationMode mode, boolean hasNestedSteps );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ConfigurationTest extends ScenarioTestBase<ConfigurationTest.FooSta
@Test
public void testFormatterConfiguration() throws Throwable {
getScenario().setModel( new ReportModel() );
getScenario().startScenario( ConfigurationTest.class.getMethod( "testFormatterConfiguration" ),
getScenario().startScenario( this.getClass(), ConfigurationTest.class.getMethod( "testFormatterConfiguration" ),
Collections.<NamedArgument>emptyList() );
given().some_step( new FooParam() );
given().another_step( new FooParam() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.*;

import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.MethodRule;
Expand Down Expand Up @@ -112,7 +107,7 @@ protected void starting( Statement base, FrameworkMethod testMethod, Object targ
scenario.setModel( reportModel );
scenario.getExecutor().injectSteps( target );

scenario.startScenario( testMethod.getMethod(), getNamedArguments( base, testMethod, target ) );
scenario.startScenario( target.getClass(), testMethod.getMethod(), getNamedArguments( base, testMethod, target ) );

// inject state from the test itself
scenario.getExecutor().readScenarioState( target );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tngtech.jgiven.junit.tags;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import com.tngtech.jgiven.junit.ScenarioTest;

public abstract class AbstractScenarioForTestingTagInheritance<G, W, T> extends ScenarioTest<G, W, T> {

@Test
public void ensure_all_tags_are_found() throws Throwable {
getScenario().finished();

List<String> tagIds = getScenario().getModel().getLastScenarioModel().getTagIds();
assertThat( tagIds ).containsAll( Arrays.asList( "TestTag" ) );

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tngtech.jgiven.junit.tags;

@TestTag
public class ClassImplementingAbstractScenario
extends
AbstractScenarioForTestingTagInheritance<ClassImplementingAbstractScenario.GivenStep<?>, ClassImplementingAbstractScenario.GivenStep<?>, ClassImplementingAbstractScenario.GivenStep<?>> {

public static class GivenStep<T> {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tngtech.jgiven.junit.tags;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import com.tngtech.jgiven.annotation.IsTag;

@IsTag(name = "Security")
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface TestTag {

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onTestStart( ITestResult paramITestResult ) {
scenario.getExecutor().injectSteps( instance );

Method method = paramITestResult.getMethod().getConstructorOrMethod().getMethod();
scenario.startScenario( method, getArgumentsFrom( method, paramITestResult ) );
scenario.startScenario( instance.getClass(), method, getArgumentsFrom( method, paramITestResult ) );

// inject state from the test itself
scenario.getExecutor().readScenarioState( instance );
Expand Down

0 comments on commit 94ca713

Please sign in to comment.