Java Code Examples for org.robolectric.Robolectric#runUiThreadTasksIncludingDelayedTasks()
The following examples show how to use
org.robolectric.Robolectric#runUiThreadTasksIncludingDelayedTasks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawPathTaskTest.java From open with GNU General Public License v3.0 | 7 votes |
@Test public void shouldNotDrawAnyPointsIfCancelled() throws Exception { ArrayList<Location> locations = new ArrayList<Location>(); stub(box.contains(locationToGeoPoint(outsideBefore1))).toReturn(false); stub(box.contains(locationToGeoPoint(outsideBefore2))).toReturn(false); stub(box.contains(locationToGeoPoint(inside1))).toReturn(true); stub(box.contains(locationToGeoPoint(inside2))).toReturn(true); locations.add(outsideBefore1); locations.add(outsideBefore2); locations.add(inside1); locations.add(inside2); task.cancel(true); task.execute(locations); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertThat(getPathLayer()).isNull(); }
Example 2
Source File: WebOSWebAppSessionTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
@Test public void testJumpToTrack() throws JSONException { ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); session.jumpToTrack(7, listener); Robolectric.runUiThreadTasksIncludingDelayedTasks(); ArgumentCaptor<JSONObject> argPacket = ArgumentCaptor.forClass(JSONObject.class); ArgumentCaptor<JSONObject> argPayload = ArgumentCaptor.forClass(JSONObject.class); Mockito.verify(socket).sendMessage(argPacket.capture(), argPayload.capture()); Mockito.verify(listener).onSuccess(null); JSONObject packet = argPacket.getValue(); JSONObject payload = argPayload.getValue(); Assert.assertNull(payload); Assert.assertTrue(packet.has("payload")); Assert.assertEquals("jumpToTrack", packet.getJSONObject("payload") .getJSONObject("mediaCommand").getString("type")); Assert.assertEquals(7, packet.getJSONObject("payload") .getJSONObject("mediaCommand").getInt("index")); Assert.assertEquals("connectsdk.mediaCommand", packet.getJSONObject("payload") .getString("contentType")); }
Example 3
Source File: DrawPathTaskTest.java From open with GNU General Public License v3.0 | 6 votes |
@Test public void shouldDrawFirstPointAfterExitingBBox() throws Exception { ArrayList<Location> locations = new ArrayList<Location>(); stub(box.contains(locationToGeoPoint(inside1))).toReturn(true); stub(box.contains(locationToGeoPoint(inside2))).toReturn(true); stub(box.contains(locationToGeoPoint(outSideAfter1))).toReturn(false); stub(box.contains(locationToGeoPoint(outSideAfter2))).toReturn(false); locations.add(inside1); locations.add(inside2); locations.add(outSideAfter1); locations.add(outSideAfter2); task.execute(locations); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertThat(getPathPoints()).contains(locationToGeoPoint(inside1)); assertThat(getPathPoints()).contains(locationToGeoPoint(inside2)); assertThat(getPathPoints()).contains(locationToGeoPoint(outSideAfter1)); assertThat(getPathPoints()).doesNotContain(locationToGeoPoint(outSideAfter2)); }
Example 4
Source File: DrawPathTaskTest.java From open with GNU General Public License v3.0 | 6 votes |
@Test public void shouldDrawFirstPointBeforeEnteringBBox() throws Exception { ArrayList<Location> locations = new ArrayList<Location>(); stub(box.contains(locationToGeoPoint(outsideBefore1))).toReturn(false); stub(box.contains(locationToGeoPoint(outsideBefore2))).toReturn(false); stub(box.contains(locationToGeoPoint(inside1))).toReturn(true); stub(box.contains(locationToGeoPoint(inside2))).toReturn(true); locations.add(outsideBefore1); locations.add(outsideBefore2); locations.add(inside1); locations.add(inside2); task.execute(locations); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertThat(getPathPoints()).doesNotContain(locationToGeoPoint(outsideBefore1)); assertThat(getPathPoints()).contains(locationToGeoPoint(outsideBefore2)); assertThat(getPathPoints()).contains(locationToGeoPoint(inside1)); assertThat(getPathPoints()).contains(locationToGeoPoint(inside2)); }
Example 5
Source File: WebOSTVServiceTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
private void verifyPlayMediaOnTheLatestWebOS(MediaInfo mediaInfo, boolean shouldLoop, MediaPlayer.LaunchListener listener, WebOSWebAppSession webAppSession) { // should try to join to the web app ArgumentCaptor<ResponseListener> argListener = ArgumentCaptor.forClass(ResponseListener .class); Mockito.verify(webAppSession).join(argListener.capture()); // run join success ResponseListener webAppListener = argListener.getValue(); webAppListener.onSuccess(null); Robolectric.runUiThreadTasksIncludingDelayedTasks(); // should delegate playing media to the WebAppSession ArgumentCaptor<MediaInfo> argMediaInfo = ArgumentCaptor.forClass(MediaInfo.class); ArgumentCaptor<Boolean> argShouldLoop = ArgumentCaptor.forClass(Boolean.class); Mockito.verify(webAppSession).playMedia(argMediaInfo.capture(), argShouldLoop.capture(), Mockito.same(listener)); MediaInfo capturedMediaInfo = argMediaInfo.getValue(); Assert.assertEquals(mediaInfo.getDescription(), capturedMediaInfo.getDescription()); Assert.assertEquals(mediaInfo.getMimeType(), capturedMediaInfo.getMimeType()); Assert.assertEquals(mediaInfo.getTitle(), capturedMediaInfo.getTitle()); Assert.assertEquals(mediaInfo.getUrl(), capturedMediaInfo.getUrl()); Assert.assertEquals(mediaInfo.getImages(), capturedMediaInfo.getImages()); Assert.assertEquals(mediaInfo.getSubtitleInfo(), capturedMediaInfo.getSubtitleInfo()); Assert.assertEquals(shouldLoop, argShouldLoop.getValue().booleanValue()); }
Example 6
Source File: DLNAServiceSendCommandTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
@Test public void testSendPostCommandWithWrongPayload() throws Exception { Object payload = "payload"; ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, payload, listener); service.avTransportURL = COMMAND_URL; service.sendCommand(command); TestUtil.runUtilBackgroundTasks(); Robolectric.runUiThreadTasksIncludingDelayedTasks(); Mockito.verify(httpConnection, Mockito.times(0)).execute(); Mockito.verify(listener).onError(Mockito.any(ServiceCommandError.class)); }
Example 7
Source File: DLNAServiceSendCommandTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
@Test public void testSendPostCommandWithNullPayload() throws Exception { Object payload = null; ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, payload, listener); service.avTransportURL = COMMAND_URL; service.sendCommand(command); TestUtil.runUtilBackgroundTasks(); Robolectric.runUiThreadTasksIncludingDelayedTasks(); Mockito.verify(httpConnection, Mockito.times(0)).execute(); Mockito.verify(listener).onError(Mockito.any(ServiceCommandError.class)); }
Example 8
Source File: WebOSWebAppSessionTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
@Test public void testNext() throws JSONException { ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); session.next(listener); Robolectric.runUiThreadTasksIncludingDelayedTasks(); ArgumentCaptor<JSONObject> argPacket = ArgumentCaptor.forClass(JSONObject.class); ArgumentCaptor<JSONObject> argPayload = ArgumentCaptor.forClass(JSONObject.class); Mockito.verify(socket).sendMessage(argPacket.capture(), argPayload.capture()); Mockito.verify(listener).onSuccess(null); JSONObject packet = argPacket.getValue(); JSONObject payload = argPayload.getValue(); Assert.assertNull(payload); Assert.assertTrue(packet.has("payload")); Assert.assertEquals("playNext", packet.getJSONObject("payload") .getJSONObject("mediaCommand").getString("type")); Assert.assertEquals("connectsdk.mediaCommand", packet.getJSONObject("payload") .getString("contentType")); }
Example 9
Source File: WebOSWebAppSessionTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
@Test public void testPrevious() throws JSONException { ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); session.previous(listener); Robolectric.runUiThreadTasksIncludingDelayedTasks(); ArgumentCaptor<JSONObject> argPacket = ArgumentCaptor.forClass(JSONObject.class); ArgumentCaptor<JSONObject> argPayload = ArgumentCaptor.forClass(JSONObject.class); Mockito.verify(socket).sendMessage(argPacket.capture(), argPayload.capture()); Mockito.verify(listener).onSuccess(null); JSONObject packet = argPacket.getValue(); JSONObject payload = argPayload.getValue(); Assert.assertNull(payload); Assert.assertTrue(packet.has("payload")); Assert.assertEquals("playPrevious", packet.getJSONObject("payload") .getJSONObject("mediaCommand").getString("type")); Assert.assertEquals("connectsdk.mediaCommand", packet.getJSONObject("payload") .getString ("contentType")); }
Example 10
Source File: ZeroConfDiscoveryPrividerTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 6 votes |
@Test public void testServiceRemoveEvent() throws Exception { // given String uuid = "192.168.0.1"; String name = "Test TV"; ServiceDescription serviceDescription = new ServiceDescription("_testservicetype._tcp.local.", uuid, uuid); serviceDescription.setFriendlyName(name); ServiceEvent event = createMockedServiceEvent(uuid, name); DiscoveryProviderListener listener = mock(DiscoveryProviderListener.class); dp.addListener(listener); dp.foundServices.put(uuid, serviceDescription); // when dp.jmdnsListener.serviceRemoved(event); Robolectric.runUiThreadTasksIncludingDelayedTasks(); // then verify(listener).onServiceRemoved(any(DiscoveryProvider.class), any(ServiceDescription.class)); }
Example 11
Source File: DIALServiceSendCommandTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 5 votes |
private void verifyFailedConnection(int code) throws IOException { ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, null, listener); String response = "responsedata"; Mockito.when(httpConnection.getResponseCode()).thenReturn(code); Mockito.when(httpConnection.getResponseString()).thenReturn(response); service.sendCommand(command); TestUtil.runUtilBackgroundTasks(); Robolectric.runUiThreadTasksIncludingDelayedTasks(); Mockito.verify(listener).onError(Mockito.any(ServiceCommandError.class)); }
Example 12
Source File: ClickGuardTest.java From clickguard with Apache License 2.0 | 5 votes |
@Test public void guardShouldRestWhenWatchPeriodEnds() { ClickGuard guard = ClickGuard.newGuard(1000); long start = SystemClock.elapsedRealtime(); guard.watch(); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertFalse(guard.isWatching()); assertTrue((SystemClock.elapsedRealtime() - start) == 1000); }
Example 13
Source File: DIALServiceSendCommandTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 5 votes |
@Test public void testSendCommand201ShouldInvokeSuccess() throws Exception { ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, null, listener); String response = "responsedata"; Mockito.when(httpConnection.getResponseCode()).thenReturn(201); Mockito.when(httpConnection.getResponseHeader(Mockito.eq("Location"))).thenReturn(response); service.sendCommand(command); TestUtil.runUtilBackgroundTasks(); Robolectric.runUiThreadTasksIncludingDelayedTasks(); Mockito.verify(listener).onSuccess(Mockito.eq(response)); }
Example 14
Source File: DIALServiceSendCommandTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 5 votes |
@Test public void testSendCommand200ShouldInvokeSuccess() throws Exception { ResponseListener<Object> listener = Mockito.mock(ResponseListener.class); ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(service, COMMAND_URL, null, listener); String response = "responsedata"; Mockito.when(httpConnection.getResponseCode()).thenReturn(200); Mockito.when(httpConnection.getResponseString()).thenReturn(response); service.sendCommand(command); TestUtil.runUtilBackgroundTasks(); Robolectric.runUiThreadTasksIncludingDelayedTasks(); Mockito.verify(listener).onSuccess(Mockito.eq(response)); }
Example 15
Source File: PagerResultsFragmentTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void displayResults_shouldShowViewAllActionForMultipleResults() throws Exception { menu.findItem(R.id.action_view_all).setVisible(false); fragment.add(new SimpleFeature()); fragment.add(new SimpleFeature()); fragment.displayResults(2, 0); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertThat(menu.findItem(R.id.action_view_all)).isVisible(); }
Example 16
Source File: RouteFragmentTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void success_shouldHideLocationMarker() throws Exception { TestHelper.startFragment(fragment, act); fragment.getActivity().findViewById(R.id.locate_button).setVisibility(View.VISIBLE); fragment.success(new Route(MOCK_ROUTE_JSON)); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertThat(fragment.getActivity().findViewById(R.id.locate_button)).isGone(); }
Example 17
Source File: ClickGuardTest.java From clickguard with Apache License 2.0 | 5 votes |
@Test public void guardedViewPreventsMultipleClicks() { View view = new View(Robolectric.application); CountClickListener listener = new CountClickListener(); view.setOnClickListener(listener); ClickGuard guard = ClickGuard.newGuard(10000).add(view); assertFalse(guard.isWatching()); clickView(view, 1); assertEquals(1, listener.getClickedCount()); assertTrue(guard.isWatching()); clickView(view, 5); assertTrue(guard.isWatching()); assertEquals(1, listener.getClickedCount()); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertFalse(guard.isWatching()); clickView(view, 1); assertTrue(guard.isWatching()); assertEquals(2, listener.getClickedCount()); guard.rest(); assertFalse(guard.isWatching()); clickView(view, 1); assertEquals(3, listener.getClickedCount()); clickView(view, 5); assertEquals(3, listener.getClickedCount()); }
Example 18
Source File: ClickGuardTest.java From clickguard with Apache License 2.0 | 5 votes |
@Test public void guardedListenerPreventsMultipleClicks() { View view = new View(Robolectric.application); CountClickGuardedOnClickListener listener = new CountClickGuardedOnClickListener(); view.setOnClickListener(listener); clickView(view, 5); assertEquals(1, listener.clickedCount); Robolectric.runUiThreadTasksIncludingDelayedTasks(); clickView(view, 5); assertEquals(2, listener.clickedCount); }
Example 19
Source File: ClickGuardTest.java From clickguard with Apache License 2.0 | 5 votes |
@Test public void wrappedListenerPreventsMultipleClicks() { View view = new View(Robolectric.application); CountClickListener listener = new CountClickListener(); view.setOnClickListener(ClickGuard.wrap(listener)); clickView(view, 5); assertEquals(1, listener.getClickedCount()); Robolectric.runUiThreadTasksIncludingDelayedTasks(); clickView(view, 5); assertEquals(2, listener.getClickedCount()); }
Example 20
Source File: RouteFragmentTest.java From open with GNU General Public License v3.0 | 4 votes |
@Test public void shouldHideBaseAttribution() throws Exception { TestHelper.startFragment(fragment, act); Robolectric.runUiThreadTasksIncludingDelayedTasks(); assertThat(act.findViewById(R.id.attribution)).isNotVisible(); }