Package org.javalite.test.jspec
Class Expectation<T>
java.lang.Object
org.javalite.test.jspec.Expectation<T>
- Author:
- Igor Polevoy, Eric Nielsen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInvokes a boolean method and uses return value in comparison.voidTests that the Tested value is a specific type.voidshouldBeEqual(T expected)Tested value is equal expected.voidTested value should be false.voidTested value should be null.voidshouldBeTheSameAs(T expected)Tested value is the same reference value as expected.voidTested value should be true.voidshouldBeType(Class clazz)Tests that the Tested value is a specific type.voidshouldContain(Object expected)Tests that an expected value is contained in the tested object.voidshouldEqual(T expected)Alias toshouldBeEqual(Object).voidshouldHave(String booleanMethod)This is for cases suh as: "hasErrors()":a(p).shouldHave("errors").voidshouldNotBe(String booleanMethod)Invokes a boolean method and uses return value in comparison.voidshouldNotBeEqual(T expected)Tested and expected values are not equal.voidTested reference should not be null.voidshouldNotBeTheSameAs(T expected)Tested value is not the same reference value as expected.voidshouldNotContain(Object expected)This method is exactly opposite (negated) ofshouldContain(Object).voidshouldNotHave(String booleanMethod)This is for cases suh as: "hasErrors()":a(p).shouldNotHave("errors").
-
Constructor Details
-
Expectation
-
-
Method Details
-
shouldEqual
Alias toshouldBeEqual(Object).- Parameters:
expected- expected value.
-
shouldBeEqual
Tested value is equal expected.- Parameters:
expected- expected value.
-
shouldHave
This is for cases suh as: "hasErrors()":a(p).shouldHave("errors"). Invokes a boolean method and uses return value in comparison.- Parameters:
booleanMethod- name of boolean method as specified in Java Beans specification. Example: if method name ishasChildren(), then the string "children" needs to be passed. This results in readable code such as:a(bean).shouldHave("children");
-
shouldNotHave
This is for cases suh as: "hasErrors()":a(p).shouldNotHave("errors"). Invokes a boolean method and uses return value in comparison.- Parameters:
booleanMethod- name of boolean method as specified in Java Beans specification. Example: if method name ishasChildren(), then the string "children" needs to be passed. This results in readable code such as:a(bean).shouldNotHave("children");
-
shouldBe
Invokes a boolean method and uses return value in comparison.- Parameters:
booleanMethod- name of boolean method as specified in Java Beans specification. Example: if method name isisValid(), then the string "valid" needs to be passed. This results in readable code such as:a(bean).shouldBe("valid");
-
shouldNotBe
Invokes a boolean method and uses return value in comparison.- Parameters:
booleanMethod- name of boolean method as specified in Java Beans specification. Example: if method name isisValid(), then the string "valid" needs to be passed. This results in readable code such as:a(bean).shouldNotBe("valid");
-
shouldNotBeEqual
Tested and expected values are not equal.- Parameters:
expected- expected value.
-
shouldNotBeNull
public void shouldNotBeNull()Tested reference should not be null. -
shouldBeType
Tests that the Tested value is a specific type.- Parameters:
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:a(new Toyota()).shouldBeA(Car.class).Think of this not in terms of direct typing but from a point of view of inheritance.Synonym for
shouldBeA(Class).
-
shouldBeA
Tests that the Tested value is a specific type.- Parameters:
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:a(new Toyota()).shouldBeA(Car.class).Think of this not in terms of direct typing but from a point of view of inheritance.Synonym for
shouldBeType(Class).
-
shouldBeFalse
public void shouldBeFalse()Tested value should be false. -
shouldBeTrue
public void shouldBeTrue()Tested value should be true. -
shouldBeNull
public void shouldBeNull()Tested value should be null. -
shouldBeTheSameAs
Tested value is the same reference value as expected.- Parameters:
expected- expected reference.
-
shouldContain
Tests that an expected value is contained in the tested object. The tested object can be of the following types:java.util.List- in this case, the tested list is expected to contain an expected object. For example, this will pass:
This usesa(Arrays.asList(1, 2, 3)).shouldContain(3);List.contains(Object)logicjava.util.Map- in this case, the tested map is expected to contain an object whose key is the expected object. For example, this will pass:Map map = new HashMap(); map.put("one", 1); map.put("two", 2); map.put("three", 3); a(map).shouldContain("two");- Any object - in this case, the string representation of this object is tested to contain a string representation of
expected value as a substring.For example, this will pass:
the("meaning of life is 42").shouldContain("meaning");
- Parameters:
expected- value that is expected to be contained in a tested object.
-
shouldNotContain
This method is exactly opposite (negated) ofshouldContain(Object).- Parameters:
expected- value that is expected to be NOT contained in a tested object.
-
shouldNotBeTheSameAs
Tested value is not the same reference value as expected.- Parameters:
expected- expected reference.
-