DozeParametersTest.java revision fc2b64e3e80d44dabd6c32eb8cd69893d39476a9
1/*
2 * Copyright (C) 2016 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
17package com.android.systemui.statusbar.phone;
18
19import android.support.test.runner.AndroidJUnit4;
20import android.test.suitebuilder.annotation.SmallTest;
21import com.android.systemui.statusbar.phone.DozeParameters.IntInOutMatcher;
22import org.junit.Test;
23import org.junit.runner.RunWith;
24
25import static junit.framework.Assert.assertTrue;
26import static junit.framework.Assert.assertFalse;
27import static junit.framework.Assert.fail;
28
29@SmallTest
30@RunWith(AndroidJUnit4.class)
31public class DozeParametersTest {
32
33    @Test
34    public void test_inOutMatcher_defaultIn() {
35        IntInOutMatcher intInOutMatcher = new IntInOutMatcher("*");
36
37        assertTrue(intInOutMatcher.isIn(1));
38        assertTrue(intInOutMatcher.isIn(-1));
39        assertTrue(intInOutMatcher.isIn(0));
40    }
41
42    @Test
43    public void test_inOutMatcher_defaultOut() {
44        IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!*");
45
46        assertFalse(intInOutMatcher.isIn(1));
47        assertFalse(intInOutMatcher.isIn(-1));
48        assertFalse(intInOutMatcher.isIn(0));
49    }
50
51    @Test
52    public void test_inOutMatcher_someIn() {
53        IntInOutMatcher intInOutMatcher = new IntInOutMatcher("1,2,3,!*");
54
55        assertTrue(intInOutMatcher.isIn(1));
56        assertTrue(intInOutMatcher.isIn(2));
57        assertTrue(intInOutMatcher.isIn(3));
58
59        assertFalse(intInOutMatcher.isIn(0));
60        assertFalse(intInOutMatcher.isIn(4));
61    }
62
63    @Test
64    public void test_inOutMatcher_someOut() {
65        IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,!2,!3,*");
66
67        assertFalse(intInOutMatcher.isIn(1));
68        assertFalse(intInOutMatcher.isIn(2));
69        assertFalse(intInOutMatcher.isIn(3));
70
71        assertTrue(intInOutMatcher.isIn(0));
72        assertTrue(intInOutMatcher.isIn(4));
73    }
74
75    @Test
76    public void test_inOutMatcher_mixed() {
77        IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,2,!3,*");
78
79        assertFalse(intInOutMatcher.isIn(1));
80        assertTrue(intInOutMatcher.isIn(2));
81        assertFalse(intInOutMatcher.isIn(3));
82
83        assertTrue(intInOutMatcher.isIn(0));
84        assertTrue(intInOutMatcher.isIn(4));
85    }
86
87    @Test
88    public void test_inOutMatcher_failEmpty() {
89        try {
90            new IntInOutMatcher("");
91            fail("Expected IllegalArgumentException");
92        } catch (IllegalArgumentException e) {
93            // expected
94        }
95    }
96
97    @Test
98    public void test_inOutMatcher_failNull() {
99        try {
100            new IntInOutMatcher(null);
101            fail("Expected IllegalArgumentException");
102        } catch (IllegalArgumentException e) {
103            // expected
104        }
105    }
106
107    @Test
108    public void test_inOutMatcher_failEmptyClause() {
109        try {
110            new IntInOutMatcher("!1,*,");
111            fail("Expected IllegalArgumentException");
112        } catch (IllegalArgumentException e) {
113            // expected
114        }
115    }
116
117    @Test
118    public void test_inOutMatcher_failDuplicate() {
119        try {
120            new IntInOutMatcher("!1,*,!1");
121            fail("Expected IllegalArgumentException");
122        } catch (IllegalArgumentException e) {
123            // expected
124        }
125    }
126
127    @Test
128    public void test_inOutMatcher_failDuplicateDefault() {
129        try {
130            new IntInOutMatcher("!1,*,*");
131            fail("Expected IllegalArgumentException");
132        } catch (IllegalArgumentException e) {
133            // expected
134        }
135    }
136
137    @Test
138    public void test_inOutMatcher_failMalformedNot() {
139        try {
140            new IntInOutMatcher("!,*");
141            fail("Expected IllegalArgumentException");
142        } catch (IllegalArgumentException e) {
143            // expected
144        }
145    }
146
147    @Test
148    public void test_inOutMatcher_failText() {
149        try {
150            new IntInOutMatcher("!abc,*");
151            fail("Expected IllegalArgumentException");
152        } catch (IllegalArgumentException e) {
153            // expected
154        }
155    }
156
157    @Test
158    public void test_inOutMatcher_failContradiction() {
159        try {
160            new IntInOutMatcher("1,!1,*");
161            fail("Expected IllegalArgumentException");
162        } catch (IllegalArgumentException e) {
163            // expected
164        }
165    }
166
167    @Test
168    public void test_inOutMatcher_failContradictionDefault() {
169        try {
170            new IntInOutMatcher("1,*,!*");
171            fail("Expected IllegalArgumentException");
172        } catch (IllegalArgumentException e) {
173            // expected
174        }
175    }
176
177    @Test
178    public void test_inOutMatcher_failMissingDefault() {
179        try {
180            new IntInOutMatcher("1");
181            fail("Expected IllegalArgumentException");
182        } catch (IllegalArgumentException e) {
183            // expected
184        }
185    }
186
187}
188