2020import java .io .PrintStream ;
2121import java .util .UUID ;
2222
23+ import static io .cucumber .core .backend .HookDefinition .HookType .BEFORE ;
2324import static io .cucumber .core .plugin .Bytes .bytes ;
25+ import static io .cucumber .core .plugin .TeamCityPluginTestStepDefinition .getAnnotationSourceReference ;
26+ import static io .cucumber .core .plugin .TeamCityPluginTestStepDefinition .getStackSourceReference ;
27+ import static java .nio .charset .StandardCharsets .UTF_8 ;
2428import static java .time .Clock .fixed ;
2529import static java .time .Instant .EPOCH ;
2630import static java .time .ZoneId .of ;
@@ -72,7 +76,7 @@ void should_handle_scenario_outline() {
7276 "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
7377 + "path/test.feature:5' name = 'examples name']\n " +
7478 "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
75- + "path/test.feature:7' name = 'Example #1.1']\n " +
79+ + "path/test.feature:7' name = '#1.1: name 1']\n " +
7680 "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
7781 "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
7882 + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n " +
@@ -83,9 +87,10 @@ void should_handle_scenario_outline() {
8387 "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'second step']\n "
8488 +
8589 "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
86- "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.1']\n " +
90+ "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.1: name 1']\n "
91+ +
8792 "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
88- + "path/test.feature:8' name = 'Example #1.2']\n " +
93+ + "path/test.feature:8' name = '#1.2: name 2']\n " +
8994 "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
9095 "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
9196 + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n " +
@@ -96,7 +101,8 @@ void should_handle_scenario_outline() {
96101 "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'third step']\n "
97102 +
98103 "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
99- "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.2']\n " +
104+ "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.2: name 2']\n "
105+ +
100106 "##teamcity[customProgressStatus testsCategory = '' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n "
101107 +
102108 "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'examples name']\n " +
@@ -121,7 +127,7 @@ void should_handle_nameless_attach_events() {
121127 .withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
122128 .withBackendSupplier (new StubBackendSupplier (
123129 singletonList (new StubHookDefinition (
124- (TestCaseState state ) -> state .attach ("A message" , "text/plain" , null ))),
130+ (TestCaseState state ) -> state .attach ("A message" . getBytes ( UTF_8 ) , "text/plain" , null ))),
125131 singletonList (new StubStepDefinition ("first step" )),
126132 emptyList ()))
127133 .build ()
@@ -168,7 +174,8 @@ void should_handle_attach_events() {
168174 .withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
169175 .withBackendSupplier (new StubBackendSupplier (
170176 singletonList (new StubHookDefinition (
171- (TestCaseState state ) -> state .attach ("A message" , "text/plain" , "message.txt" ))),
177+ (TestCaseState state ) -> state .attach ("A message" .getBytes (UTF_8 ), "text/plain" ,
178+ "message.txt" ))),
172179 singletonList (new StubStepDefinition ("first step" )),
173180 emptyList ()))
174181 .build ()
@@ -258,17 +265,17 @@ void should_print_error_message_for_before_hooks() {
258265 .withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
259266 .withBackendSupplier (new StubBackendSupplier (
260267 singletonList (
261- new StubHookDefinition (new StubException ("Step failed" )
268+ new StubHookDefinition (getAnnotationSourceReference (), BEFORE , new StubException ()
262269 .withStacktrace ("the stack trace" ))),
263270 singletonList (new StubStepDefinition ("first step" )),
264271 emptyList ()))
265272 .build ()
266273 .run ();
267274
268275 assertThat (out , bytes (containsString ("" +
269- "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '{stubbed location with details} ' captureStandardOutput = 'true' name = 'Before']\n "
276+ "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://io.cucumber.core.plugin.TeamCityPluginTestStepDefinition/beforeHook ' captureStandardOutput = 'true' name = 'Before(beforeHook) ']\n "
270277 +
271- "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step failed' details = 'Step failed |n\t the stack trace|n' name = 'Before']" )));
278+ "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step failed' details = 'stub exception |n\t the stack trace|n' name = 'Before(beforeHook) ']" )));
272279 }
273280
274281 @ Test
@@ -284,14 +291,14 @@ void should_print_location_hint_for_java_hooks() {
284291 .withAdditionalPlugins (new TeamCityPlugin (new PrintStream (out )))
285292 .withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
286293 .withBackendSupplier (new StubBackendSupplier (
287- singletonList (new StubHookDefinition ("com.example.HookDefinition.beforeHook()" )),
294+ singletonList (new StubHookDefinition (getAnnotationSourceReference (), BEFORE )),
288295 singletonList (new StubStepDefinition ("first step" )),
289296 emptyList ()))
290297 .build ()
291298 .run ();
292299
293300 assertThat (out , bytes (containsString ("" +
294- "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://com.example.HookDefinition /beforeHook' captureStandardOutput = 'true' name = 'Before(beforeHook)']\n " )));
301+ "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://io.cucumber.core.plugin.TeamCityPluginTestStepDefinition /beforeHook' captureStandardOutput = 'true' name = 'Before(beforeHook)']\n " )));
295302 }
296303
297304 @ Test
@@ -307,14 +314,14 @@ void should_print_location_hint_for_lambda_hooks() {
307314 .withAdditionalPlugins (new TeamCityPlugin (new PrintStream (out )))
308315 .withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
309316 .withBackendSupplier (new StubBackendSupplier (
310- singletonList (new StubHookDefinition ("com.example.HookDefinition.<init>(HookDefinition.java:12)" )),
317+ singletonList (new StubHookDefinition (getStackSourceReference (), BEFORE )),
311318 singletonList (new StubStepDefinition ("first step" )),
312319 emptyList ()))
313320 .build ()
314321 .run ();
315322
316323 assertThat (out , bytes (containsString ("" +
317- "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://com.example.HookDefinition/HookDefinition ' captureStandardOutput = 'true' name = 'Before(HookDefinition )']\n " )));
324+ "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://io.cucumber.core.plugin.TeamCityPluginTestStepDefinition/TeamCityPluginTestStepDefinition ' captureStandardOutput = 'true' name = 'Before(TeamCityPluginTestStepDefinition )']\n " )));
318325 }
319326
320327 @ Test
@@ -397,4 +404,5 @@ void should_print_comparison_failure_for_failed_assert_equal_with_prefix() {
397404 assertThat (out ,
398405 bytes (containsString ("expected = 'one value' actual = 'another value' name = 'first step']" )));
399406 }
407+
400408}
0 commit comments