public class Expectation<T> extends Object
Constructor and Description |
---|
Expectation(T actual) |
Modifier and Type | Method and Description |
---|---|
void |
shouldBe(String booleanMethod)
Invokes a boolean method and uses return value in comparison.
|
void |
shouldBeA(Class clazz)
Tests that the Tested value is a specific type.
|
void |
shouldBeEqual(T expected)
Tested value is equal expected.
|
void |
shouldBeFalse()
Tested value should be false.
|
void |
shouldBeNull()
Tested value should be null.
|
void |
shouldBeTheSameAs(T expected)
Tested value is the same reference value as expected.
|
void |
shouldBeTrue()
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 to
shouldBeEqual(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 |
shouldNotBeNull()
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) of
shouldContain(Object) . |
void |
shouldNotHave(String booleanMethod)
This is for cases suh as: "hasErrors()":
a(p).shouldNotHave("errors") . |
public Expectation(T actual)
public void shouldEqual(T expected)
shouldBeEqual(Object)
.expected
- expected value.public void shouldBeEqual(T expected)
expected
- expected value.public void shouldHave(String booleanMethod)
a(p).shouldHave("errors")
.
Invokes a boolean method and uses return value in comparison.booleanMethod
- name of boolean method as specified in Java Beans specification. Example: if method name
is hasChildren()
, then the string "children" needs to be passed. This results in readable code
such as:
a(bean).shouldHave("children");
public void shouldNotHave(String booleanMethod)
a(p).shouldNotHave("errors")
.
Invokes a boolean method and uses return value in comparison.booleanMethod
- name of boolean method as specified in Java Beans specification. Example: if method name
is hasChildren()
, then the string "children" needs to be passed. This results in readable code
such as:
a(bean).shouldNotHave("children");
public void shouldBe(String booleanMethod)
booleanMethod
- name of boolean method as specified in Java Beans specification. Example: if method name
is isValid()
, then the string "valid" needs to be passed. This results in readable code
such as:
a(bean).shouldBe("valid");
public void shouldNotBe(String booleanMethod)
booleanMethod
- name of boolean method as specified in Java Beans specification. Example: if method name
is isValid()
, then the string "valid" needs to be passed. This results in readable code
such as:
a(bean).shouldNotBe("valid");
public void shouldNotBeEqual(T expected)
expected
- expected value.public void shouldNotBeNull()
public void shouldBeType(Class clazz)
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)
.
public void shouldBeA(Class clazz)
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)
.
public void shouldBeFalse()
public void shouldBeTrue()
public void shouldBeNull()
public void shouldBeTheSameAs(T expected)
expected
- expected reference.public void shouldContain(Object expected)
java.util.List
- in this case, the tested list is expected to contain an expected object.
For example, this will pass:
a(Arrays.asList(1, 2, 3)).shouldContain(3);
This uses List.contains(Object)
logic
java.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");
the("meaning of life is 42").shouldContain("meaning");
expected
- value that is expected to be contained in a tested object.public void shouldNotContain(Object expected)
shouldContain(Object)
.expected
- value that is expected to be NOT contained in a tested object.public void shouldNotBeTheSameAs(T expected)
expected
- expected reference.Copyright © 2019 JavaLite. All rights reserved.