OpenUrlServiceImpl implements OpenUrlService { public void logfailed(Context context, String url) throws SQLException { Date now = new Date(); if (StringUtils.isBlank(url)) { return; } OpenURLTracker tracker = failedOpenUrlTrackerService.create(context); tracker.setUploadDate(now); tracker.setUrl(url); }  void processUrl(Context c, String urlStr); void reprocessFailedQueue(Context context); void logfailed(Context context, String url);  }
@Test public void testLogfailed() throws SQLException { Context context = mock(Context.class); OpenURLTracker tracker1 = mock(OpenURLTracker.class); doCallRealMethod().when(tracker1).setUrl(anyString()); when(tracker1.getUrl()).thenCallRealMethod(); when(failedOpenURLTrackerService.create(any(Context.class))).thenReturn(tracker1); String failedUrl = "failed-url"; openUrlService.logfailed(context, failedUrl); Assert.assertThat(tracker1.getUrl(), is(failedUrl)); }