This commit is contained in:
Looly
2022-09-13 11:11:36 +08:00
parent c72bc8c721
commit 18daa4b431
3 changed files with 74 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ import org.junit.Assert;
import org.junit.Test;
public class BooleanUtilTest {
@Test
public void toBooleanTest() {
Assert.assertTrue(BooleanUtil.toBoolean("true"));
@@ -16,27 +16,74 @@ public class BooleanUtilTest {
Assert.assertTrue(BooleanUtil.toBoolean(""));
Assert.assertTrue(BooleanUtil.toBoolean(""));
Assert.assertTrue(BooleanUtil.toBoolean(""));
Assert.assertFalse(BooleanUtil.toBoolean("false"));
Assert.assertFalse(BooleanUtil.toBoolean("6455434"));
Assert.assertFalse(BooleanUtil.toBoolean(""));
}
@Test
public void andTest(){
Assert.assertFalse(BooleanUtil.and(true,false));
Assert.assertFalse(BooleanUtil.andOfWrap(true,false));
public void andTest() {
Assert.assertFalse(BooleanUtil.and(true, false));
Assert.assertFalse(BooleanUtil.andOfWrap(true, false));
}
@Test
public void orTest(){
Assert.assertTrue(BooleanUtil.or(true,false));
Assert.assertTrue(BooleanUtil.orOfWrap(true,false));
public void orTest() {
Assert.assertTrue(BooleanUtil.or(true, false));
Assert.assertTrue(BooleanUtil.orOfWrap(true, false));
}
@Test
public void xorTest(){
Assert.assertTrue(BooleanUtil.xor(true,false));
Assert.assertTrue(BooleanUtil.xorOfWrap(true,false));
public void xorTest() {
Assert.assertTrue(BooleanUtil.xor(true, false));
Assert.assertTrue(BooleanUtil.xorOfWrap(true, false));
}
@SuppressWarnings("ConstantConditions")
@Test
public void isTrueIsFalseTest() {
Assert.assertFalse(BooleanUtil.isTrue(null));
Assert.assertFalse(BooleanUtil.isFalse(null));
}
@Test
public void orOfWrapTest() {
Assert.assertFalse(BooleanUtil.orOfWrap(Boolean.FALSE, null));
Assert.assertTrue(BooleanUtil.orOfWrap(Boolean.TRUE, null));
}
@SuppressWarnings("ConstantConditions")
@Test
public void negateTest() {
Assert.assertFalse(BooleanUtil.negate(Boolean.TRUE));
Assert.assertTrue(BooleanUtil.negate(Boolean.FALSE));
Assert.assertFalse(BooleanUtil.negate(Boolean.TRUE.booleanValue()));
Assert.assertTrue(BooleanUtil.negate(Boolean.FALSE.booleanValue()));
}
@Test
public void toStringTest() {
Assert.assertEquals("true", BooleanUtil.toStringTrueFalse(true));
Assert.assertEquals("false", BooleanUtil.toStringTrueFalse(false));
Assert.assertEquals("yes", BooleanUtil.toStringYesNo(true));
Assert.assertEquals("no", BooleanUtil.toStringYesNo(false));
Assert.assertEquals("on", BooleanUtil.toStringOnOff(true));
Assert.assertEquals("off", BooleanUtil.toStringOnOff(false));
}
@SuppressWarnings("ConstantConditions")
@Test
public void toBooleanObjectTest(){
Assert.assertTrue(BooleanUtil.toBooleanObject("yes"));
Assert.assertTrue(BooleanUtil.toBooleanObject(""));
Assert.assertTrue(BooleanUtil.toBooleanObject(""));
Assert.assertTrue(BooleanUtil.toBooleanObject(""));
Assert.assertNull(BooleanUtil.toBooleanObject(null));
Assert.assertNull(BooleanUtil.toBooleanObject("不识别"));
}
}