private boolean contains(Object expected) { checkNull(); if (actual instanceof Collection) { return ((Collection) actual).contains(expected); } else if (actual instanceof Map) { return ((Map) actual).containsKey(expected); } else { return actual.toString().contains(expected.toString()); } }
/** * Tested value is the same reference value as expected. * * @param expected expected reference. */ public void shouldBeTheSameAs(T expected) { checkNull(); if (actual != expected) throw new TestException("references are not the same, but they should be"); }
/** * Tested value should be false. */ public void shouldBeFalse() { checkNull(); if ((Boolean) actual) throw new TestException("should not be true, but it is"); }
/** * Tested and expected values are not equal. * * @param expected expected value. */ public void shouldNotBeEqual(T expected) { checkNull(); if (actual.equals(expected)) throw new TestException("Objects: '" + actual + "' and '" + expected + "' are equal, but they should not be"); }
/** * Tested value should be true. */ public void shouldBeTrue() { checkNull(); if (!(Boolean) actual) throw new TestException("should be true, but it is not"); }
/** * Tested value is not the same reference value as expected. * * @param expected expected reference. */ public void shouldNotBeTheSameAs(T expected) { checkNull(); if (actual == expected) throw new TestException("references are the same, but they should not be"); }
/** * Tests that the Tested value is a specific type. * * @param clazz type the the expected value should have (or super type). Lets say the super type is Car, and sub type is * Toyota, then this test will pass: * <pre> * a(new Toyota()).shouldBeA(Car.class). * </pre> * Think of this not in terms of direct typing but from a point of view of inheritance. * <p> * Synonym for {@link #shouldBeA(Class)}. * */ public void shouldBeType(Class clazz) { checkNull(); if (!clazz.isAssignableFrom(actual.getClass())) throw new TestException(actual.getClass() + " is not " + clazz); }
/** * Tested value is equal expected. * * @param expected expected value. */ public void shouldBeEqual(T expected) { checkNull(); if (actual == null) { if (expected != null) { throw newShouldBeEqualException(expected); } } else { if (expected == null) { throw newShouldBeEqualException(expected); } //TODO: improve Number comparison, see http://stackoverflow.com/questions/2683202/comparing-the-values-of-two-generic-numbers if (actual instanceof Number && expected instanceof Number) { if (((Number) actual).doubleValue() != ((Number) expected).doubleValue()) { throw newShouldBeEqualException(expected); } } else if (!actual.equals(expected)) { throw newShouldBeEqualException(expected); } } }
checkNull(); String methodName1 = "is" + capitalize(booleanMethod); String methodName2 = "has" + capitalize(booleanMethod);
private boolean contains(Object expected) { checkNull(); if (actual instanceof Collection) { return ((Collection) actual).contains(expected); } else if (actual instanceof Map) { return ((Map) actual).containsKey(expected); } else { return actual.toString().contains(expected.toString()); } }
private boolean contains(Object expected) { checkNull(); if (actual instanceof Collection) { return ((Collection) actual).contains(expected); } else if (actual instanceof Map) { return ((Map) actual).containsKey(expected); } else { return actual.toString().contains(expected.toString()); } }
/** * Tested and expected values are not equal. * * @param expected expected value. */ public void shouldNotBeEqual(T expected) { checkNull(); if (actual.equals(expected)) throw new TestException("Objects: '" + actual + "' and '" + expected + "' are equal, but they should not be"); }
/** * Tested value is not the same reference value as expected. * * @param expected expected reference. */ public void shouldNotBeTheSameAs(T expected) { checkNull(); if (actual == expected) throw new TestException("references are the same, but they should not be"); }
/** * Tested value should be true. */ public void shouldBeTrue() { checkNull(); if (!(Boolean) actual) throw new TestException("should be true, but it is not"); }
/** * Tested value should be false. */ public void shouldBeFalse() { checkNull(); if ((Boolean) actual) throw new TestException("should not be true, but it is"); }
/** * Tested value should be true. */ public void shouldBeTrue() { checkNull(); if (!(Boolean) actual) throw new TestException("should be true, but it is not"); }
/** * Tested and expected values are not equal. * * @param expected expected value. */ public void shouldNotBeEqual(T expected) { checkNull(); if (actual.equals(expected)) throw new TestException("Objects: '" + actual + "' and '" + expected + "' are equal, but they should not be"); }
/** * Tested value should be false. */ public void shouldBeFalse() { checkNull(); if ((Boolean) actual) throw new TestException("should not be true, but it is"); }
/** * Tested value is the same reference value as expected. * * @param expected expected reference. */ public void shouldBeTheSameAs(T expected) { checkNull(); if (actual != expected) throw new TestException("references are not the same, but they should be"); }
/** * Tested value is not the same reference value as expected. * * @param expected expected reference. */ public void shouldNotBeTheSameAs(T expected) { checkNull(); if (actual == expected) throw new TestException("references are the same, but they should not be"); }