@Test /** for {@link SingleThumbnailAdapter#get()} */ public void should_return_proper_operation_result() { // Given mockStatic(JerseyRequest.class); when(buildRequest( eq(sessionStorageMock), eq(InputStream.class), eq(new String[] {"/thumbnails", "/public/Samples/Reports/07g.RevenueDetailReport"}), any(DefaultErrorHandler.class))) .thenReturn(jerseyRequestMock); when(jerseyRequestMock.setAccept("image/jpeg")).thenReturn(jerseyRequestMock); when(jerseyRequestMock.get()).thenReturn(operationResultMock); SingleThumbnailAdapter thumbnailAdapter = new SingleThumbnailAdapter(sessionStorageMock); thumbnailAdapter.report("/public/Samples/Reports/07g.RevenueDetailReport"); // When OperationResult<InputStream> retrieved = thumbnailAdapter.get(); // Then assertNotNull(retrieved); assertSame(retrieved, operationResultMock); verify(jerseyRequestMock).setAccept(eq("image/jpeg")); verify(jerseyRequestMock).get(); verifyStatic(times(1)); buildRequest( eq(sessionStorageMock), eq(InputStream.class), eq(new String[] {"/thumbnails", "/public/Samples/Reports/07g.RevenueDetailReport"}), any(DefaultErrorHandler.class)); }
private JerseyRequest<Map> request() { return JerseyRequest.buildRequest( sessionStorage, Map.class, new String[] {"/settings/" + groupKey}, new DefaultErrorHandler()); }
private JerseyRequest<Organization> buildRequest() { return JerseyRequest.buildRequest( sessionStorage, Organization.class, new String[] {"/organizations", organizationId}, new DefaultErrorHandler()); }
@Test public void should_retrieve_state_asynchronously() throws InterruptedException { /* Given */ PowerMockito.mockStatic(JerseyRequest.class); PowerMockito.when( JerseyRequest.buildRequest( eq(storageMock), eq(StateDto.class), eq(new String[] {"/import", taskId, "/state"}))) .thenReturn(requestMock); PowerMockito.doReturn(resultMock).when(requestMock).get(); ImportRequestAdapter adapterSpy = PowerMockito.spy(new ImportRequestAdapter(storageMock, taskId)); final AtomicInteger newThreadId = new AtomicInteger(); final int currentThreadId = (int) Thread.currentThread().getId(); final Callback<OperationResult<StateDto>, Void> callback = PowerMockito.spy( new Callback<OperationResult<StateDto>, Void>() { @Override public Void execute(OperationResult<StateDto> data) { newThreadId.set((int) Thread.currentThread().getId()); synchronized (this) { this.notify(); } return null; } }); PowerMockito.doReturn(null).when(callback).execute(resultMock); /* When */ RequestExecution retrieved = adapterSpy.asyncState(callback); /* Wait */ synchronized (callback) { callback.wait(1000); } /* Then */ Mockito.verify(requestMock).get(); Mockito.verify(callback).execute(resultMock); Assert.assertNotNull(retrieved); Assert.assertNotSame(currentThreadId, newThreadId.get()); }
@Test(testName = "state") public void should_return_proper_OperationResult_object() { // Given PowerMockito.mockStatic(JerseyRequest.class); PowerMockito.when( JerseyRequest.buildRequest( eq(storageMock), eq(StateDto.class), eq(fakeArrayPath), any(DefaultErrorHandler.class))) .thenReturn(requestMock); PowerMockito.when(requestMock.get()).thenReturn(resultMock); // When ImportRequestAdapter adapter = new ImportRequestAdapter(storageMock, taskId); OperationResult<StateDto> opResult = adapter.state(); // Then assertSame(opResult, resultMock); }