1919
2020package io .temporal .internal .testing ;
2121
22- import static org .junit .Assert .*;
22+ import static org .junit .Assert .assertEquals ;
23+ import static org .junit .Assert .assertTrue ;
24+ import static org .junit .Assert .fail ;
2325
2426import io .grpc .Status ;
2527import io .temporal .activity .Activity ;
@@ -353,68 +355,107 @@ public void e() {
353355 }
354356
355357 @ Test
356- public void testInvokingActivityByBaseInterface () {
358+ public void testInvokingActivityByBaseInterface1 () {
357359 BImpl bImpl = new BImpl ();
358360 DImpl dImpl = new DImpl ();
359- EImpl eImpl = new EImpl ();
360- {
361- testEnvironment .registerActivitiesImplementations (bImpl , dImpl );
362- try {
363- testEnvironment .newActivityStub (A .class );
364- fail ("A doesn't implement activity" );
365- } catch (IllegalArgumentException e ) {
366- // expected as A doesn't implement any activity
367- }
368- B b = testEnvironment .newActivityStub (B .class );
369- b .a ();
370- b .b ();
371- A a = b ;
372- a .a ();
373- D d = testEnvironment .newActivityStub (D .class );
374- d .a ();
375- d .d ();
376- a = d ;
377- a .a ();
378- List <String > expectedB = new ArrayList <>();
379- expectedB .add ("a" );
380- expectedB .add ("b" );
381- expectedB .add ("a" );
382- assertEquals (expectedB , bImpl .invocations );
383-
384- List <String > expectedD = new ArrayList <>();
385- expectedD .add ("a" );
386- expectedD .add ("d" );
387- expectedD .add ("a" );
388- assertEquals (expectedD , dImpl .invocations );
361+ testEnvironment .registerActivitiesImplementations (bImpl , dImpl );
362+ try {
363+ testEnvironment .newActivityStub (A .class );
364+ fail ("A doesn't implement activity" );
365+ } catch (IllegalArgumentException e ) {
366+ // expected as A doesn't implement any activity
389367 }
390- {
391- testEnvironment .registerActivitiesImplementations (eImpl );
392- E e = testEnvironment .newActivityStub (E .class );
393- e .a ();
394- e .d ();
395- e .e ();
396- D d = testEnvironment .newActivityStub (D .class );
397- d .a ();
398- d .d ();
399- List <String > expectedE = new ArrayList <>();
400- expectedE .add ("a" );
401- expectedE .add ("d" );
402- expectedE .add ("e" );
403- expectedE .add ("a" );
404- expectedE .add ("d" );
405- assertEquals (expectedE , eImpl .invocations );
368+ B b = testEnvironment .newActivityStub (B .class );
369+ b .a ();
370+ b .b ();
371+ A a = b ;
372+ a .a ();
373+ D d = testEnvironment .newActivityStub (D .class );
374+ d .a ();
375+ d .d ();
376+ a = d ;
377+ a .a ();
378+ List <String > expectedB = new ArrayList <>();
379+ expectedB .add ("a" );
380+ expectedB .add ("b" );
381+ expectedB .add ("a" );
382+ assertEquals (expectedB , bImpl .invocations );
383+
384+ List <String > expectedD = new ArrayList <>();
385+ expectedD .add ("a" );
386+ expectedD .add ("d" );
387+ expectedD .add ("a" );
388+ assertEquals (expectedD , dImpl .invocations );
389+ }
390+
391+ @ Test
392+ public void testInvokingActivityByBaseInterface1CallRegisterTwice () {
393+ BImpl bImpl = new BImpl ();
394+ DImpl dImpl = new DImpl ();
395+ testEnvironment .registerActivitiesImplementations (bImpl );
396+ testEnvironment .registerActivitiesImplementations (dImpl );
397+ try {
398+ testEnvironment .newActivityStub (A .class );
399+ fail ("A doesn't implement activity" );
400+ } catch (IllegalArgumentException e ) {
401+ // expected as A doesn't implement any activity
406402 }
403+ B b = testEnvironment .newActivityStub (B .class );
404+ b .a ();
405+ b .b ();
406+ A a = b ;
407+ a .a ();
408+ D d = testEnvironment .newActivityStub (D .class );
409+ d .a ();
410+ d .d ();
411+ a = d ;
412+ a .a ();
413+ List <String > expectedB = new ArrayList <>();
414+ expectedB .add ("a" );
415+ expectedB .add ("b" );
416+ expectedB .add ("a" );
417+ assertEquals (expectedB , bImpl .invocations );
418+
419+ List <String > expectedD = new ArrayList <>();
420+ expectedD .add ("a" );
421+ expectedD .add ("d" );
422+ expectedD .add ("a" );
423+ assertEquals (expectedD , dImpl .invocations );
407424 }
408425
409426 @ Test
410- public void testDuplicates () {
427+ public void testInvokingActivityByBaseInterface2 () {
428+ EImpl eImpl = new EImpl ();
429+ testEnvironment .registerActivitiesImplementations (eImpl );
430+ E e = testEnvironment .newActivityStub (E .class );
431+ e .a ();
432+ e .d ();
433+ e .e ();
434+ D d = testEnvironment .newActivityStub (D .class );
435+ d .a ();
436+ d .d ();
437+ List <String > expectedE = new ArrayList <>();
438+ expectedE .add ("a" );
439+ expectedE .add ("d" );
440+ expectedE .add ("e" );
441+ expectedE .add ("a" );
442+ expectedE .add ("d" );
443+ assertEquals (expectedE , eImpl .invocations );
444+ }
445+
446+ @ Test
447+ public void testDuplicates1 () {
411448 try {
412449 CImpl cImpl = new CImpl ();
413450 testEnvironment .registerActivitiesImplementations (cImpl );
414451 } catch (IllegalArgumentException e ) {
415452 assertTrue (e .getMessage ().contains ("A.a()" ));
416453 assertTrue (e .getMessage ().contains ("Duplicated" ));
417454 }
455+ }
456+
457+ @ Test
458+ public void testDuplicates2 () {
418459 DImpl dImpl = new DImpl ();
419460 EImpl eImpl = new EImpl ();
420461 try {
@@ -424,4 +465,17 @@ public void testDuplicates() {
424465 assertTrue (e .getMessage ().contains ("already registered" ));
425466 }
426467 }
468+
469+ @ Test
470+ public void testDuplicates2CallRegisterTwice () {
471+ DImpl dImpl = new DImpl ();
472+ EImpl eImpl = new EImpl ();
473+ try {
474+ testEnvironment .registerActivitiesImplementations (dImpl );
475+ testEnvironment .registerActivitiesImplementations (eImpl );
476+ } catch (IllegalArgumentException e ) {
477+ assertTrue (e .getMessage ().contains ("a" ));
478+ assertTrue (e .getMessage ().contains ("already registered" ));
479+ }
480+ }
427481}
0 commit comments