Skip to content

Commit

Permalink
Update mock code for exception test
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekmjain committed Sep 5, 2024
1 parent f3f61d6 commit 2162167
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.ConcurrentHashMap;

import org.apache.hadoop.fs.Path;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -82,7 +83,6 @@ protected void submitJob(List<WorkUnit> workUnits)
public void setUp() throws Exception {
mockServiceStubs = mock(WorkflowServiceStubs.class);
mockClient = mock(WorkflowClient.class);
mockStub = mock(WorkflowStub.class);
mockExecutionInfo = mock(WorkflowExecutionInfo.class);
DescribeWorkflowExecutionResponse mockResponse = mock(DescribeWorkflowExecutionResponse.class);
WorkflowServiceGrpc.WorkflowServiceBlockingStub mockBlockingStub = mock(WorkflowServiceGrpc.WorkflowServiceBlockingStub.class);
Expand All @@ -95,8 +95,6 @@ public void setUp() throws Exception {
.thenReturn(mockServiceStubs);
mockWorkflowClientFactory.when(() -> TemporalWorkflowClientFactory.createClientInstance(Mockito.any(), Mockito.anyString()))
.thenReturn(mockClient);
when(mockClient.newUntypedWorkflowStub(Mockito.anyString())).thenReturn(mockStub);
when(mockStub.getExecution()).thenReturn(WorkflowExecution.getDefaultInstance());

jobProperties = new Properties();
jobProperties.setProperty(ConfigurationKeys.FS_URI_KEY, "file:///");
Expand All @@ -107,6 +105,10 @@ public void setUp() throws Exception {

@BeforeMethod
public void methodSetUp() throws Exception {
mockStub = mock(WorkflowStub.class);
when(mockClient.newUntypedWorkflowStub(Mockito.anyString())).thenReturn(mockStub);
when(mockStub.getExecution()).thenReturn(WorkflowExecution.getDefaultInstance());

File tmpDir = Files.createTempDir();
String basePath = tmpDir.getAbsolutePath();
Path appWorkDir = new Path(basePath, "testAppWorkDir");
Expand Down Expand Up @@ -178,5 +180,7 @@ public void testCancelWorkflowFetchStatusThrowsException() throws Exception {
jobLauncher.executeCancellation();

verify(mockStub, times(1)).cancel();

Mockito.reset(mockExecutionInfo);
}
}

0 comments on commit 2162167

Please sign in to comment.