@Test public void testGetServerTimeOffset() throws Exception { AsyncCallback<Long> callback = new AsyncCallback<Long>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(Long result) { offset = result; } }; PowerMockito.spy(ClientServerTimeOffset.class); Mockito.when(ClientServerTimeOffset.getCurrentTime()).thenAnswer(new Answer<Long>() { boolean startTime = true; @Override public Long answer(InvocationOnMock invocation) throws Throwable { long returnValue; if (startTime) returnValue = 1000; else returnValue = 2000; startTime = !startTime; return returnValue; } }); Mockito.when(response.getText()).thenReturn("10000"); Mockito.when(rb.sendRequest(Mockito.anyString(), Mockito.any(RequestCallback.class))).thenAnswer(new Answer<Request>() { @Override public Request answer(InvocationOnMock invocation) throws Throwable { RequestCallback callback = (RequestCallback) invocation.getArguments()[1]; Request req = Mockito.mock(Request.class); callback.onResponseReceived(req, response); return req; } }); PowerMockito.whenNew(RequestBuilder.class).withAnyArguments().thenReturn(rb); ClientServerTimeOffset.getServerTimeOffset(callback); assertNotNull(offset); Assert.assertEquals(8500L, offset.longValue()); }
public static void getServerTimeOffset(final AsyncCallback<Long> callback) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "ping"); final long startTime = getCurrentTime(); try { rb.sendRequest(null, createServerTimeOffsetRequestCallback(callback, startTime)); } catch (RequestException e) { callback.onFailure(e); } }
ClientServerTimeOffset { public static void getServerTimeOffset(final AsyncCallback<Long> callback) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "ping"); final long startTime = getCurrentTime(); try { rb.sendRequest(null, createServerTimeOffsetRequestCallback(callback, startTime)); } catch (RequestException e) { callback.onFailure(e); } } }
ClientServerTimeOffset { public static void getServerTimeOffset(final AsyncCallback<Long> callback) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "ping"); final long startTime = getCurrentTime(); try { rb.sendRequest(null, createServerTimeOffsetRequestCallback(callback, startTime)); } catch (RequestException e) { callback.onFailure(e); } }  }
ClientServerTimeOffset { public static void getServerTimeOffset(final AsyncCallback<Long> callback) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "ping"); final long startTime = getCurrentTime(); try { rb.sendRequest(null, createServerTimeOffsetRequestCallback(callback, startTime)); } catch (RequestException e) { callback.onFailure(e); } }  static void getServerTimeOffset(final AsyncCallback<Long> callback); }
ClientServerTimeOffset { public static void getServerTimeOffset(final AsyncCallback<Long> callback) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "ping"); final long startTime = getCurrentTime(); try { rb.sendRequest(null, createServerTimeOffsetRequestCallback(callback, startTime)); } catch (RequestException e) { callback.onFailure(e); } }  static void getServerTimeOffset(final AsyncCallback<Long> callback);  }