Skip to content

Commit 48f66e6

Browse files
authored
Add unit tests to ActivityCompletionException (#949)
1 parent d3eb1bd commit 48f66e6

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
7+
* except in compliance with the License. A copy of the License is located at
8+
*
9+
* <p>http://aws.amazon.com/apache2.0
10+
*
11+
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.client;
16+
17+
import static junit.framework.TestCase.*;
18+
import static org.mockito.Mockito.*;
19+
20+
import com.uber.cadence.WorkflowExecution;
21+
import com.uber.cadence.activity.ActivityTask;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
25+
public class ActivityCompletionExceptionTest {
26+
27+
private ActivityTask mockTask;
28+
private WorkflowExecution mockExecution;
29+
30+
@Before
31+
public void setUp() {
32+
// Set up mock objects for testing
33+
mockTask = mock(ActivityTask.class);
34+
mockExecution = mock(WorkflowExecution.class);
35+
36+
when(mockTask.getWorkflowExecution()).thenReturn(mockExecution);
37+
when(mockTask.getActivityType()).thenReturn("TestActivityType");
38+
when(mockTask.getActivityId()).thenReturn("TestActivityId");
39+
}
40+
41+
@Test
42+
public void testConstructorWithActivityTask() {
43+
ActivityCompletionException exception = new ActivityCompletionException(mockTask);
44+
45+
assertEquals(mockExecution, exception.getExecution());
46+
assertEquals("TestActivityType", exception.getActivityType());
47+
assertEquals("TestActivityId", exception.getActivityId());
48+
assertNull(exception.getCause());
49+
}
50+
51+
@Test
52+
public void testConstructorWithActivityTaskAndCause() {
53+
Throwable cause = new Throwable("TestCause");
54+
ActivityCompletionException exception = new ActivityCompletionException(mockTask, cause);
55+
56+
assertEquals(mockExecution, exception.getExecution());
57+
assertEquals("TestActivityType", exception.getActivityType());
58+
assertEquals("TestActivityId", exception.getActivityId());
59+
assertEquals(cause, exception.getCause());
60+
}
61+
62+
@Test
63+
public void testConstructorWithActivityIdAndCause() {
64+
Throwable cause = new Throwable("TestCause");
65+
ActivityCompletionException exception =
66+
new ActivityCompletionException("TestActivityId", cause);
67+
68+
assertNull(exception.getExecution());
69+
assertNull(exception.getActivityType());
70+
assertEquals("TestActivityId", exception.getActivityId());
71+
assertEquals(cause, exception.getCause());
72+
}
73+
74+
@Test
75+
public void testConstructorWithCauseOnly() {
76+
Throwable cause = new Throwable("TestCause");
77+
ActivityCompletionException exception = new ActivityCompletionException(cause);
78+
79+
assertNull(exception.getExecution());
80+
assertNull(exception.getActivityType());
81+
assertNull(exception.getActivityId());
82+
assertEquals(cause, exception.getCause());
83+
}
84+
85+
@Test
86+
public void testDefaultConstructor() {
87+
ActivityCompletionException exception = new ActivityCompletionException();
88+
89+
assertNull(exception.getExecution());
90+
assertNull(exception.getActivityType());
91+
assertNull(exception.getActivityId());
92+
assertNull(exception.getCause());
93+
}
94+
95+
@Test
96+
public void testExceptionMessageWithActivityTaskAndCause() {
97+
Throwable cause = new Throwable("TestCause");
98+
ActivityCompletionException exception = new ActivityCompletionException(mockTask, cause);
99+
100+
String expectedMessage =
101+
"Execution=" + mockExecution + ", ActivityType=TestActivityType, ActivityID=TestActivityId";
102+
assertEquals(expectedMessage, exception.getMessage());
103+
}
104+
105+
@Test
106+
public void testExceptionMessageWithActivityIdAndCause() {
107+
Throwable cause = new Throwable("TestCause");
108+
ActivityCompletionException exception =
109+
new ActivityCompletionException("TestActivityId", cause);
110+
111+
String expectedMessage = "ActivityIdTestActivityId";
112+
assertEquals(expectedMessage, exception.getMessage());
113+
}
114+
}

0 commit comments

Comments
 (0)