Example #1
0
  @Test(expected = AccountException.class)
  public void validateWithErrorShouldThrowException() throws InterruptedException {
    server.enqueue(
        new MockResponse()
            .setResponseCode(401)
            .setBody("{'error':'Unauthorized','message':'Credentials are invalid'}"));

    Tinify.setKey("invalid");
    Tinify.validate();

    RecordedRequest request = server.takeRequest();
    assertEquals("POST /shrink HTTP/1.1", request.getRequestLine());
    assertEquals(0, request.getBody().size());
  }
Example #2
0
  @Test
  public void validateWithValidKeyShouldReturnTrue() throws InterruptedException {
    server.enqueue(
        new MockResponse()
            .setResponseCode(400)
            .setBody("{'error':'Input missing','message':'No input'}"));

    Tinify.setKey("valid");
    assertThat(Tinify.validate(), is(true));

    RecordedRequest request = server.takeRequest();
    assertEquals("POST /shrink HTTP/1.1", request.getRequestLine());
    assertEquals(0, request.getBody().size());
  }
Example #3
0
  @Test
  public void validateWithLimitedKeyShouldReturnTrue() throws InterruptedException {
    server.enqueue(
        new MockResponse()
            .setResponseCode(429)
            .setBody(
                "{'error':'Too many requests','message':'Your monthly limit has been exceeded'}"));

    Tinify.setKey("valid");
    assertThat(Tinify.validate(), is(true));

    RecordedRequest request = server.takeRequest();
    assertEquals("POST /shrink HTTP/1.1", request.getRequestLine());
    assertEquals(0, request.getBody().size());
  }