Class Expectation<T>


  • public class Expectation<T>
    extends Object
    Author:
    Igor Polevoy, Eric Nielsen
    • Constructor Detail

      • Expectation

        public Expectation​(T actual)
    • Method Detail

      • shouldEqual

        public void shouldEqual​(T expected)
        Parameters:
        expected - expected value.
      • shouldBeEqual

        public void shouldBeEqual​(T expected)
        Tested value is equal expected.
        Parameters:
        expected - expected value.
      • shouldHave

        public void shouldHave​(String booleanMethod)
        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 is hasChildren(), then the string "children" needs to be passed. This results in readable code such as:
         a(bean).shouldHave("children");
         
      • shouldNotHave

        public void shouldNotHave​(String booleanMethod)
        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 is hasChildren(), then the string "children" needs to be passed. This results in readable code such as:
         a(bean).shouldNotHave("children");
         
      • shouldBe

        public void shouldBe​(String booleanMethod)
        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 is isValid(), then the string "valid" needs to be passed. This results in readable code such as:
         a(bean).shouldBe("valid");
         
      • shouldNotBe

        public void shouldNotBe​(String booleanMethod)
        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 is isValid(), then the string "valid" needs to be passed. This results in readable code such as:
         a(bean).shouldNotBe("valid");
         
      • shouldNotBeEqual

        public void shouldNotBeEqual​(T expected)
        Tested and expected values are not equal.
        Parameters:
        expected - expected value.
      • shouldNotBeNull

        public void shouldNotBeNull()
        Tested reference should not be null.
      • shouldBeType

        public void shouldBeType​(Class clazz)
        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

        public void shouldBeA​(Class clazz)
        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

        public void shouldBeTheSameAs​(T expected)
        Tested value is the same reference value as expected.
        Parameters:
        expected - expected reference.
      • shouldContain

        public void shouldContain​(Object expected)
        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:
          
                   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");
               
               
        • 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

        public void shouldNotContain​(Object expected)
        This method is exactly opposite (negated) of shouldContain(Object).
        Parameters:
        expected - value that is expected to be NOT contained in a tested object.
      • shouldNotBeTheSameAs

        public void shouldNotBeTheSameAs​(T expected)
        Tested value is not the same reference value as expected.
        Parameters:
        expected - expected reference.