11package testjavaimplementation ;
22
33import com .mendix .core .Core ;
4- import com .mendix .systemwideinterfaces .core .IContext ;
54import org .junit .After ;
65import org .junit .Before ;
76import org .junit .Test ;
87import unittesting .TestExecutionContext ;
8+ import unittesting .activities .AssertActivity ;
99
1010import static org .junit .Assert .*;
1111
1212public class TestExecutionContextTest {
13- private final IContext context = Core . createSystemContext () ;
13+ private static final String FAILURE_MESSAGE = "This is a failure message" ;
1414 private TestExecutionContext testExecutionContext ;
1515
1616 @ Before
1717 public void setup () {
18- this .testExecutionContext = new TestExecutionContext (context , "ExampleMicroflow" );
18+ this .testExecutionContext = new TestExecutionContext ();
1919 }
2020
2121 @ After
2222 public void tearDown () {
23- this .testExecutionContext .delete ();
2423 this .testExecutionContext = null ;
2524 }
2625
27- @ Test
28- public void testExecutionContextShouldInitializeUnitTestContext () {
29- assertNotNull (this .testExecutionContext .getUnitTestContext ());
30- }
31-
3226 @ Test
3327 public void hasFailedAssertionShouldBeFalseByDefault () {
34- assertFalse (this .testExecutionContext .hasFailedAssertion (context ));
28+ assertFalse (this .testExecutionContext .hasFailedAssertion ());
3529 }
3630
3731 @ Test
3832 public void hasFailedAssertionShouldBeFalseWhenAllAssertionsPassed () {
39- this .testExecutionContext .collectAssertion (context , "Passed 1" , true , null );
40- this .testExecutionContext .collectAssertion (context , "Passed 2" , true , null );
33+ this .testExecutionContext .collectAssertion ("Passed 1" , true , null );
34+ this .testExecutionContext .collectAssertion ("Passed 2" , true , null );
4135
42- assertFalse (this .testExecutionContext .hasFailedAssertion (context ));
36+ assertFalse (this .testExecutionContext .hasFailedAssertion ());
4337 }
4438
4539 @ Test
4640 public void hasFailedAssertionShouldBeTrueWhenCollectingFailedAssertion () {
47- this .testExecutionContext .collectAssertion (context , "Passed" , true , null );
48- this .testExecutionContext .collectAssertion (context , "Failed" , false , null );
41+ this .testExecutionContext .collectAssertion ("Passed" , true , null );
42+ this .testExecutionContext .collectAssertion ("Failed" , false , null );
43+
44+ assertTrue (this .testExecutionContext .hasFailedAssertion ());
45+ }
46+
47+ @ Test
48+ public void assertActivityShouldContainFailureMessageWhenCollectingFailedAssertion () {
49+ AssertActivity assertion = this .testExecutionContext .collectAssertion ("Failed" , false , FAILURE_MESSAGE );
50+
51+ assertEquals (FAILURE_MESSAGE , assertion .getMessage ());
52+ }
4953
50- assertTrue (this .testExecutionContext .hasFailedAssertion (context ));
54+ @ Test
55+ public void assertActivityShouldNotContainFailureMessageWhenCollectingPassedAssertion () {
56+ AssertActivity assertion = this .testExecutionContext .collectAssertion ("Passed" , true , FAILURE_MESSAGE );
57+
58+ assertNull (assertion .getMessage ());
5159 }
5260
61+
5362 @ Test
5463 public void getLastStepShouldBeNullByDefault () {
5564 assertNull (this .testExecutionContext .getLastStep ());
@@ -65,67 +74,67 @@ public void getLastStepShouldReturnLastCollectedStep() {
6574
6675 @ Test
6776 public void getFailureReasonsShouldBeNullByDefault () {
68- assertEquals (0 , this .testExecutionContext .getFailureReasons (context ).size ());
77+ assertEquals (0 , this .testExecutionContext .getFailureReasons ().size ());
6978 }
7079
7180 @ Test
7281 public void getFailureReasonsShouldBeNullIfTestPassed () {
7382 this .testExecutionContext .collectStart (true , null );
74- this .testExecutionContext .collectAssertion (context , "Passed 1" , true , null );
75- this .testExecutionContext .collectAssertion (context , "Passed 2" , true , null );
83+ this .testExecutionContext .collectAssertion ("Passed 1" , true , null );
84+ this .testExecutionContext .collectAssertion ("Passed 2" , true , null );
7685 this .testExecutionContext .collectEnd (true , null );
7786
78- assertEquals (0 , this .testExecutionContext .getFailureReasons (context ).size ());
87+ assertEquals (0 , this .testExecutionContext .getFailureReasons ().size ());
7988 }
8089
8190 @ Test
8291 public void getFailureReasonsShouldIncludeFailedStart () {
8392 this .testExecutionContext .collectStart (false , "Start failed" );
8493
85- assertEquals (1 , this .testExecutionContext .getFailureReasons (context ).size ());
94+ assertEquals (1 , this .testExecutionContext .getFailureReasons ().size ());
8695 }
8796
8897 @ Test
8998 public void getFailureReasonsShouldIncludeFailedEnd () {
9099 this .testExecutionContext .collectEnd (false , "End failed" );
91100
92- assertEquals (1 , this .testExecutionContext .getFailureReasons (context ).size ());
101+ assertEquals (1 , this .testExecutionContext .getFailureReasons ().size ());
93102 }
94103
95104 @ Test
96105 public void getFailureReasonsShouldIncludeFailedAssertion () {
97- this .testExecutionContext .collectAssertion (context , "Passed" , true , null );
98- this .testExecutionContext .collectAssertion (context , "Failed 1" , false , null );
99- this .testExecutionContext .collectAssertion (context , "Failed 2" , false , null );
106+ this .testExecutionContext .collectAssertion ("Passed" , true , null );
107+ this .testExecutionContext .collectAssertion ("Failed 1" , false , null );
108+ this .testExecutionContext .collectAssertion ("Failed 2" , false , null );
100109
101- assertEquals (1 , this .testExecutionContext .getFailureReasons (context ).size ());
110+ assertEquals (1 , this .testExecutionContext .getFailureReasons ().size ());
102111 }
103112
104113 @ Test
105114 public void getFailureReasonsShouldIncludeUncaughtException () {
106115 this .testExecutionContext .collectException (new Exception ("Example Exception" ));
107116
108- assertEquals (1 , this .testExecutionContext .getFailureReasons (context ).size ());
117+ assertEquals (1 , this .testExecutionContext .getFailureReasons ().size ());
109118 }
110119
111120 @ Test
112121 public void getFailureReasonsShouldIncludeAllUniqueFailureReasons () {
113122 this .testExecutionContext .collectStart (false , "Start failed" );
114- this .testExecutionContext .collectAssertion (context , "Failed 1" , false , null );
115- this .testExecutionContext .collectAssertion (context , "Failed 2" , false , null );
123+ this .testExecutionContext .collectAssertion ("Failed 1" , false , null );
124+ this .testExecutionContext .collectAssertion ("Failed 2" , false , null );
116125 this .testExecutionContext .collectException (new Exception ("Test Exception" ));
117126 this .testExecutionContext .collectEnd (false , "End failed" );
118127
119- assertEquals (4 , this .testExecutionContext .getFailureReasons (context ).size ());
128+ assertEquals (4 , this .testExecutionContext .getFailureReasons ().size ());
120129 }
121130
122131 @ Test
123132 public void createTestActivitiesShouldContainAllCollectedTestActivities () {
124133 this .testExecutionContext .collectStart (true , "Started test" );
125134
126- this .testExecutionContext .collectAssertion (context , "Passed" , true , null );
127- this .testExecutionContext .collectAssertion (context , "Failed 1" , false , null );
128- this .testExecutionContext .collectAssertion (context , "Failed 2" , false , null );
135+ this .testExecutionContext .collectAssertion ("Passed" , true , null );
136+ this .testExecutionContext .collectAssertion ("Failed 1" , false , null );
137+ this .testExecutionContext .collectAssertion ("Failed 2" , false , null );
129138
130139 this .testExecutionContext .collectStep ("Step 1" );
131140 this .testExecutionContext .collectStep ("Step 2" );
@@ -134,6 +143,6 @@ public void createTestActivitiesShouldContainAllCollectedTestActivities() {
134143
135144 this .testExecutionContext .collectEnd (true , "Test ended successfully" );
136145
137- assertEquals (8 , this .testExecutionContext .createTestActivities (context , null ).size ());
146+ assertEquals (8 , this .testExecutionContext .createTestActivities (Core . createSystemContext () , null ).size ());
138147 }
139148}
0 commit comments