Skip to content

Commit 7945c68

Browse files
committed
Added tests for LocalActivityOptions
1 parent a59a23c commit 7945c68

File tree

2 files changed

+203
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)