Skip to content

Commit

Permalink
feat(#1218): add
Browse files Browse the repository at this point in the history
  • Loading branch information
phos-web committed Feb 7, 2025
1 parent bf7c846 commit 1f1d462
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.citrusframework.TestResult.RESULT.FAILURE;
import static org.citrusframework.TestResult.success;
import static org.citrusframework.util.TestUtils.WAIT_THREAD_PREFIX;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -176,15 +177,18 @@ public void doExecuteAsync(final TestContext context) {
}

@Test
public void testTestListenerEventsWithSuccessTestResult() {
public void testTestListenerEventsWithSuccessfulTestResult() {
TestListener testListenerMock = mock();
context.getTestListeners().addTestListener(testListenerMock);

BeforeTest beforeTestMock = mock();
List<BeforeTest> beforeTestListMock = new ArrayList<>(){{add(beforeTestMock);}};
context.setBeforeTest(beforeTestListMock);

TestAction testActionMock = mock();
List<TestAction> testActionListMock = new ArrayList<>(){{add(testActionMock);}};
fixture.setFinalActions(testActionListMock);

AfterTest afterTestMock = mock();
List<AfterTest> afterTestListMock = new ArrayList<>(){{add(afterTestMock);}};
context.setAfterTest(afterTestListMock);
Expand All @@ -206,28 +210,26 @@ public void testTestListenerEventsWithSuccessTestResult() {
verifyNoMoreInteractions(testListenerMock);
}

@Test()
@Test(expectedExceptions = TestCaseFailedException.class)
public void testTestListenerEventsWithFailedTestResult() {
TestAction testActionMock = mock();
// doThrow(CitrusRuntimeException.class).when(testActionMock).execute(context);
doThrow(CitrusRuntimeException.class).when(testActionMock).execute(context);
fixture.addTestAction(testActionMock);
TestListener testListenerMock = mock();
context.getTestListeners().addTestListener(testListenerMock);

BeforeTest beforeTestMock = mock();
List<BeforeTest> beforeTestListMock = new ArrayList<>(){{add(beforeTestMock);}};
context.setBeforeTest(beforeTestListMock);

List<TestAction> testActionListMock = new ArrayList<>(){{add(testActionMock);}};
fixture.setFinalActions(testActionListMock);

AfterTest afterTestMock = mock();
List<AfterTest> afterTestListMock = new ArrayList<>(){{add(afterTestMock);}};
context.setAfterTest(afterTestListMock);
// TestResult testResultMock = mock();
// fixture.setTestResult(testResultMock);
// when(testResultMock.isSuccess()).thenReturn(false);

fixture.doExecute(context);
CitrusRuntimeException citrusRuntimeExceptionMock = mock();
context.addException(citrusRuntimeExceptionMock);
fixture.finish(context);

InOrder inOrder = inOrder(testListenerMock);
Expand All @@ -237,7 +239,7 @@ public void testTestListenerEventsWithFailedTestResult() {
inOrder.verify(testListenerMock, times(1)).onTestFinish(fixture);
inOrder.verify(testListenerMock, times(1)).onFinalActionsStart(fixture);
inOrder.verify(testListenerMock, times(1)).onFinalActionsEnd(fixture);
inOrder.verify(testListenerMock, times(1)).onTestFailure(fixture, citrusRuntimeExceptionMock);
inOrder.verify(testListenerMock, times(1)).onTestFailure(fixture, fixture.getTestResult().getCause());
inOrder.verify(testListenerMock, times(1)).onBeforeSequenceAfterTest(fixture);
inOrder.verify(testListenerMock, times(1)).onAfterSequenceAfterTest(fixture);
inOrder.verify(testListenerMock, times(1)).onTestEnd(fixture);
Expand Down

0 comments on commit 1f1d462

Please sign in to comment.