示例#1
0
  @Test
  public void shouldUseTheStringValueOfTheFirstSecondAndThirdInToString() {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);

    // When
    String stringRepresentation = triple.toString();

    // Then
    assertThat(stringRepresentation, is("(5, Five, true)"));
  }
示例#2
0
  @Test(expected = NullPointerException.class)
  public void shouldThrowNullPointerExceptionIfNullMapperPassedToMapThird() throws Exception {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);
    Mapper<Boolean, String> mapper = null;

    // When
    triple.mapThird(mapper);

    // Then a NullPointerException is thrown
  }
示例#3
0
  @Test
  public void shouldBeEqualIfHasSameFirstSecondAndThird() {
    // Given
    Triple<Integer, String, Boolean> triple1 = tuple(5, "Five", true);
    Triple<Integer, String, Boolean> triple2 = tuple(5, "Five", true);

    // When
    Boolean isEqual = triple1.equals(triple2);

    // Then
    assertThat(isEqual, is(true));
  }
示例#4
0
  @Test(expected = NullPointerException.class)
  public void shouldThrowNullPointerExceptionIfNullUnaryFunctionPassedToMapThird()
      throws Exception {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);
    UnaryFunction<Boolean, String> function = null;

    // When
    triple.mapThird(function);

    // Then a NullPointerException is thrown
  }
示例#5
0
  @Test
  public void shouldNotBeEqualIfHasDifferentThird() {
    // Given
    Triple<Integer, String, Boolean> triple1 = tuple(5, "Five", true);
    Triple<Integer, String, Boolean> triple2 = tuple(5, "Five", false);

    // When
    Boolean isEqual = triple1.equals(triple2);

    // Then
    assertThat(isEqual, is(false));
  }
示例#6
0
  @Test
  public void shouldNotBeEqualIfNotATriple() throws Exception {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);
    Iterable<Object> iterable = iterableBuilderOf(Object.class).with(5, "five", true).build();

    // When
    boolean firstDirection = triple.equals(iterable);
    boolean secondDirection = iterable.equals(triple);

    // Then
    assertThat(firstDirection, is(false));
    assertThat(secondDirection, is(false));
  }
示例#7
0
  @Test
  public void shouldBeMappableUsingUnaryFunctionOnThirdPosition() throws Exception {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);
    UnaryFunction<Boolean, String> function =
        new UnaryFunction<Boolean, String>() {
          @Override
          public String call(Boolean input) {
            return input.toString();
          }
        };
    Triple<Integer, String, String> expected = tuple(5, "Five", "true");

    // When
    Triple<Integer, String, String> actual = triple.mapThird(function);

    // Then
    assertThat(actual, is(expected));
  }
示例#8
0
  @Test
  public void shouldBeMappableUsingUnaryFunctionOnSecondPosition() throws Exception {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);
    UnaryFunction<String, Integer> function =
        new UnaryFunction<String, Integer>() {
          @Override
          public Integer call(String input) {
            return input.length();
          }
        };
    Triple<Integer, Integer, Boolean> expected = tuple(5, 4, true);

    // When
    Triple<Integer, Integer, Boolean> actual = triple.mapSecond(function);

    // Then
    assertThat(actual, is(expected));
  }
示例#9
0
  @Test
  public void shouldBeMappableUsingUnaryFunctionOnFirstPosition() throws Exception {
    // Given
    Triple<Integer, String, Boolean> triple = tuple(5, "Five", true);
    UnaryFunction<Integer, String> function =
        new UnaryFunction<Integer, String>() {
          @Override
          public String call(Integer input) {
            return String.valueOf(input);
          }
        };
    Triple<String, String, Boolean> expected = tuple("5", "Five", true);

    // When
    Triple<String, String, Boolean> actual = triple.mapFirst(function);

    // Then
    assertThat(actual, is(expected));
  }