Skip to content

Commit 4e75b0f

Browse files
committed
Added tests for LocalActivityOptions
1 parent a59a23c commit 4e75b0f

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
26+
import java.time.Duration;
27+
import java.util.Arrays;
28+
import java.util.Collection;
29+
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
import org.junit.runners.Parameterized;
33+
34+
// This test is separated into its own file because it uses the Parameterized runner
35+
@RunWith(Parameterized.class)
36+
public class LocalActivityOptionsEqualsTest {
37+
38+
private final LocalActivityOptions options1;
39+
// In the java equals method the `other` parameter is of type Object
40+
private final Object options2;
41+
private final boolean equals;
42+
43+
public LocalActivityOptionsEqualsTest(
44+
String name, LocalActivityOptions options1, Object options2, boolean equals) {
45+
this.options1 = options1;
46+
this.options2 = options2;
47+
this.equals = equals;
48+
}
49+
50+
@Parameterized.Parameters(name = "{index}: {0}")
51+
public static Collection<Object[]> data() {
52+
LocalActivityOptions options = LocalActivityOptionsTest.createOptions();
53+
54+
return Arrays.asList(
55+
new Object[]{
56+
"Same object", options, options, true,
57+
},
58+
new Object[]{
59+
"Other is null", options, null, false,
60+
},
61+
new Object[]{
62+
"Other is not instance of LocalActivityOptions", options, new Object(), false,
63+
},
64+
new Object[]{
65+
"Emtpy equals empty",
66+
new LocalActivityOptions.Builder().build(),
67+
new LocalActivityOptions.Builder().build(),
68+
true
69+
},
70+
new Object[]{
71+
"Unset property on localActivityOptions is checked not equal",
72+
new LocalActivityOptions.Builder().build(),
73+
new LocalActivityOptions.Builder()
74+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
75+
.build(),
76+
false
77+
},
78+
new Object[]{
79+
"Property on localActivityOptions is checked equals",
80+
new LocalActivityOptions.Builder()
81+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
82+
.build(),
83+
new LocalActivityOptions.Builder()
84+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
85+
.build(),
86+
true
87+
},
88+
new Object[]{
89+
"Property on localActivityOptions is checked not equal",
90+
new LocalActivityOptions.Builder()
91+
.setScheduleToCloseTimeout(Duration.ofSeconds(1))
92+
.build(),
93+
new LocalActivityOptions.Builder()
94+
.setScheduleToCloseTimeout(Duration.ofSeconds(2))
95+
.build(),
96+
false
97+
},
98+
new Object[]{
99+
"retryOptions property not equal",
100+
new LocalActivityOptions.Builder()
101+
.setRetryOptions(
102+
new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(1)).build())
103+
.build(),
104+
new LocalActivityOptions.Builder()
105+
.setRetryOptions(
106+
new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(2)).build())
107+
.build(),
108+
false
109+
});
110+
}
111+
112+
@Test
113+
public void testEquals() {
114+
boolean got = options1.equals(options2);
115+
assertEquals(equals, got);
116+
}
117+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
26+
import java.time.Duration;
27+
28+
import junit.framework.TestCase;
29+
import org.junit.Before;
30+
import org.junit.Test;
31+
32+
public class LocalActivityOptionsTest extends TestCase {
33+
34+
@Test
35+
public void testTestToString() {
36+
String asString = createOptions().toString();
37+
38+
final String expected =
39+
"LocalActivityOptions{"
40+
+ "scheduleToCloseTimeout=PT2M3S, "
41+
+ "retryOptions=RetryOptions{"
42+
+ "initialInterval=PT2M3S, "
43+
+ "backoffCoefficient=0.0, "
44+
+ "expiration=null, "
45+
+ "maximumAttempts=43, "
46+
+ "maximumInterval=null, "
47+
+ "doNotRetry=null"
48+
+ "}}";
49+
50+
assertEquals(expected, asString);
51+
}
52+
53+
@Test
54+
public void testTestHashCode() {
55+
LocalActivityOptions options1 = createOptions(123);
56+
LocalActivityOptions options2 = createOptions(456);
57+
58+
// The hash code of different objects should be different
59+
assertNotEquals(options1.hashCode(), options2.hashCode());
60+
}
61+
62+
public static LocalActivityOptions createOptions() {
63+
return createOptions(123);
64+
}
65+
66+
public static LocalActivityOptions createOptions(int initialRetryInterval) {
67+
RetryOptions retryOptions =
68+
new RetryOptions.Builder()
69+
.setInitialInterval(Duration.ofSeconds(initialRetryInterval))
70+
.setMaximumAttempts(43)
71+
.build();
72+
73+
return new LocalActivityOptions.Builder()
74+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
75+
.setRetryOptions(retryOptions)
76+
.build();
77+
}
78+
}

0 commit comments

Comments
 (0)