junit4ify EnumUtilsTest
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1149314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4574329913
commit
42c7d34dff
|
@ -18,23 +18,27 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EnumUtilsTest extends TestCase {
|
public class EnumUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConstructable() {
|
public void testConstructable() {
|
||||||
// enforce public constructor
|
// enforce public constructor
|
||||||
new EnumUtils();
|
new EnumUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test_getEnumMap() {
|
public void test_getEnumMap() {
|
||||||
Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
|
Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
|
||||||
assertEquals( "getEnumMap not created correctly", "{RED=RED, AMBER=AMBER, GREEN=GREEN}", test.toString());
|
assertEquals( "getEnumMap not created correctly", "{RED=RED, AMBER=AMBER, GREEN=GREEN}", test.toString());
|
||||||
|
@ -48,6 +52,7 @@ public class EnumUtilsTest extends TestCase {
|
||||||
assertEquals(false, test.containsKey("PURPLE"));
|
assertEquals(false, test.containsKey("PURPLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test_getEnumList() {
|
public void test_getEnumList() {
|
||||||
List<Traffic> test = EnumUtils.getEnumList(Traffic.class);
|
List<Traffic> test = EnumUtils.getEnumList(Traffic.class);
|
||||||
assertEquals(3, test.size());
|
assertEquals(3, test.size());
|
||||||
|
@ -56,6 +61,7 @@ public class EnumUtilsTest extends TestCase {
|
||||||
assertEquals(Traffic.GREEN, test.get(2));
|
assertEquals(Traffic.GREEN, test.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test_isEnum() {
|
public void test_isEnum() {
|
||||||
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "RED"));
|
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "RED"));
|
||||||
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "AMBER"));
|
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "AMBER"));
|
||||||
|
@ -64,15 +70,12 @@ public class EnumUtilsTest extends TestCase {
|
||||||
assertEquals(false, EnumUtils.isValidEnum(Traffic.class, null));
|
assertEquals(false, EnumUtils.isValidEnum(Traffic.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
public void test_isEnum_nullClass() {
|
public void test_isEnum_nullClass() {
|
||||||
try {
|
EnumUtils.isValidEnum((Class<Traffic>) null, "PURPLE");
|
||||||
EnumUtils.isValidEnum((Class<Traffic>) null, "PURPLE");
|
|
||||||
fail();
|
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test_getEnum() {
|
public void test_getEnum() {
|
||||||
assertEquals(Traffic.RED, EnumUtils.getEnum(Traffic.class, "RED"));
|
assertEquals(Traffic.RED, EnumUtils.getEnum(Traffic.class, "RED"));
|
||||||
assertEquals(Traffic.AMBER, EnumUtils.getEnum(Traffic.class, "AMBER"));
|
assertEquals(Traffic.AMBER, EnumUtils.getEnum(Traffic.class, "AMBER"));
|
||||||
|
@ -81,31 +84,22 @@ public class EnumUtilsTest extends TestCase {
|
||||||
assertEquals(null, EnumUtils.getEnum(Traffic.class, null));
|
assertEquals(null, EnumUtils.getEnum(Traffic.class, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
public void test_getEnum_nullClass() {
|
public void test_getEnum_nullClass() {
|
||||||
try {
|
EnumUtils.getEnum((Class<Traffic>) null, "PURPLE");
|
||||||
EnumUtils.getEnum((Class<Traffic>) null, "PURPLE");
|
|
||||||
fail();
|
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void test_generateBitVector_nullClass() {
|
public void test_generateBitVector_nullClass() {
|
||||||
try {
|
EnumUtils.generateBitVector(null, EnumSet.of(Traffic.RED));
|
||||||
EnumUtils.generateBitVector(null, EnumSet.of(Traffic.RED));
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void test_generateBitVector_longClass() {
|
public void test_generateBitVector_longClass() {
|
||||||
try {
|
EnumUtils.generateBitVector(TooMany.class, EnumSet.of(TooMany.A1));
|
||||||
EnumUtils.generateBitVector(TooMany.class, EnumSet.of(TooMany.A1));
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test_generateBitVector() {
|
public void test_generateBitVector() {
|
||||||
assertEquals(0L, EnumUtils.generateBitVector(Traffic.class, null));
|
assertEquals(0L, EnumUtils.generateBitVector(Traffic.class, null));
|
||||||
assertEquals(0L, EnumUtils.generateBitVector(Traffic.class, EnumSet.noneOf(Traffic.class)));
|
assertEquals(0L, EnumUtils.generateBitVector(Traffic.class, EnumSet.noneOf(Traffic.class)));
|
||||||
|
@ -118,23 +112,18 @@ public class EnumUtilsTest extends TestCase {
|
||||||
assertEquals(7L, EnumUtils.generateBitVector(Traffic.class, EnumSet.of(Traffic.RED, Traffic.AMBER, Traffic.GREEN)));
|
assertEquals(7L, EnumUtils.generateBitVector(Traffic.class, EnumSet.of(Traffic.RED, Traffic.AMBER, Traffic.GREEN)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void test_processBitVector_nullClass() {
|
public void test_processBitVector_nullClass() {
|
||||||
final Class<Traffic> empty = null;
|
final Class<Traffic> empty = null;
|
||||||
try {
|
EnumUtils.processBitVector(empty, 0L);
|
||||||
EnumUtils.processBitVector(empty, 0L);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void test_processBitVector_longClass() {
|
public void test_processBitVector_longClass() {
|
||||||
try {
|
EnumUtils.processBitVector(TooMany.class, 0L);
|
||||||
EnumUtils.processBitVector(TooMany.class, 0L);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void test_processBitVector() {
|
public void test_processBitVector() {
|
||||||
assertEquals(EnumSet.noneOf(Traffic.class), EnumUtils.processBitVector(Traffic.class, 0L));
|
assertEquals(EnumSet.noneOf(Traffic.class), EnumUtils.processBitVector(Traffic.class, 0L));
|
||||||
assertEquals(EnumSet.of(Traffic.RED), EnumUtils.processBitVector(Traffic.class, 1L));
|
assertEquals(EnumSet.of(Traffic.RED), EnumUtils.processBitVector(Traffic.class, 1L));
|
||||||
|
@ -151,8 +140,8 @@ enum Traffic {
|
||||||
RED, AMBER, GREEN
|
RED, AMBER, GREEN
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TooMany{
|
enum TooMany {
|
||||||
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,
|
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,
|
||||||
A1,B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1;
|
A1,B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1,
|
||||||
|
A2,B2,C2,D2,E2,F2,G2,H2,I2,J2,K2,L2,M2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue