Package org.javalite.test.jspec
Class Expectation<T>
java.lang.Object
org.javalite.test.jspec.Expectation<T>
- Author:
- Igor Polevoy, Eric Nielsen
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Invokes a boolean method and uses return value in comparison.void
Tests that the Tested value is a specific type.void
shouldBeEqual(T expected)
Tested value is equal expected.void
Tested value should be false.void
Tested value should be null.void
shouldBeTheSameAs(T expected)
Tested value is the same reference value as expected.void
Tested value should be true.void
shouldBeType(Class clazz)
Tests that the Tested value is a specific type.void
shouldContain(Object expected)
Tests that an expected value is contained in the tested object.void
shouldEqual(T expected)
Alias toshouldBeEqual(Object)
.void
shouldHave(String booleanMethod)
This is for cases suh as: "hasErrors()":a(p).shouldHave("errors")
.void
shouldNotBe(String booleanMethod)
Invokes a boolean method and uses return value in comparison.void
shouldNotBeEqual(T expected)
Tested and expected values are not equal.void
Tested reference should not be null.void
shouldNotBeTheSameAs(T expected)
Tested value is not the same reference value as expected.void
shouldNotContain(Object expected)
This method is exactly opposite (negated) ofshouldContain(Object)
.void
shouldNotHave(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.
-