コード例 #1
0
  @Test
  public void testInstanceOf() {

    AlchemyAssertion<Object> instance = Assertions.instanceOf(Number.class);

    instance.check(one(positiveIntegers()));
    instance.check(one(positiveLongs()));
    instance.check(one(positiveDoubles()));

    assertThrows(() -> instance.check(one(alphabeticString())));
  }
コード例 #2
0
  @Test
  public void testNot() {
    AlchemyAssertion<Object> assertion = mock(AlchemyAssertion.class);
    doThrow(new FailedAssertionException()).when(assertion).check(any());

    AlchemyAssertion<Object> instance = Assertions.not(assertion);

    instance.check("");

    doNothing().when(assertion).check(any());

    assertThrows(() -> instance.check("")).isInstanceOf(FailedAssertionException.class);
  }
コード例 #3
0
  @Test
  public void testEqualTo() {
    String first = one(strings());
    String second = "";
    do {
      second = one(strings());
    } while (Objects.equals(first, second));

    AlchemyAssertion<String> instance = Assertions.equalTo(second);

    // Check against self should be ok;
    instance.check(second);
    instance.check("" + second);

    assertThrows(() -> instance.check(first)).isInstanceOf(FailedAssertionException.class);
  }
コード例 #4
0
  @Test
  public void testSameInstanceAs() {
    AlchemyAssertion<Object> instanceOne = Assertions.<Object>sameInstanceAs(null);

    // null is the same instance as null
    assertThat(instanceOne, notNullValue());
    instanceOne.check(null);

    // null is not the same instance as any other non-null object
    assertThrows(() -> instanceOne.check("")).isInstanceOf(FailedAssertionException.class);

    Object someObject = new Object();
    AlchemyAssertion<Object> instanceTwo = Assertions.sameInstanceAs(someObject);
    instanceTwo.check(someObject);

    Object differentObject = new Object();
    assertThrows(() -> instanceTwo.check(differentObject))
        .isInstanceOf(FailedAssertionException.class);
  }
コード例 #5
0
  @DontRepeat
  @Test
  public void testNotNull() throws Exception {

    AlchemyAssertion<Object> instance = notNull();
    assertThat(instance, notNullValue());
    Tests.checkForNullCase(instance);

    Object mock = mock(Object.class);
    instance.check(mock);
    verifyZeroInteractions(mock);
  }