Avoid boolean boxing in asserts where possible

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1199724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2011-11-09 12:51:52 +00:00
parent 40e4babd35
commit f4b810ba42
9 changed files with 198 additions and 195 deletions

View File

@ -36,9 +36,9 @@ public class BooleanUtilsTest {
assertNotNull(new BooleanUtils());
Constructor<?>[] cons = BooleanUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(BooleanUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(BooleanUtils.class.getModifiers()));
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
assertTrue(Modifier.isPublic(BooleanUtils.class.getModifiers()));
assertFalse(Modifier.isFinal(BooleanUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
@ -52,58 +52,58 @@ public class BooleanUtilsTest {
//-----------------------------------------------------------------------
@Test
public void test_isTrue_Boolean() {
assertEquals(true, BooleanUtils.isTrue(Boolean.TRUE));
assertEquals(false, BooleanUtils.isTrue(Boolean.FALSE));
assertEquals(false, BooleanUtils.isTrue((Boolean) null));
assertTrue(BooleanUtils.isTrue(Boolean.TRUE));
assertFalse(BooleanUtils.isTrue(Boolean.FALSE));
assertFalse(BooleanUtils.isTrue((Boolean) null));
}
@Test
public void test_isNotTrue_Boolean() {
assertEquals(false, BooleanUtils.isNotTrue(Boolean.TRUE));
assertEquals(true, BooleanUtils.isNotTrue(Boolean.FALSE));
assertEquals(true, BooleanUtils.isNotTrue((Boolean) null));
assertFalse(BooleanUtils.isNotTrue(Boolean.TRUE));
assertTrue(BooleanUtils.isNotTrue(Boolean.FALSE));
assertTrue(BooleanUtils.isNotTrue((Boolean) null));
}
//-----------------------------------------------------------------------
@Test
public void test_isFalse_Boolean() {
assertEquals(false, BooleanUtils.isFalse(Boolean.TRUE));
assertEquals(true, BooleanUtils.isFalse(Boolean.FALSE));
assertEquals(false, BooleanUtils.isFalse((Boolean) null));
assertFalse(BooleanUtils.isFalse(Boolean.TRUE));
assertTrue(BooleanUtils.isFalse(Boolean.FALSE));
assertFalse(BooleanUtils.isFalse((Boolean) null));
}
@Test
public void test_isNotFalse_Boolean() {
assertEquals(true, BooleanUtils.isNotFalse(Boolean.TRUE));
assertEquals(false, BooleanUtils.isNotFalse(Boolean.FALSE));
assertEquals(true, BooleanUtils.isNotFalse((Boolean) null));
assertTrue(BooleanUtils.isNotFalse(Boolean.TRUE));
assertFalse(BooleanUtils.isNotFalse(Boolean.FALSE));
assertTrue(BooleanUtils.isNotFalse((Boolean) null));
}
//-----------------------------------------------------------------------
@Test
public void test_toBoolean_Boolean() {
assertEquals(true, BooleanUtils.toBoolean(Boolean.TRUE));
assertEquals(false, BooleanUtils.toBoolean(Boolean.FALSE));
assertEquals(false, BooleanUtils.toBoolean((Boolean) null));
assertTrue(BooleanUtils.toBoolean(Boolean.TRUE));
assertFalse(BooleanUtils.toBoolean(Boolean.FALSE));
assertFalse(BooleanUtils.toBoolean((Boolean) null));
}
@Test
public void test_toBooleanDefaultIfNull_Boolean_boolean() {
assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, true));
assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false));
assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true));
assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, false));
assertEquals(true, BooleanUtils.toBooleanDefaultIfNull((Boolean) null, true));
assertEquals(false, BooleanUtils.toBooleanDefaultIfNull((Boolean) null, false));
assertTrue(BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, true));
assertTrue(BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false));
assertFalse(BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true));
assertFalse(BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, false));
assertTrue(BooleanUtils.toBooleanDefaultIfNull((Boolean) null, true));
assertFalse(BooleanUtils.toBooleanDefaultIfNull((Boolean) null, false));
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test
public void test_toBoolean_int() {
assertEquals(true, BooleanUtils.toBoolean(1));
assertEquals(true, BooleanUtils.toBoolean(-1));
assertEquals(false, BooleanUtils.toBoolean(0));
assertTrue(BooleanUtils.toBoolean(1));
assertTrue(BooleanUtils.toBoolean(-1));
assertFalse(BooleanUtils.toBoolean(0));
}
@Test
@ -124,8 +124,8 @@ public class BooleanUtilsTest {
//-----------------------------------------------------------------------
@Test
public void test_toBoolean_int_int_int() {
assertEquals(true, BooleanUtils.toBoolean(6, 6, 7));
assertEquals(false, BooleanUtils.toBoolean(7, 6, 7));
assertTrue(BooleanUtils.toBoolean(6, 6, 7));
assertFalse(BooleanUtils.toBoolean(7, 6, 7));
}
@Test(expected = IllegalArgumentException.class)
@ -138,11 +138,11 @@ public class BooleanUtilsTest {
Integer six = Integer.valueOf(6);
Integer seven = Integer.valueOf(7);
assertEquals(true, BooleanUtils.toBoolean((Integer) null, null, seven));
assertEquals(false, BooleanUtils.toBoolean((Integer) null, six, null));
assertTrue(BooleanUtils.toBoolean((Integer) null, null, seven));
assertFalse(BooleanUtils.toBoolean((Integer) null, six, null));
assertEquals(true, BooleanUtils.toBoolean(Integer.valueOf(6), six, seven));
assertEquals(false, BooleanUtils.toBoolean(Integer.valueOf(7), six, seven));
assertTrue(BooleanUtils.toBoolean(Integer.valueOf(6), six, seven));
assertFalse(BooleanUtils.toBoolean(Integer.valueOf(7), six, seven));
}
@Test(expected = IllegalArgumentException.class)
@ -306,62 +306,62 @@ public class BooleanUtilsTest {
//-----------------------------------------------------------------------
@Test
public void test_toBoolean_String() {
assertEquals(false, BooleanUtils.toBoolean((String) null));
assertEquals(false, BooleanUtils.toBoolean(""));
assertEquals(false, BooleanUtils.toBoolean("off"));
assertEquals(false, BooleanUtils.toBoolean("oof"));
assertEquals(false, BooleanUtils.toBoolean("yep"));
assertEquals(false, BooleanUtils.toBoolean("trux"));
assertEquals(false, BooleanUtils.toBoolean("false"));
assertEquals(false, BooleanUtils.toBoolean("a"));
assertEquals(true, BooleanUtils.toBoolean("true")); // interned handled differently
assertEquals(true, BooleanUtils.toBoolean(new StringBuffer("tr").append("ue").toString()));
assertEquals(true, BooleanUtils.toBoolean("truE"));
assertEquals(true, BooleanUtils.toBoolean("trUe"));
assertEquals(true, BooleanUtils.toBoolean("trUE"));
assertEquals(true, BooleanUtils.toBoolean("tRue"));
assertEquals(true, BooleanUtils.toBoolean("tRuE"));
assertEquals(true, BooleanUtils.toBoolean("tRUe"));
assertEquals(true, BooleanUtils.toBoolean("tRUE"));
assertEquals(true, BooleanUtils.toBoolean("TRUE"));
assertEquals(true, BooleanUtils.toBoolean("TRUe"));
assertEquals(true, BooleanUtils.toBoolean("TRuE"));
assertEquals(true, BooleanUtils.toBoolean("TRue"));
assertEquals(true, BooleanUtils.toBoolean("TrUE"));
assertEquals(true, BooleanUtils.toBoolean("TrUe"));
assertEquals(true, BooleanUtils.toBoolean("TruE"));
assertEquals(true, BooleanUtils.toBoolean("True"));
assertEquals(true, BooleanUtils.toBoolean("on"));
assertEquals(true, BooleanUtils.toBoolean("oN"));
assertEquals(true, BooleanUtils.toBoolean("On"));
assertEquals(true, BooleanUtils.toBoolean("ON"));
assertEquals(true, BooleanUtils.toBoolean("yes"));
assertEquals(true, BooleanUtils.toBoolean("yeS"));
assertEquals(true, BooleanUtils.toBoolean("yEs"));
assertEquals(true, BooleanUtils.toBoolean("yES"));
assertEquals(true, BooleanUtils.toBoolean("Yes"));
assertEquals(true, BooleanUtils.toBoolean("YeS"));
assertEquals(true, BooleanUtils.toBoolean("YEs"));
assertEquals(true, BooleanUtils.toBoolean("YES"));
assertEquals(false, BooleanUtils.toBoolean("yes?"));
assertEquals(false, BooleanUtils.toBoolean("tru"));
assertFalse(BooleanUtils.toBoolean((String) null));
assertFalse(BooleanUtils.toBoolean(""));
assertFalse(BooleanUtils.toBoolean("off"));
assertFalse(BooleanUtils.toBoolean("oof"));
assertFalse(BooleanUtils.toBoolean("yep"));
assertFalse(BooleanUtils.toBoolean("trux"));
assertFalse(BooleanUtils.toBoolean("false"));
assertFalse(BooleanUtils.toBoolean("a"));
assertTrue(BooleanUtils.toBoolean("true")); // interned handled differently
assertTrue(BooleanUtils.toBoolean(new StringBuffer("tr").append("ue").toString()));
assertTrue(BooleanUtils.toBoolean("truE"));
assertTrue(BooleanUtils.toBoolean("trUe"));
assertTrue(BooleanUtils.toBoolean("trUE"));
assertTrue(BooleanUtils.toBoolean("tRue"));
assertTrue(BooleanUtils.toBoolean("tRuE"));
assertTrue(BooleanUtils.toBoolean("tRUe"));
assertTrue(BooleanUtils.toBoolean("tRUE"));
assertTrue(BooleanUtils.toBoolean("TRUE"));
assertTrue(BooleanUtils.toBoolean("TRUe"));
assertTrue(BooleanUtils.toBoolean("TRuE"));
assertTrue(BooleanUtils.toBoolean("TRue"));
assertTrue(BooleanUtils.toBoolean("TrUE"));
assertTrue(BooleanUtils.toBoolean("TrUe"));
assertTrue(BooleanUtils.toBoolean("TruE"));
assertTrue(BooleanUtils.toBoolean("True"));
assertTrue(BooleanUtils.toBoolean("on"));
assertTrue(BooleanUtils.toBoolean("oN"));
assertTrue(BooleanUtils.toBoolean("On"));
assertTrue(BooleanUtils.toBoolean("ON"));
assertTrue(BooleanUtils.toBoolean("yes"));
assertTrue(BooleanUtils.toBoolean("yeS"));
assertTrue(BooleanUtils.toBoolean("yEs"));
assertTrue(BooleanUtils.toBoolean("yES"));
assertTrue(BooleanUtils.toBoolean("Yes"));
assertTrue(BooleanUtils.toBoolean("YeS"));
assertTrue(BooleanUtils.toBoolean("YEs"));
assertTrue(BooleanUtils.toBoolean("YES"));
assertFalse(BooleanUtils.toBoolean("yes?"));
assertFalse(BooleanUtils.toBoolean("tru"));
assertEquals(false, BooleanUtils.toBoolean("no"));
assertEquals(false, BooleanUtils.toBoolean("off"));
assertEquals(false, BooleanUtils.toBoolean("yoo"));
assertFalse(BooleanUtils.toBoolean("no"));
assertFalse(BooleanUtils.toBoolean("off"));
assertFalse(BooleanUtils.toBoolean("yoo"));
}
@Test
public void test_toBoolean_String_String_String() {
assertEquals(true, BooleanUtils.toBoolean((String) null, null, "N"));
assertEquals(false, BooleanUtils.toBoolean((String) null, "Y", null));
assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "N"));
assertEquals(true, BooleanUtils.toBoolean("Y", new String("Y"), new String("N")));
assertEquals(false, BooleanUtils.toBoolean("N", "Y", "N"));
assertEquals(false, BooleanUtils.toBoolean("N", new String("Y"), new String("N")));
assertEquals(true, BooleanUtils.toBoolean((String) null, null, null));
assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "Y"));
assertEquals(true, BooleanUtils.toBoolean("Y", new String("Y"), new String("Y")));
assertTrue(BooleanUtils.toBoolean((String) null, null, "N"));
assertFalse(BooleanUtils.toBoolean((String) null, "Y", null));
assertTrue(BooleanUtils.toBoolean("Y", "Y", "N"));
assertTrue(BooleanUtils.toBoolean("Y", new String("Y"), new String("N")));
assertFalse(BooleanUtils.toBoolean("N", "Y", "N"));
assertFalse(BooleanUtils.toBoolean("N", new String("Y"), new String("N")));
assertTrue(BooleanUtils.toBoolean((String) null, null, null));
assertTrue(BooleanUtils.toBoolean("Y", "Y", "Y"));
assertTrue(BooleanUtils.toBoolean("Y", new String("Y"), new String("Y")));
}
@Test(expected = IllegalArgumentException.class)

View File

@ -17,6 +17,7 @@
package org.apache.commons.lang3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@ -42,9 +43,9 @@ public class CharUtilsTest {
assertNotNull(new CharUtils());
Constructor<?>[] cons = CharUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(BooleanUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(BooleanUtils.class.getModifiers()));
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
assertTrue(Modifier.isPublic(BooleanUtils.class.getModifiers()));
assertFalse(Modifier.isFinal(BooleanUtils.class.getModifiers()));
}
@Test
@ -211,144 +212,144 @@ public class CharUtilsTest {
@Test
public void testIsAscii_char() {
assertEquals(true, CharUtils.isAscii('a'));
assertEquals(true, CharUtils.isAscii('A'));
assertEquals(true, CharUtils.isAscii('3'));
assertEquals(true, CharUtils.isAscii('-'));
assertEquals(true, CharUtils.isAscii('\n'));
assertEquals(false, CharUtils.isAscii(CHAR_COPY));
assertTrue(CharUtils.isAscii('a'));
assertTrue(CharUtils.isAscii('A'));
assertTrue(CharUtils.isAscii('3'));
assertTrue(CharUtils.isAscii('-'));
assertTrue(CharUtils.isAscii('\n'));
assertFalse(CharUtils.isAscii(CHAR_COPY));
for (int i = 0; i < 128; i++) {
if (i < 128) {
assertEquals(true, CharUtils.isAscii((char) i));
assertTrue(CharUtils.isAscii((char) i));
} else {
assertEquals(false, CharUtils.isAscii((char) i));
assertFalse(CharUtils.isAscii((char) i));
}
}
}
@Test
public void testIsAsciiPrintable_char() {
assertEquals(true, CharUtils.isAsciiPrintable('a'));
assertEquals(true, CharUtils.isAsciiPrintable('A'));
assertEquals(true, CharUtils.isAsciiPrintable('3'));
assertEquals(true, CharUtils.isAsciiPrintable('-'));
assertEquals(false, CharUtils.isAsciiPrintable('\n'));
assertEquals(false, CharUtils.isAscii(CHAR_COPY));
assertTrue(CharUtils.isAsciiPrintable('a'));
assertTrue(CharUtils.isAsciiPrintable('A'));
assertTrue(CharUtils.isAsciiPrintable('3'));
assertTrue(CharUtils.isAsciiPrintable('-'));
assertFalse(CharUtils.isAsciiPrintable('\n'));
assertFalse(CharUtils.isAscii(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if (i >= 32 && i <= 126) {
assertEquals(true, CharUtils.isAsciiPrintable((char) i));
assertTrue(CharUtils.isAsciiPrintable((char) i));
} else {
assertEquals(false, CharUtils.isAsciiPrintable((char) i));
assertFalse(CharUtils.isAsciiPrintable((char) i));
}
}
}
@Test
public void testIsAsciiControl_char() {
assertEquals(false, CharUtils.isAsciiControl('a'));
assertEquals(false, CharUtils.isAsciiControl('A'));
assertEquals(false, CharUtils.isAsciiControl('3'));
assertEquals(false, CharUtils.isAsciiControl('-'));
assertEquals(true, CharUtils.isAsciiControl('\n'));
assertEquals(false, CharUtils.isAsciiControl(CHAR_COPY));
assertFalse(CharUtils.isAsciiControl('a'));
assertFalse(CharUtils.isAsciiControl('A'));
assertFalse(CharUtils.isAsciiControl('3'));
assertFalse(CharUtils.isAsciiControl('-'));
assertTrue(CharUtils.isAsciiControl('\n'));
assertFalse(CharUtils.isAsciiControl(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if (i < 32 || i == 127) {
assertEquals(true, CharUtils.isAsciiControl((char) i));
assertTrue(CharUtils.isAsciiControl((char) i));
} else {
assertEquals(false, CharUtils.isAsciiControl((char) i));
assertFalse(CharUtils.isAsciiControl((char) i));
}
}
}
@Test
public void testIsAsciiAlpha_char() {
assertEquals(true, CharUtils.isAsciiAlpha('a'));
assertEquals(true, CharUtils.isAsciiAlpha('A'));
assertEquals(false, CharUtils.isAsciiAlpha('3'));
assertEquals(false, CharUtils.isAsciiAlpha('-'));
assertEquals(false, CharUtils.isAsciiAlpha('\n'));
assertEquals(false, CharUtils.isAsciiAlpha(CHAR_COPY));
assertTrue(CharUtils.isAsciiAlpha('a'));
assertTrue(CharUtils.isAsciiAlpha('A'));
assertFalse(CharUtils.isAsciiAlpha('3'));
assertFalse(CharUtils.isAsciiAlpha('-'));
assertFalse(CharUtils.isAsciiAlpha('\n'));
assertFalse(CharUtils.isAsciiAlpha(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if ((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z')) {
assertEquals(true, CharUtils.isAsciiAlpha((char) i));
assertTrue(CharUtils.isAsciiAlpha((char) i));
} else {
assertEquals(false, CharUtils.isAsciiAlpha((char) i));
assertFalse(CharUtils.isAsciiAlpha((char) i));
}
}
}
@Test
public void testIsAsciiAlphaUpper_char() {
assertEquals(false, CharUtils.isAsciiAlphaUpper('a'));
assertEquals(true, CharUtils.isAsciiAlphaUpper('A'));
assertEquals(false, CharUtils.isAsciiAlphaUpper('3'));
assertEquals(false, CharUtils.isAsciiAlphaUpper('-'));
assertEquals(false, CharUtils.isAsciiAlphaUpper('\n'));
assertEquals(false, CharUtils.isAsciiAlphaUpper(CHAR_COPY));
assertFalse(CharUtils.isAsciiAlphaUpper('a'));
assertTrue(CharUtils.isAsciiAlphaUpper('A'));
assertFalse(CharUtils.isAsciiAlphaUpper('3'));
assertFalse(CharUtils.isAsciiAlphaUpper('-'));
assertFalse(CharUtils.isAsciiAlphaUpper('\n'));
assertFalse(CharUtils.isAsciiAlphaUpper(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if (i >= 'A' && i <= 'Z') {
assertEquals(true, CharUtils.isAsciiAlphaUpper((char) i));
assertTrue(CharUtils.isAsciiAlphaUpper((char) i));
} else {
assertEquals(false, CharUtils.isAsciiAlphaUpper((char) i));
assertFalse(CharUtils.isAsciiAlphaUpper((char) i));
}
}
}
@Test
public void testIsAsciiAlphaLower_char() {
assertEquals(true, CharUtils.isAsciiAlphaLower('a'));
assertEquals(false, CharUtils.isAsciiAlphaLower('A'));
assertEquals(false, CharUtils.isAsciiAlphaLower('3'));
assertEquals(false, CharUtils.isAsciiAlphaLower('-'));
assertEquals(false, CharUtils.isAsciiAlphaLower('\n'));
assertEquals(false, CharUtils.isAsciiAlphaLower(CHAR_COPY));
assertTrue(CharUtils.isAsciiAlphaLower('a'));
assertFalse(CharUtils.isAsciiAlphaLower('A'));
assertFalse(CharUtils.isAsciiAlphaLower('3'));
assertFalse(CharUtils.isAsciiAlphaLower('-'));
assertFalse(CharUtils.isAsciiAlphaLower('\n'));
assertFalse(CharUtils.isAsciiAlphaLower(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if (i >= 'a' && i <= 'z') {
assertEquals(true, CharUtils.isAsciiAlphaLower((char) i));
assertTrue(CharUtils.isAsciiAlphaLower((char) i));
} else {
assertEquals(false, CharUtils.isAsciiAlphaLower((char) i));
assertFalse(CharUtils.isAsciiAlphaLower((char) i));
}
}
}
@Test
public void testIsAsciiNumeric_char() {
assertEquals(false, CharUtils.isAsciiNumeric('a'));
assertEquals(false, CharUtils.isAsciiNumeric('A'));
assertEquals(true, CharUtils.isAsciiNumeric('3'));
assertEquals(false, CharUtils.isAsciiNumeric('-'));
assertEquals(false, CharUtils.isAsciiNumeric('\n'));
assertEquals(false, CharUtils.isAsciiNumeric(CHAR_COPY));
assertFalse(CharUtils.isAsciiNumeric('a'));
assertFalse(CharUtils.isAsciiNumeric('A'));
assertTrue(CharUtils.isAsciiNumeric('3'));
assertFalse(CharUtils.isAsciiNumeric('-'));
assertFalse(CharUtils.isAsciiNumeric('\n'));
assertFalse(CharUtils.isAsciiNumeric(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if (i >= '0' && i <= '9') {
assertEquals(true, CharUtils.isAsciiNumeric((char) i));
assertTrue(CharUtils.isAsciiNumeric((char) i));
} else {
assertEquals(false, CharUtils.isAsciiNumeric((char) i));
assertFalse(CharUtils.isAsciiNumeric((char) i));
}
}
}
@Test
public void testIsAsciiAlphanumeric_char() {
assertEquals(true, CharUtils.isAsciiAlphanumeric('a'));
assertEquals(true, CharUtils.isAsciiAlphanumeric('A'));
assertEquals(true, CharUtils.isAsciiAlphanumeric('3'));
assertEquals(false, CharUtils.isAsciiAlphanumeric('-'));
assertEquals(false, CharUtils.isAsciiAlphanumeric('\n'));
assertEquals(false, CharUtils.isAsciiAlphanumeric(CHAR_COPY));
assertTrue(CharUtils.isAsciiAlphanumeric('a'));
assertTrue(CharUtils.isAsciiAlphanumeric('A'));
assertTrue(CharUtils.isAsciiAlphanumeric('3'));
assertFalse(CharUtils.isAsciiAlphanumeric('-'));
assertFalse(CharUtils.isAsciiAlphanumeric('\n'));
assertFalse(CharUtils.isAsciiAlphanumeric(CHAR_COPY));
for (int i = 0; i < 196; i++) {
if ((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || (i >= '0' && i <= '9')) {
assertEquals(true, CharUtils.isAsciiAlphanumeric((char) i));
assertTrue(CharUtils.isAsciiAlphanumeric((char) i));
} else {
assertEquals(false, CharUtils.isAsciiAlphanumeric((char) i));
assertFalse(CharUtils.isAsciiAlphanumeric((char) i));
}
}
}

View File

@ -44,13 +44,13 @@ public class EnumUtilsTest {
Map<String, Traffic> test = EnumUtils.getEnumMap(Traffic.class);
assertEquals( "getEnumMap not created correctly", "{RED=RED, AMBER=AMBER, GREEN=GREEN}", test.toString());
assertEquals(3, test.size());
assertEquals(true, test.containsKey("RED"));
assertTrue(test.containsKey("RED"));
assertEquals(Traffic.RED, test.get("RED"));
assertEquals(true, test.containsKey("AMBER"));
assertTrue(test.containsKey("AMBER"));
assertEquals(Traffic.AMBER, test.get("AMBER"));
assertEquals(true, test.containsKey("GREEN"));
assertTrue(test.containsKey("GREEN"));
assertEquals(Traffic.GREEN, test.get("GREEN"));
assertEquals(false, test.containsKey("PURPLE"));
assertFalse(test.containsKey("PURPLE"));
}
@Test
@ -64,11 +64,11 @@ public class EnumUtilsTest {
@Test
public void test_isEnum() {
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "RED"));
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "AMBER"));
assertEquals(true, EnumUtils.isValidEnum(Traffic.class, "GREEN"));
assertEquals(false, EnumUtils.isValidEnum(Traffic.class, "PURPLE"));
assertEquals(false, EnumUtils.isValidEnum(Traffic.class, null));
assertTrue(EnumUtils.isValidEnum(Traffic.class, "RED"));
assertTrue(EnumUtils.isValidEnum(Traffic.class, "AMBER"));
assertTrue(EnumUtils.isValidEnum(Traffic.class, "GREEN"));
assertFalse(EnumUtils.isValidEnum(Traffic.class, "PURPLE"));
assertFalse(EnumUtils.isValidEnum(Traffic.class, null));
}
@Test(expected=NullPointerException.class)

View File

@ -46,9 +46,9 @@ public class ObjectUtilsTest {
assertNotNull(new ObjectUtils());
Constructor<?>[] cons = ObjectUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(ObjectUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(ObjectUtils.class.getModifiers()));
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
assertTrue(Modifier.isPublic(ObjectUtils.class.getModifiers()));
assertFalse(Modifier.isFinal(ObjectUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------

View File

@ -17,6 +17,7 @@
package org.apache.commons.lang3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -32,7 +33,6 @@ import org.junit.Test;
import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
import org.apache.commons.lang3.text.translate.NumericEntityEscaper;
import org.apache.commons.lang3.text.translate.NumericEntityUnescaper;
/**
* Unit tests for {@link StringEscapeUtils}.
@ -47,9 +47,9 @@ public class StringEscapeUtilsTest {
assertNotNull(new StringEscapeUtils());
Constructor<?>[] cons = StringEscapeUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(StringEscapeUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(StringEscapeUtils.class.getModifiers()));
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
assertTrue(Modifier.isPublic(StringEscapeUtils.class.getModifiers()));
assertFalse(Modifier.isFinal(StringEscapeUtils.class.getModifiers()));
}
@Test

View File

@ -106,9 +106,9 @@ public class StringUtilsTest {
assertNotNull(new StringUtils());
Constructor<?>[] cons = StringUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(StringUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(StringUtils.class.getModifiers()));
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
assertTrue(Modifier.isPublic(StringUtils.class.getModifiers()));
assertFalse(Modifier.isFinal(StringUtils.class.getModifiers()));
}
//-----------------------------------------------------------------------
@ -1186,7 +1186,7 @@ public class StringUtilsTest {
assertEquals("abcabcabc", StringUtils.repeat("abc", 3));
String str = StringUtils.repeat("a", 10000); // bigger than pad limit
assertEquals(10000, str.length());
assertEquals(true, StringUtils.containsOnly(str, new char[] {'a'}));
assertTrue(StringUtils.containsOnly(str, new char[] {'a'}));
}
@Test
@ -1306,7 +1306,7 @@ public class StringUtilsTest {
assertEquals("abcxx", StringUtils.rightPad("abc", 5, 'x'));
String str = StringUtils.rightPad("aaa", 10000, 'a'); // bigger than pad length
assertEquals(10000, str.length());
assertEquals(true, StringUtils.containsOnly(str, new char[] {'a'}));
assertTrue(StringUtils.containsOnly(str, new char[] {'a'}));
}
@Test
@ -1342,7 +1342,7 @@ public class StringUtilsTest {
assertEquals("abc", StringUtils.leftPad("abc", 2, ' '));
String str = StringUtils.leftPad("aaa", 10000, 'a'); // bigger than pad length
assertEquals(10000, str.length());
assertEquals(true, StringUtils.containsOnly(str, new char[] {'a'}));
assertTrue(StringUtils.containsOnly(str, new char[] {'a'}));
}
@Test

View File

@ -285,10 +285,10 @@ public class EqualsBuilderTest {
public void testSuper() {
TestObject o1 = new TestObject(4);
TestObject o2 = new TestObject(5);
assertEquals(true, new EqualsBuilder().appendSuper(true).append(o1, o1).isEquals());
assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o1).isEquals());
assertEquals(false, new EqualsBuilder().appendSuper(true).append(o1, o2).isEquals());
assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o2).isEquals());
assertTrue(new EqualsBuilder().appendSuper(true).append(o1, o1).isEquals());
assertFalse(new EqualsBuilder().appendSuper(false).append(o1, o1).isEquals());
assertFalse(new EqualsBuilder().appendSuper(true).append(o1, o2).isEquals());
assertFalse(new EqualsBuilder().appendSuper(false).append(o1, o2).isEquals());
}
@Test
@ -311,16 +311,16 @@ public class EqualsBuilderTest {
public void testObjectBuild() {
TestObject o1 = new TestObject(4);
TestObject o2 = new TestObject(5);
assertTrue(new EqualsBuilder().append(o1, o1).build());
assertTrue(!new EqualsBuilder().append(o1, o2).build());
assertEquals(Boolean.TRUE, new EqualsBuilder().append(o1, o1).build());
assertEquals(Boolean.FALSE, new EqualsBuilder().append(o1, o2).build());
o2.setA(4);
assertTrue(new EqualsBuilder().append(o1, o2).build());
assertEquals(Boolean.TRUE, new EqualsBuilder().append(o1, o2).build());
assertTrue(!new EqualsBuilder().append(o1, this).build());
assertEquals(Boolean.FALSE, new EqualsBuilder().append(o1, this).build());
assertTrue(!new EqualsBuilder().append(o1, null).build());
assertTrue(!new EqualsBuilder().append(null, o2).build());
assertTrue(new EqualsBuilder().append((Object) null, (Object) null).build());
assertEquals(Boolean.FALSE, new EqualsBuilder().append(o1, null).build());
assertEquals(Boolean.FALSE, new EqualsBuilder().append(null, o2).build());
assertEquals(Boolean.TRUE, new EqualsBuilder().append((Object) null, (Object) null).build());
}
@Test

View File

@ -17,8 +17,10 @@
package org.apache.commons.lang3.reflect;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;
@ -67,9 +69,9 @@ public class FieldUtilsTest {
assertNotNull(new FieldUtils());
Constructor<?>[] cons = FieldUtils.class.getDeclaredConstructors();
assertEquals(1, cons.length);
assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
assertEquals(true, Modifier.isPublic(FieldUtils.class.getModifiers()));
assertEquals(false, Modifier.isFinal(FieldUtils.class.getModifiers()));
assertTrue(Modifier.isPublic(cons[0].getModifiers()));
assertTrue(Modifier.isPublic(FieldUtils.class.getModifiers()));
assertFalse(Modifier.isFinal(FieldUtils.class.getModifiers()));
}
@Test

View File

@ -76,20 +76,20 @@ public class PairTest {
public void testComparable1() throws Exception {
Pair<String, String> pair1 = Pair.of("A", "D");
Pair<String, String> pair2 = Pair.of("B", "C");
assertEquals(true, pair1.compareTo(pair1) == 0);
assertEquals(true, pair1.compareTo(pair2) < 0);
assertEquals(true, pair2.compareTo(pair2) == 0);
assertEquals(true, pair2.compareTo(pair1) > 0);
assertTrue(pair1.compareTo(pair1) == 0);
assertTrue(pair1.compareTo(pair2) < 0);
assertTrue(pair2.compareTo(pair2) == 0);
assertTrue(pair2.compareTo(pair1) > 0);
}
@Test
public void testComparable2() throws Exception {
Pair<String, String> pair1 = Pair.of("A", "C");
Pair<String, String> pair2 = Pair.of("A", "D");
assertEquals(true, pair1.compareTo(pair1) == 0);
assertEquals(true, pair1.compareTo(pair2) < 0);
assertEquals(true, pair2.compareTo(pair2) == 0);
assertEquals(true, pair2.compareTo(pair1) > 0);
assertTrue(pair1.compareTo(pair1) == 0);
assertTrue(pair1.compareTo(pair2) < 0);
assertTrue(pair2.compareTo(pair2) == 0);
assertTrue(pair2.compareTo(pair1) > 0);
}
@Test