/** * 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"); }
/** * Expect that the results are different, throw TestException if same. * * @param expectation difference expectation. */ public static <T> void expect(DifferenceExpectation<T> expectation) { a(expectation.getExpected()).shouldNotBeEqual(expectation.exec()); } }
/** * 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 should be null. */ public void shouldBeNull() { if (actual != null) throw new TestException("argument is not null, but it should be"); }
/** * Synonym of methods {@link JSpec#the(Object)} or {@link JSpec#a(Object)}. * * @param o1 instance for checking * @return generalized expectation */ public static Expectation<Object> $(Object o1){ return a(o1); }
default <T> void expect(DifferenceExpectation<T> expectation) { JSpec.expect(expectation); } }
/** * Invokes a boolean method and uses return value in comparison. * * @param booleanMethod name of boolean method as specified in Java Beans specification. Example: if method name * is <code>isValid()</code>, then the string "valid" needs to be passed. This results in readable code * such as: * <pre> * a(bean).shouldBe("valid"); * </pre> */ public void shouldBe(String booleanMethod) { invokeBoolean(booleanMethod, Boolean.TRUE); }
/** * Alias to {@link #shouldBeEqual(Object)}. * * @param expected expected value. */ public void shouldEqual(T expected){ shouldBeEqual(expected); }
/** * This is for cases suh as: "hasErrors()": <code>a(p).shouldHave("errors")</code>. * Invokes a boolean method and uses return value in comparison. * @param booleanMethod name of boolean method as specified in Java Beans specification. Example: if method name * is <code>hasChildren()</code>, then the string "children" needs to be passed. This results in readable code * such as: * <pre> * a(bean).shouldHave("children"); * </pre> */ public void shouldHave(String booleanMethod) { shouldBe(booleanMethod); }
/** * Wrapper for {@link org.javalite.test.jspec.JSpec#it} */ default <T> Expectation<T> it(T o1) { return JSpec.it(o1); }
public static Expectation<Object> a(Object o1){ return new Expectation<>(o1); }
/** * This is for cases suh as: "hasErrors()": <code>a(p).shouldNotHave("errors")</code>. * Invokes a boolean method and uses return value in comparison. * @param booleanMethod name of boolean method as specified in Java Beans specification. Example: if method name * is <code>hasChildren()</code>, then the string "children" needs to be passed. This results in readable code * such as: * <pre> * a(bean).shouldNotHave("children"); * </pre> */ public void shouldNotHave(String booleanMethod) { shouldNotBe(booleanMethod); }
default Expectation<Object> the(Object o1){ return JSpec.the(o1); }
/** * Tested value should be false. */ public void shouldBeFalse() { checkNull(); if ((Boolean) actual) throw new TestException("should not be true, but it is"); }
/** * Tested reference should not be null. */ public void shouldNotBeNull() { if (actual == null) throw new TestException("Object is null, while it is not expected"); }
default <T> void expect(ExceptionExpectation<T> expectation){ JSpec.expect(expectation); }
/** * Invokes a boolean method and uses return value in comparison. * * @param booleanMethod name of boolean method as specified in Java Beans specification. Example: if method name * is <code>isValid()</code>, then the string "valid" needs to be passed. This results in readable code * such as: * <pre> * a(bean).shouldNotBe("valid"); * </pre> */ public void shouldNotBe(String booleanMethod) { invokeBoolean(booleanMethod, Boolean.FALSE); }
/** * 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"); }
/** * 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"); }