/** Scenario: Service throws a RuntimeException Should throw a 500 - */
  @Test
  public void testCanHandleARuntimeException() {

    when(primeService.getPrimes(any(PrimeNumberRequest.class)))
        .thenThrow(new RuntimeException("Test RuntimeException"));
    requestSpec
        .get("/prime")
        .prettyPeek()
        .then()
        .statusCode(500)
        .body("errors.id", containsInAnyOrder("Internal Server Error"))
        .body("errors.message", containsInAnyOrder("Test RuntimeException"))
        .body("errors.value", containsInAnyOrder(""));
  }
  /** Scenario: hit /prime?start=10. Should return values between 0 and 50; */
  @Test
  public void testCanSupplyValueForEndRange() {

    List<Integer> primes = Arrays.asList(2, 3, 5, 7);
    PrimeNumberRequest primeNumberRequest = new PrimeNumberRequest(0, 10, 25);

    when(primeService.getPrimes(primeNumberRequest)).thenReturn(primes);
    requestSpec
        .get("/prime?end=10")
        .prettyPeek()
        .then()
        .statusCode(200)
        .body("data", containsInAnyOrder(2, 3, 5, 7));

    verify(primeService).getPrimes(primeNumberRequest);
  }
  /** Scenario: hit /prime?start=10. Should return values between 10 and 100; */
  @Test
  public void testCanSupplyValueForStartRange() {

    List<Integer> primes = Arrays.asList(11, 13, 17, 19, 23, 29);
    PrimeNumberRequest primeNumberRequest = new PrimeNumberRequest(10, 100, 25);

    when(primeService.getPrimes(primeNumberRequest)).thenReturn(primes);
    requestSpec
        .get("/prime?start=10")
        .prettyPeek()
        .then()
        .statusCode(200)
        .body("data", containsInAnyOrder(11, 13, 17, 19, 23, 29));

    verify(primeService).getPrimes(primeNumberRequest);
  }
  /**
   * Scenario: hit /prime with no parameters Should use default values for start (0), end (100) and
   * limit (25) and return all prime numbers up to 100
   */
  @Test
  public void testHappyPath() {

    List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);
    PrimeNumberRequest primeNumberRequest = new PrimeNumberRequest(0, 100, 25);

    when(primeService.getPrimes(primeNumberRequest)).thenReturn(primes);
    requestSpec
        .get("/prime")
        .prettyPeek()
        .then()
        .statusCode(200)
        .body("data", containsInAnyOrder(2, 3, 5, 7, 11, 13, 17, 19, 23, 29));

    verify(primeService).getPrimes(primeNumberRequest);
  }