|
| 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 | +} |
0 commit comments