Skip to content

Commit 45cd506

Browse files
committed
Added tests for LocalActivityOptions
1 parent a59a23c commit 45cd506

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 com.uber.cadence.common.RetryOptions;
23+
import java.time.Duration;
24+
import junit.framework.TestCase;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
28+
public class LocalActivityOptionsTest extends TestCase {
29+
30+
LocalActivityOptions options;
31+
32+
@Before
33+
public void setUp() {
34+
options = createOptions();
35+
}
36+
37+
@Test
38+
public void testMerge() {}
39+
40+
@Test
41+
public void testTestToString() {
42+
String asString = options.toString();
43+
44+
String expected =
45+
"LocalActivityOptions{"
46+
+ "scheduleToCloseTimeout=PT2M3S, "
47+
+ "retryOptions=RetryOptions{"
48+
+ "initialInterval=PT2M3S, "
49+
+ "backoffCoefficient=0.0, "
50+
+ "expiration=null, "
51+
+ "maximumAttempts=43, "
52+
+ "maximumInterval=null, "
53+
+ "doNotRetry=null"
54+
+ "}}";
55+
56+
assertEquals(expected, asString);
57+
}
58+
59+
@Test
60+
public void testTestEquals() {}
61+
62+
@Test
63+
public void testTestHashCode() {}
64+
65+
public static LocalActivityOptions createOptions() {
66+
RetryOptions retryOptions =
67+
new RetryOptions.Builder()
68+
.setInitialInterval(Duration.ofSeconds(123))
69+
.setMaximumAttempts(43)
70+
.build();
71+
72+
return new LocalActivityOptions.Builder()
73+
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
74+
.setRetryOptions(retryOptions)
75+
.build();
76+
}
77+
}

0 commit comments

Comments
 (0)