Ejemplo n.º 1
0
 @Test
 public void test_toIntegerObject_boolean_Integer_Integer() {
   Integer six = Integer.valueOf(6);
   Integer seven = Integer.valueOf(7);
   assertEquals(six, BooleanUtils.toIntegerObject(true, six, seven));
   assertEquals(seven, BooleanUtils.toIntegerObject(false, six, seven));
 }
Ejemplo n.º 2
0
 @Test
 public void test_toBooleanObject_Integer() {
   assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(Integer.valueOf(1)));
   assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(Integer.valueOf(-1)));
   assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(Integer.valueOf(0)));
   assertEquals(null, BooleanUtils.toBooleanObject((Integer) null));
 }
Ejemplo n.º 3
0
  @Test
  public void testOr_primitive_validInput_2items() {
    assertTrue("False result for (true, true)", BooleanUtils.or(new boolean[] {true, true}));

    assertTrue("True result for (false, false)", !BooleanUtils.or(new boolean[] {false, false}));

    assertTrue("False result for (true, false)", BooleanUtils.or(new boolean[] {true, false}));

    assertTrue("False result for (false, true)", BooleanUtils.or(new boolean[] {false, true}));
  }
Ejemplo n.º 4
0
 @Test
 public void test_toIntegerObject_Boolean_Integer_Integer_Integer() {
   Integer six = Integer.valueOf(6);
   Integer seven = Integer.valueOf(7);
   Integer eight = Integer.valueOf(8);
   assertEquals(six, BooleanUtils.toIntegerObject(Boolean.TRUE, six, seven, eight));
   assertEquals(seven, BooleanUtils.toIntegerObject(Boolean.FALSE, six, seven, eight));
   assertEquals(eight, BooleanUtils.toIntegerObject((Boolean) null, six, seven, eight));
   assertEquals(null, BooleanUtils.toIntegerObject((Boolean) null, six, seven, null));
 }
Ejemplo n.º 5
0
  @Test
  public void test_toBoolean_Integer_Integer_Integer() {
    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));

    assertEquals(true, BooleanUtils.toBoolean(Integer.valueOf(6), six, seven));
    assertEquals(false, BooleanUtils.toBoolean(Integer.valueOf(7), six, seven));
  }
Ejemplo n.º 6
0
  @Test
  public void testOr_object_validInput_3items() {
    assertTrue(
        "False result for (false, false, true)",
        BooleanUtils.or(new Boolean[] {Boolean.FALSE, Boolean.FALSE, Boolean.TRUE}).booleanValue());

    assertTrue(
        "False result for (false, true, false)",
        BooleanUtils.or(new Boolean[] {Boolean.FALSE, Boolean.TRUE, Boolean.FALSE}).booleanValue());

    assertTrue(
        "False result for (true, false, false)",
        BooleanUtils.or(new Boolean[] {Boolean.TRUE, Boolean.FALSE, Boolean.FALSE}).booleanValue());

    assertTrue(
        "False result for (true, true, true)",
        BooleanUtils.or(new Boolean[] {Boolean.TRUE, Boolean.TRUE, Boolean.TRUE}).booleanValue());

    assertTrue(
        "True result for (false, false)",
        !BooleanUtils.or(new Boolean[] {Boolean.FALSE, Boolean.FALSE, Boolean.FALSE})
            .booleanValue());

    assertTrue(
        "False result for (true, true, false)",
        BooleanUtils.or(new Boolean[] {Boolean.TRUE, Boolean.TRUE, Boolean.FALSE}).booleanValue());

    assertTrue(
        "False result for (true, false, true)",
        BooleanUtils.or(new Boolean[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE}).booleanValue());

    assertTrue(
        "False result for (false, true, true)",
        BooleanUtils.or(new Boolean[] {Boolean.FALSE, Boolean.TRUE, Boolean.TRUE}).booleanValue());
  }
Ejemplo n.º 7
0
 @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")));
 }
Ejemplo n.º 8
0
 @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));
 }
Ejemplo n.º 9
0
  @Test
  public void test_toBooleanObject_String_String_String_String() {
    assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((String) null, null, "N", "U"));
    assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((String) null, "Y", null, "U"));
    assertSame(null, BooleanUtils.toBooleanObject((String) null, "Y", "N", null));

    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("Y", "Y", "N", "U"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("N", "Y", "N", "U"));
    assertEquals(null, BooleanUtils.toBooleanObject("U", "Y", "N", "U"));
  }
Ejemplo n.º 10
0
  @Test
  public void test_toBooleanObject_Integer_Integer_Integer_Integer() {
    Integer six = Integer.valueOf(6);
    Integer seven = Integer.valueOf(7);
    Integer eight = Integer.valueOf(8);

    assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject((Integer) null, null, seven, eight));
    assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject((Integer) null, six, null, eight));
    assertSame(null, BooleanUtils.toBooleanObject((Integer) null, six, seven, null));

    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(Integer.valueOf(6), six, seven, eight));
    assertEquals(
        Boolean.FALSE, BooleanUtils.toBooleanObject(Integer.valueOf(7), six, seven, eight));
    assertEquals(null, BooleanUtils.toBooleanObject(Integer.valueOf(8), six, seven, eight));
  }
Ejemplo n.º 11
0
  // -----------------------------------------------------------------------
  // -----------------------------------------------------------------------
  @Test
  public void test_toBooleanObject_String() {
    assertEquals(null, BooleanUtils.toBooleanObject((String) null));
    assertEquals(null, BooleanUtils.toBooleanObject(""));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("false"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("no"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("off"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("FALSE"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("NO"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("OFF"));
    assertEquals(null, BooleanUtils.toBooleanObject("oof"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("true"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("yes"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("on"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TRUE"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("ON"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("YES"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TruE"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TruE"));

    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("y"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("Y"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("t"));
    assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("T"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("f"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("F"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("n"));
    assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("N"));
    assertEquals(null, BooleanUtils.toBooleanObject("z"));

    assertEquals(null, BooleanUtils.toBooleanObject("ab"));
    assertEquals(null, BooleanUtils.toBooleanObject("yoo"));
  }
Ejemplo n.º 12
0
 @Test(expected = IllegalArgumentException.class)
 public void testOr_primitive_emptyInput() {
   BooleanUtils.or(new boolean[] {});
 }
Ejemplo n.º 13
0
 @Test(expected = IllegalArgumentException.class)
 public void testAnd_object_emptyInput() {
   BooleanUtils.and(new Boolean[] {});
 }
Ejemplo n.º 14
0
 //  testAnd
 //  -----------------------------------------------------------------------
 @Test(expected = IllegalArgumentException.class)
 public void testAnd_primitive_nullInput() {
   BooleanUtils.and((boolean[]) null);
 }
Ejemplo n.º 15
0
 @Test(expected = IllegalArgumentException.class)
 public void test_toBoolean_String_String_String_nullValue() {
   BooleanUtils.toBoolean(null, "Y", "N");
 }
Ejemplo n.º 16
0
 // -----------------------------------------------------------------------
 @Test
 public void test_toBoolean_Boolean() {
   assertEquals(true, BooleanUtils.toBoolean(Boolean.TRUE));
   assertEquals(false, BooleanUtils.toBoolean(Boolean.FALSE));
   assertEquals(false, BooleanUtils.toBoolean((Boolean) null));
 }
Ejemplo n.º 17
0
 @Test(expected = IllegalArgumentException.class)
 public void testOr_object_nullElementInput() {
   BooleanUtils.or(new Boolean[] {null});
 }
Ejemplo n.º 18
0
 @Test
 public void test_toStringOnOff_boolean() {
   assertEquals("on", BooleanUtils.toStringOnOff(true));
   assertEquals("off", BooleanUtils.toStringOnOff(false));
 }
Ejemplo n.º 19
0
 @Test
 public void test_toString_Boolean_String_String_String() {
   assertEquals("U", BooleanUtils.toString((Boolean) null, "Y", "N", "U"));
   assertEquals("Y", BooleanUtils.toString(Boolean.TRUE, "Y", "N", "U"));
   assertEquals("N", BooleanUtils.toString(Boolean.FALSE, "Y", "N", "U"));
 }
Ejemplo n.º 20
0
 @Test
 public void test_toStringYesNo_Boolean() {
   assertEquals(null, BooleanUtils.toStringYesNo((Boolean) null));
   assertEquals("yes", BooleanUtils.toStringYesNo(Boolean.TRUE));
   assertEquals("no", BooleanUtils.toStringYesNo(Boolean.FALSE));
 }
Ejemplo n.º 21
0
 @Test
 public void test_toStringOnOff_Boolean() {
   assertEquals(null, BooleanUtils.toStringOnOff((Boolean) null));
   assertEquals("on", BooleanUtils.toStringOnOff(Boolean.TRUE));
   assertEquals("off", BooleanUtils.toStringOnOff(Boolean.FALSE));
 }
Ejemplo n.º 22
0
 // -----------------------------------------------------------------------
 @Test
 public void test_toStringTrueFalse_Boolean() {
   assertEquals(null, BooleanUtils.toStringTrueFalse((Boolean) null));
   assertEquals("true", BooleanUtils.toStringTrueFalse(Boolean.TRUE));
   assertEquals("false", BooleanUtils.toStringTrueFalse(Boolean.FALSE));
 }
Ejemplo n.º 23
0
 @Test(expected = IllegalArgumentException.class)
 public void test_toBoolean_String_String_String_noMatch() {
   BooleanUtils.toBoolean("X", "Y", "N");
 }
Ejemplo n.º 24
0
 @Test
 public void test_isNotFalse_Boolean() {
   assertEquals(true, BooleanUtils.isNotFalse(Boolean.TRUE));
   assertEquals(false, BooleanUtils.isNotFalse(Boolean.FALSE));
   assertEquals(true, BooleanUtils.isNotFalse((Boolean) null));
 }
Ejemplo n.º 25
0
 @Test(expected = IllegalArgumentException.class)
 public void testOr_object_nullInput() {
   BooleanUtils.or((Boolean[]) null);
 }
Ejemplo n.º 26
0
 @Test
 public void test_toStringYesNo_boolean() {
   assertEquals("yes", BooleanUtils.toStringYesNo(true));
   assertEquals("no", BooleanUtils.toStringYesNo(false));
 }
Ejemplo n.º 27
0
 @Test
 public void test_toString_boolean_String_String_String() {
   assertEquals("Y", BooleanUtils.toString(true, "Y", "N"));
   assertEquals("N", BooleanUtils.toString(false, "Y", "N"));
 }
Ejemplo n.º 28
0
 // -----------------------------------------------------------------------
 @Test
 public void test_negate_Boolean() {
   assertSame(null, BooleanUtils.negate(null));
   assertSame(Boolean.TRUE, BooleanUtils.negate(Boolean.FALSE));
   assertSame(Boolean.FALSE, BooleanUtils.negate(Boolean.TRUE));
 }
Ejemplo n.º 29
0
 // -----------------------------------------------------------------------
 @Test
 public void test_toStringTrueFalse_boolean() {
   assertEquals("true", BooleanUtils.toStringTrueFalse(true));
   assertEquals("false", BooleanUtils.toStringTrueFalse(false));
 }
Ejemplo n.º 30
0
  // -----------------------------------------------------------------------
  @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"));

    assertEquals(false, BooleanUtils.toBoolean("no"));
    assertEquals(false, BooleanUtils.toBoolean("off"));
    assertEquals(false, BooleanUtils.toBoolean("yoo"));
  }