Пример #1
0
  public void testExceptionIfNot5xx() {
    FalseOn5xx function = new FalseOn5xx();
    HttpResponse response = EasyMock.createMock(HttpResponse.class);
    HttpResponseException exception = EasyMock.createMock(HttpResponseException.class);

    // Status code is called twice
    expect(response.getStatusCode()).andReturn(600);
    expect(response.getStatusCode()).andReturn(600);
    // Get response gets called twice
    expect(exception.getResponse()).andReturn(response);
    expect(exception.getResponse()).andReturn(response);
    // Get cause is called to determine the root cause
    expect(exception.getCause()).andReturn(null);

    replay(response);
    replay(exception);

    try {
      function.createOrPropagate(exception);
    } catch (Exception ex) {
      assertEquals(ex, exception);
    }

    verify(response);
    verify(exception);
  }
Пример #2
0
  public void testOriginalExceptionIfNotHttpResponseException() {
    FalseOn5xx function = new FalseOn5xx();
    RuntimeException exception = new RuntimeException();

    try {
      function.createOrPropagate(exception);
    } catch (Exception ex) {
      assertEquals(ex, exception);
    }
  }
Пример #3
0
  public void testFalseIf5xx() throws Exception {
    FalseOn5xx function = new FalseOn5xx();
    HttpResponse response = EasyMock.createMock(HttpResponse.class);
    HttpResponseException exception = EasyMock.createMock(HttpResponseException.class);

    // Status code is called twice
    expect(response.getStatusCode()).andReturn(503);
    expect(response.getStatusCode()).andReturn(503);
    // Get response gets called twice
    expect(exception.getResponse()).andReturn(response);
    expect(exception.getResponse()).andReturn(response);
    // Get cause is called to determine the root cause
    expect(exception.getCause()).andReturn(null);

    replay(response);
    replay(exception);

    assertFalse(function.createOrPropagate(exception));

    verify(response);
    verify(exception);
  }