コード例 #1
0
  @Test
  public void setStarRating_withNull_shouldSetStarRatingToNull() throws Exception {
    // Setting star rating to 0 before each case, so we can detect when it gets set to null
    final double initialStarRating = 0.0;

    subject.setStarRating(initialStarRating);
    subject.setStarRating(null);
    assertThat(subject.getStarRating()).isEqualTo(null);
  }
コード例 #2
0
  @Test
  public void setStarRating_withinValidRange_shouldSetStarRating() throws Exception {
    subject.setStarRating(0.0);
    assertThat(subject.getStarRating()).isEqualTo(0.0);

    subject.setStarRating(5.0);
    assertThat(subject.getStarRating()).isEqualTo(5.0);

    subject.setStarRating(2.5);
    assertThat(subject.getStarRating()).isEqualTo(2.5);
  }
コード例 #3
0
  @Test
  public void setStarRating_withValuesOutsideOfValidRange_shouldNotSetStarRating()
      throws Exception {
    // First, set star rating to a valid value
    final double initialStarRating = 4.9;
    subject.setStarRating(initialStarRating);

    subject.setStarRating(5.0001);
    assertThat(subject.getStarRating()).isEqualTo(initialStarRating);

    subject.setStarRating(-0.001);
    assertThat(subject.getStarRating()).isEqualTo(initialStarRating);
  }
コード例 #4
0
  @Test
  public void setStarRating_withNanOrInf_shouldNotSetStarRating() throws Exception {
    // First, set star rating to a valid value
    final double initialStarRating = 3.75;
    subject.setStarRating(initialStarRating);

    subject.setStarRating(Double.NaN);
    assertThat(subject.getStarRating()).isEqualTo(initialStarRating);

    subject.setStarRating(Double.POSITIVE_INFINITY);
    assertThat(subject.getStarRating()).isEqualTo(initialStarRating);

    subject.setStarRating(Double.NEGATIVE_INFINITY);
    assertThat(subject.getStarRating()).isEqualTo(initialStarRating);
  }