@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")); }
@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")); }
@Test(expected = AccountException.class) public void clientWithoutKeyShouldThrowException() { Tinify.client(); }
@Test public void clientWithKeyShouldReturnClient() { Tinify.setKey("abcde"); assertThat(Tinify.client(), isA(Client.class)); }