Skip to content

Commit 4f39f33

Browse files
authored
Added tests for LocalActivityOptions (#978)
1 parent a59a23c commit 4f39f33

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
*
3+
* * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* *
5+
* * Modifications copyright (C) 2017 Uber Technologies, Inc.
6+
* *
7+
* * Licensed under the Apache License, Version 2.0 (the "License"). You may not
8+
* * use this file except in compliance with the License. A copy of the License is
9+
* * located at
10+
* *
11+
* * http://aws.amazon.com/apache2.0
12+
* *
13+
* * or in the "license" file accompanying this file. This file is distributed on
14+
* * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15+
* * express or implied. See the License for the specific language governing
16+
* * permissions and limitations under the License.
17+
*
18+
*/
19+
20+
package com.uber.cadence.activity;
21+
22+
import static org.junit.Assert.assertEquals;
23+
24+
import com.uber.cadence.common.RetryOptions;
25+
import java.time.Duration;
26+
import java.util.Arrays;
27+
import java.util.Collection;
28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
30+
import org.junit.runners.Parameterized;
31+
32+
// This test is separated into its own file because it uses the Parameterized runner
33+
@RunWith(Parameterized.class)
34+
public class LocalActivityOptionsEqualsTest {
35+
36+
private final LocalActivityOptions options1;
37+
// In the java equals method the `other` parameter is of type Object
38+
private final Object options2;
39+
private final boolean equals;
40+
41+
public LocalActivityOptionsEqualsTest(
42+
String name, LocalActivityOptions options1, Object options2, boolean equals) {
43+
this.options1 = options1;
44+
this.options2 = options2;
45+
this.equals = equals;
46+
}
47+
48+
@Parameterized.Parameters(name = "{index}: {0}")
49+
public static Collection<Object[]> data() {
50+
LocalActivityOptions options = LocalActivityOptionsTest.createOptions();
51+
52+
return Arrays.asList(
53+
new Object[] {
54+
"Same object", options, options, true,
55+
},
56+
new Object[] {
57+
"Other is null", options, null, false,
58+
},
59+
new Object[] {
60+
"Other is not instance of LocalActivityOptions", options, new Object(), false,
61+
},
62+
new Object[] {
63+
"Emtpy equals empty",
64+
new LocalActivityOptions.Builder().build(),
65+
new LocalActivityOptions.Builder().build(),
66+
true
67+
},
68+
new Object[] {
69+
"Unset property on localActivityOptions is checked not equal",
70+
new LocalActivityOptions.Builder().build(),
71+
new LocalActivityOptions.Builder()
72+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
73+
.build(),
74+
false
75+
},
76+
new Object[] {
77+
"Property on localActivityOptions is checked equals",
78+
new LocalActivityOptions.Builder()
79+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
80+
.build(),
81+
new LocalActivityOptions.Builder()
82+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
83+
.build(),
84+
true
85+
},
86+
new Object[] {
87+
"Property on localActivityOptions is checked not equal",
88+
new LocalActivityOptions.Builder()
89+
.setScheduleToCloseTimeout(Duration.ofSeconds(1))
90+
.build(),
91+
new LocalActivityOptions.Builder()
92+
.setScheduleToCloseTimeout(Duration.ofSeconds(2))
93+
.build(),
94+
false
95+
},
96+
new Object[] {
97+
"retryOptions property not equal",
98+
new LocalActivityOptions.Builder()
99+
.setRetryOptions(
100+
new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(1)).build())
101+
.build(),
102+
new LocalActivityOptions.Builder()
103+
.setRetryOptions(
104+
new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(2)).build())
105+
.build(),
106+
false
107+
});
108+
}
109+
110+
@Test
111+
public void testEquals() {
112+
boolean got = options1.equals(options2);
113+
assertEquals(equals, got);
114+
}
115+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
*
3+
* * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* *
5+
* * Modifications copyright (C) 2017 Uber Technologies, Inc.
6+
* *
7+
* * Licensed under the Apache License, Version 2.0 (the "License"). You may not
8+
* * use this file except in compliance with the License. A copy of the License is
9+
* * located at
10+
* *
11+
* * http://aws.amazon.com/apache2.0
12+
* *
13+
* * or in the "license" file accompanying this file. This file is distributed on
14+
* * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15+
* * express or implied. See the License for the specific language governing
16+
* * permissions and limitations under the License.
17+
*
18+
*/
19+
20+
package com.uber.cadence.activity;
21+
22+
import static org.junit.Assert.assertNotEquals;
23+
24+
import com.uber.cadence.common.RetryOptions;
25+
import java.time.Duration;
26+
import junit.framework.TestCase;
27+
import org.junit.Test;
28+
29+
public class LocalActivityOptionsTest extends TestCase {
30+
31+
@Test
32+
public void testTestToString() {
33+
String asString = createOptions().toString();
34+
35+
final String expected =
36+
"LocalActivityOptions{"
37+
+ "scheduleToCloseTimeout=PT2M3S, "
38+
+ "retryOptions=RetryOptions{"
39+
+ "initialInterval=PT2M3S, "
40+
+ "backoffCoefficient=0.0, "
41+
+ "expiration=null, "
42+
+ "maximumAttempts=43, "
43+
+ "maximumInterval=null, "
44+
+ "doNotRetry=null"
45+
+ "}}";
46+
47+
assertEquals(expected, asString);
48+
}
49+
50+
@Test
51+
public void testTestHashCode() {
52+
LocalActivityOptions options1 = createOptions(123);
53+
LocalActivityOptions options2 = createOptions(456);
54+
55+
// The hash code of different objects should be different
56+
assertNotEquals(options1.hashCode(), options2.hashCode());
57+
}
58+
59+
public static LocalActivityOptions createOptions() {
60+
return createOptions(123);
61+
}
62+
63+
public static LocalActivityOptions createOptions(int initialRetryInterval) {
64+
RetryOptions retryOptions =
65+
new RetryOptions.Builder()
66+
.setInitialInterval(Duration.ofSeconds(initialRetryInterval))
67+
.setMaximumAttempts(43)
68+
.build();
69+
70+
return new LocalActivityOptions.Builder()
71+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
72+
.setRetryOptions(retryOptions)
73+
.build();
74+
}
75+
}

0 commit comments

Comments
 (0)