blob: 8e7b5934304aa4daa59b856b9832a82dddf4d603 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/* Copyright 2017 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
package org.brotli.dec;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.TreeSet;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Tests for Enum-like classes.
*/
@RunWith(JUnit4.class)
public class EnumTest {
private void checkEnumClass(Class<?> clazz) {
TreeSet<Integer> values = new TreeSet<Integer>();
for (Field f : clazz.getDeclaredFields()) {
assertEquals("int", f.getType().getName());
assertEquals(Modifier.FINAL | Modifier.STATIC, f.getModifiers());
Integer value = null;
try {
value = f.getInt(null);
} catch (IllegalAccessException ex) {
fail("Inaccessible field");
}
assertFalse(values.contains(value));
values.add(value);
}
assertEquals(0, values.first().intValue());
assertEquals(values.size(), values.last() + 1);
}
@Test
public void testRunningState() {
checkEnumClass(RunningState.class);
}
@Test
public void testWordTransformType() {
checkEnumClass(WordTransformType.class);
}
}
|