1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.compatibility.common.tradefed.util;
17 
18 import static org.junit.Assert.*;
19 
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.junit.runners.JUnit4;
23 
24 import java.util.HashSet;
25 import java.util.Set;
26 
27 /**
28  * Unit tests for {@link RetryFilterHelper}
29  */
30 @RunWith(JUnit4.class)
31 public class RetryFilterHelperTest {
32 
33     private static final String TEST_STRING = "abcd";
34     private static final RetryType TEST_RETRY_TYPE = RetryType.FAILED;
35 
36     /**
37      * Tests that options can be internally copied using
38      * {@link RetryFilterHelper#setAllOptionsFrom(RetryFilterHelper)}.
39      */
40     @Test
testSetAllOptionsFrom()41     public void testSetAllOptionsFrom() throws Exception {
42         RetryFilterHelper helper = new RetryFilterHelper(null, 0);
43         RetryFilterHelper otherObj = new RetryFilterHelper(null, 0, TEST_STRING,
44                 new HashSet<String>(), new HashSet<String>(), null ,null, null, null);
45         helper.setAllOptionsFrom(otherObj);
46         assertEquals(TEST_STRING, helper.mSubPlan);
47     }
48 
49     /**
50      * Tests that options can be cleared using {@link RetryFilterHelper#clearOptions()}.
51      */
52     @Test
testClearOptions()53     public void testClearOptions() throws Exception {
54         Set<String> include = new HashSet<>();
55         include.add(TEST_STRING);
56         Set<String> exclude = new HashSet<>();
57         exclude.add(TEST_STRING);
58         RetryFilterHelper helper = new RetryFilterHelper(null, 0, TEST_STRING, include, exclude,
59                 TEST_STRING, TEST_STRING, TEST_STRING, TEST_RETRY_TYPE);
60         helper.clearOptions();
61         assertTrue(helper.mSubPlan == null);
62         assertTrue(helper.mIncludeFilters.isEmpty());
63         assertTrue(helper.mExcludeFilters.isEmpty());
64         assertTrue(helper.mAbiName == null);
65         assertTrue(helper.mModuleName == null);
66         assertTrue(helper.mTestName == null);
67         assertTrue(helper.mRetryType == null);
68     }
69 
70 }
71