/** * Tested value should be null. */ public void shouldBeNull() { if (actual != null) throw new TestException("argument is not null, but it should be"); }
/** * Tested reference should not be null. */ public void shouldNotBeNull() { if (actual == null) throw new TestException("Object is null, while it is not expected"); }
/** * 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 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"); }
/** * This method is exactly opposite (negated) of {@link #shouldContain(Object)}. * * @param expected value that is expected to be NOT contained in a tested object. */ public void shouldNotContain(Object expected) { if(contains(expected)) throw new TestException("tested object contains the value: " + expected + ", but it should 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"); }
private TestException newShouldBeEqualException(T expected) { StringBuilder sb = new StringBuilder().append("Test object:\n"); if (actual == null) { sb.append("null"); } else { sb.append(actual.getClass().getName()).append(" == <").append(actual).append(">\n"); } sb.append("and expected\n"); if (expected == null) { sb.append("null"); } else { sb.append(expected.getClass().getName()).append(" == <").append(expected).append(">\n"); } sb.append("are not equal, but they should be."); return new TestException(sb.toString()); }
/** * 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); }
public static <T> void expect(ExceptionExpectation<T> expectation){ try{ expectation.exec(); }catch(Exception e){ if(!e.getClass().getName().equals(expectation.getClazz().getName())){ e.printStackTrace(); throw new TestException("Expected exception: " + expectation.getClazz() + ", but instead got: " + e); } return; } throw new TestException("Expected exception: " + expectation.getClazz() + ", but instead got nothing"); }
throw new TestException("tested value does not contain expected value: " + expected);
throw new TestException("Method: " + m.getName() + " should return " + returnValue + ", but returned " + result);
/** * Tested value should be null. */ public void shouldBeNull() { if (actual != null) throw new TestException("argument is not null, but it should be"); }
/** * Tested reference should not be null. */ public void shouldNotBeNull() { if (actual == null) throw new TestException("Object is null, while it is not expected"); }
/** * Tested value should be null. */ public void shouldBeNull() { if (actual != null) throw new TestException("argument is not null, but it should be"); }
/** * Tested reference should not be null. */ public void shouldNotBeNull() { if (actual == null) throw new TestException("Object is null, while it is not expected"); }
/** * 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"); }