Пример #1
0
  @Test
  public void appIdentifierShouldResetClientWithNewAppIdentifier() throws InterruptedException {
    server.enqueue(new MockResponse().setResponseCode(200));

    Tinify.setKey("abcde");
    Tinify.setAppIdentifier("MyApp/1.0");
    Tinify.client();
    Tinify.setAppIdentifier("MyApp/2.0");
    Tinify.client().request(Client.Method.GET, "/");

    RecordedRequest request = server.takeRequest(5, TimeUnit.SECONDS);
    assertEquals(Client.USER_AGENT + " MyApp/2.0", request.getHeader("User-Agent"));
  }
Пример #2
0
  @Test
  public void keyShouldResetClientWithNewKey() throws Exception, InterruptedException {
    server.enqueue(new MockResponse().setResponseCode(200));

    Tinify.setKey("abcde");
    Tinify.client();
    Tinify.setKey("fghij");
    Tinify.client().request(Client.Method.GET, "/");

    RecordedRequest request = server.takeRequest(5, TimeUnit.SECONDS);

    String credentials = new String(Base64.encodeBase64(("api:fghij").getBytes()));
    assertEquals("Basic " + credentials, request.getHeader("Authorization"));
  }
Пример #3
0
 @Test(expected = AccountException.class)
 public void clientWithoutKeyShouldThrowException() {
   Tinify.client();
 }
Пример #4
0
 @Test
 public void clientWithKeyShouldReturnClient() {
   Tinify.setKey("abcde");
   assertThat(Tinify.client(), isA(Client.class));
 }