/** * Analyzes the data file identified by the given resource name. * * @param aResourceName the name of the resource (= data file) to analyse, cannot be <code>null * </code>. * @return the analysis results, never <code>null</code>. * @throws Exception in case of exceptions. */ private I2CDataSet analyseDataFile( final String aResourceName, final int aSclIndex, final int aSdaIndex) throws Exception { URL resource = ResourceUtils.getResource(getClass(), aResourceName); AcquisitionResult container = DataTestUtils.getCapturedData(resource); ToolContext toolContext = DataTestUtils.createToolContext(container); ToolProgressListener progressListener = Mockito.mock(ToolProgressListener.class); AnnotationListener annotationListener = Mockito.mock(AnnotationListener.class); I2CAnalyserTask worker = new I2CAnalyserTask(toolContext, progressListener, annotationListener); worker.setLineAIndex(aSclIndex); worker.setLineBIndex(aSdaIndex); worker.setDetectSDA_SCL(false); worker.setReportACK(false); worker.setReportNACK(false); worker.setReportStart(false); worker.setReportStop(false); // Simulate we're running in a separate thread by directly calling the main // working routine... I2CDataSet result = worker.call(); assertNotNull(result); return result; }
@Test public void testValidSubscription() { // add configuration // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Capture the arg of subscription and return the mocked future ArgumentCaptor<String> urlProviderArg = ArgumentCaptor.forClass(String.class); ArgumentCaptor<SubscribeContext> subscribeContextArg = ArgumentCaptor.forClass(SubscribeContext.class); when(ngsiClient.subscribeContext( urlProviderArg.capture(), eq(null), subscribeContextArg.capture())) .thenReturn(responseFuture); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); // check ngsiClient.unsubscribe() is never called verify(ngsiClient, never()).unsubscribeContext(any(), any(), any()); subscriptionManager.validateSubscriptionId("12345678", "http://iotAgent"); }
@Test public void testGetUsersWithAuthority() throws SQLException { String expectedQuery = "select \"public\".\"users\".\"username\", \"public\".\"users\".\"locked\", \"public\".\"authorities\".\"authority\", count(\"public\".\"users\".\"username\") over () as \"count\" from \"public\".\"users\" join \"public\".\"authorities\" on \"public\".\"users\".\"username\" = \"public\".\"authorities\".\"username\" where \"public\".\"authorities\".\"authority\" = 'ROLE_ADMIN' order by \"public\".\"users\".\"username\" asc limit 5 offset 0"; Pageable pageable = Mockito.mock(Pageable.class); ResultSet resultSet = Mockito.mock(ResultSet.class); Mockito.when(pageable.getPageNumber()).thenReturn(0); Mockito.when(pageable.getPageSize()).thenReturn(5); Mockito.when(resultSet.getInt(PagingConstants.COUNT)).thenReturn(1); Mockito.when(resultSet.getString("username")).thenReturn("admin"); RESTPage<UserDTO> page = userDao.getUsersWithAuthority("ROLE_ADMIN", pageable); ArgumentCaptor<PagingRowCallbackHandler> pagingRowCallbackHandlerCaptor = ArgumentCaptor.forClass(PagingRowCallbackHandler.class); Mockito.verify(jdbcTemplate) .query(Matchers.eq(expectedQuery), pagingRowCallbackHandlerCaptor.capture()); PagingRowCallbackHandler pagingRowCallbackHandler = pagingRowCallbackHandlerCaptor.getValue(); pagingRowCallbackHandler.processRow(resultSet); Mockito.verify(resultSet).getInt(PagingConstants.COUNT); Mockito.verify(resultSet).getString("username"); Assert.assertEquals(1, page.getContentSize()); Assert.assertEquals("admin", page.getContent().get(0).getUsername()); }
@Test public void recruitersCanSeeJobseekersByJobAndDate() { setupRepositories(); setupActors(); JobPosting developerPosting = recruiter.post(developerJob).to(jobRepository); JobPosting architectPosting = recruiter.post(architectJob).to(jobRepository); TimeServer timeServerOne = Mockito.mock(TimeServer.class); TimeServer timeServerTwo = Mockito.mock(TimeServer.class); Date dayOne = null; Date dayTwo = null; try { dayOne = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2013-05-01 12:30:00"); dayTwo = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2013-07-04 12:30:00"); } catch (ParseException e) { fail(); } Mockito.when(timeServerOne.getCurrentTime()).thenReturn(dayOne); Mockito.when(timeServerTwo.getCurrentTime()).thenReturn(dayTwo); ApplicationProcessor appProcessorOne = new ApplicationProcessor(appRepo, timeServerOne); ApplicationProcessor appProcessorTwo = new ApplicationProcessor(appRepo, timeServerTwo); boolean applyStatus; applyStatus = jobseekerTom.applyFor(developerPosting).to(appProcessorOne); assertTrue(applyStatus); applyStatus = jobseekerHarry.applyFor(developerPosting).to(appProcessorOne); assertTrue(applyStatus); applyStatus = jobseekerTom.applyFor(architectPosting).to(appProcessorTwo); assertTrue(applyStatus); applyStatus = jobseekerDick.applyFor(architectPosting).to(appProcessorTwo); assertTrue(applyStatus); Applications appsOnDayOne = recruiter.getApplications().filterBy(dayOne).from(appRepo); ApplicationsDisplayer appsDisplayer = Mockito.mock(ApplicationsDisplayer.class); appsOnDayOne.displayTo(appsDisplayer); Mockito.verify(appsDisplayer) .displayApplications(Mockito.argThat(new SetOfTwoAppsWithDates(dayOne))); Applications appsOnDayTwoForArchitect = recruiter.getApplications().filterBy(architectPosting).filterBy(dayTwo).from(appRepo); appsDisplayer = Mockito.mock(ApplicationsDisplayer.class); appsOnDayTwoForArchitect.displayTo(appsDisplayer); Mockito.verify(appsDisplayer) .displayApplications( Mockito.argThat(new SetOfTwoAppsWithJobPostingsAndDates(dayTwo, architectPosting))); }
@Test public void setConfigurationOK() throws Exception { // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Capture the arg of subscription and return the mocked future ArgumentCaptor<String> urlProviderArg = ArgumentCaptor.forClass(String.class); ArgumentCaptor<SubscribeContext> subscribeContextArg = ArgumentCaptor.forClass(SubscribeContext.class); when(ngsiClient.subscribeContext( urlProviderArg.capture(), eq(null), subscribeContextArg.capture())) .thenReturn(responseFuture); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); SubscribeContext subscribeContext = subscribeContextArg.getValue(); assertEquals("S.*", subscribeContext.getEntityIdList().get(0).getId()); assertEquals("TempSensor", subscribeContext.getEntityIdList().get(0).getType()); assertEquals(true, subscribeContext.getEntityIdList().get(0).getIsPattern()); assertEquals("temp", subscribeContext.getAttributeList().get(0)); assertEquals("PT1H", subscribeContext.getDuration()); assertEquals("http://iotAgent", urlProviderArg.getValue()); Set<Provider> providers = configuration.getEventTypeIns().get(0).getProviders(); for (Provider provider : providers) { assertEquals("12345678", provider.getSubscriptionId()); assertNotNull(provider.getSubscriptionDate()); } }
@Test public void recruitersAreDisplayedByName() { Recruiter recruiter = Recruiter.named("George"); RecruiterDisplayer recDisplayer = Mockito.mock(RecruiterDisplayer.class); recruiter.displayTo(recDisplayer); DisplayableName name = new Name("George"); Mockito.verify(recDisplayer).displayRecruiter(name); }
@Test public void recruiterCanPostJob() { Recruiter recruiter = Recruiter.named("George"); Job developerJob = ATSJob.titled("Developer"); JobRepository jobRepository = Mockito.mock(JobRepository.class); recruiter.post(developerJob).to(jobRepository); JobPosting posting = new JobPosting(recruiter, developerJob); Mockito.verify(jobRepository).add(posting); }
@Test public void testInvalideSubscription() { // Mock future for unsubscribeContext ListenableFuture<UnsubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(any(), any()); when(ngsiClient.unsubscribeContext(eq("http://iotAgent"), eq(null), eq("9999"))) .thenReturn(responseFuture); subscriptionManager.validateSubscriptionId("9999", "http://iotAgent"); }
@Test public void testUnsubscribeOnProviderRemoval() { // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); // Return the mocked future on subscription when(ngsiClient.subscribeContext(any(), any(), any())).thenReturn(responseFuture); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); // Mock future for unsubscribeContext ListenableFuture<UnsubscribeContextResponse> responseFuture2 = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture2).addCallback(successArg.capture(), any()); when(ngsiClient.unsubscribeContext(eq("http://iotAgent"), eq(null), eq("12345678"))) .thenReturn(responseFuture2); // Reset conf should trigger unsubsribeContext Configuration emptyConfiguration = getBasicConf(); emptyConfiguration.getEventTypeIns().get(0).setProviders(Collections.emptySet()); subscriptionManager.setConfiguration(emptyConfiguration); // Check that unsubsribe is called Assert.notNull(successArg.getValue()); }
@Test public void testGetUsersWithAuthority_page2() { String expectedQuery = "select \"public\".\"users\".\"username\", \"public\".\"users\".\"locked\", \"public\".\"authorities\".\"authority\", count(\"public\".\"users\".\"username\") over () as \"count\" from \"public\".\"users\" join \"public\".\"authorities\" on \"public\".\"users\".\"username\" = \"public\".\"authorities\".\"username\" where \"public\".\"authorities\".\"authority\" = 'ROLE_ADMIN' order by \"public\".\"users\".\"username\" asc limit 5 offset 5"; Pageable pageable = Mockito.mock(Pageable.class); Mockito.when(pageable.getPageNumber()).thenReturn(1); Mockito.when(pageable.getPageSize()).thenReturn(5); userDao.getUsersWithAuthority("ROLE_ADMIN", pageable); Mockito.verify(jdbcTemplate) .query(Matchers.eq(expectedQuery), Matchers.any(PagingRowCallbackHandler.class)); }
@Test public void recruitersCanSeeJobseekersByJob() { setupActors(); setupRepositories(); JobPosting developerPosting = recruiter.post(developerJob).to(jobRepository); JobPosting architectPosting = recruiter.post(architectJob).to(jobRepository); boolean applyStatus; applyStatus = jobseekerTom.applyFor(developerPosting).to(appProcessor); assertTrue(applyStatus); applyStatus = jobseekerHarry.applyFor(developerPosting).to(appProcessor); assertTrue(applyStatus); applyStatus = jobseekerTom.applyFor(architectPosting).to(appProcessor); assertTrue(applyStatus); applyStatus = jobseekerDick.applyFor(architectPosting).to(appProcessor); assertTrue(applyStatus); Applications developerApps = recruiter.getApplications().filterBy(developerPosting).from(appRepo); ApplicationsDisplayer appsDisplayer = Mockito.mock(ApplicationsDisplayer.class); developerApps.displayTo(appsDisplayer); Mockito.verify(appsDisplayer) .displayApplications( Mockito.argThat(new SetOfTwoAppsWithJobSeekers(jobseekerTom, jobseekerHarry))); Applications architectApps = recruiter.getApplications().filterBy(architectPosting).from(appRepo); appsDisplayer = Mockito.mock(ApplicationsDisplayer.class); architectApps.displayTo(appsDisplayer); Mockito.verify(appsDisplayer) .displayApplications( Mockito.argThat(new SetOfTwoAppsWithJobSeekers(jobseekerTom, jobseekerDick))); }
@Test public void recruitersCanDisplayJobsTheyPosted() { setupActors(); JobRepository jobRepository = new JobRepository(); JobPosting developerPosting = recruiter.post(developerJob).to(jobRepository); JobPosting architectPosting = recruiter.post(architectJob).to(jobRepository); JobPosting programmerPosting = recruiter.post(programmerJob).to(jobRepository); JobPostings jobPostings = recruiter.getPostedJobs().from(jobRepository); JobPostingsDisplayer postingsDisplayer = Mockito.mock(JobPostingsDisplayer.class); jobPostings.displayTo(postingsDisplayer); Mockito.verify(postingsDisplayer) .displayJobPostings( Matchers.argThat( new SetOfThreeJobPostings(developerPosting, architectPosting, programmerPosting))); }
public class QuestHouseTest { QuestRoom mockRoom = Mockito.mock(QuestRoom.class); // A mocked QuestRoom // 0================================================================0 // | NEW QUEST BUILDING TESTS | // 0================================================================0 /** * Tests that a new QuestBuilding object will return null if you try to get its initial QuestRoom * object. */ @Test public void testEmptyInitialRoom() { QuestHouse houseOfRooms = new QuestHouse(); assertNull(houseOfRooms.getInitialRoom()); // Asserts that the initial room is null } /** Tests that a new QuestBuilding object will start with zero rooms. */ @Test public void testZeroStartingRooms() { QuestHouse houseOfRooms = new QuestHouse(); int numRooms = houseOfRooms.getNumberOfRooms(); assertEquals(0, numRooms); // Asserts that the initial number of rooms is zero } // 0================================================================0 // | INITIAL ROOM TESTS | // 0================================================================0 /** * Tests that setting the initial room of a QuestBuilding object with a non-null QuestRoom object * will return a non-null QuestRoom object. This is not a particularly good test but it does show * that an initial room will be set to something other than null. */ @Test public void testSetInitialRoom() { QuestHouse houseOfRooms = new QuestHouse(); houseOfRooms.setInitialRoom(mockRoom); assertNotNull(houseOfRooms.getInitialRoom()); // Asserts that the initial room is not null } /** * Tests that incrementing the number of rooms by a specific amount will return the same amount * when getNumberOfRooms is called. */ @Test public void testIncrementNumberOfRooms() { QuestHouse houseOfRooms = new QuestHouse(); int numLoops = 5; for (int i = 0; i < numLoops; i++) { houseOfRooms.incrementNumberOfRooms(); } assertEquals( numLoops, houseOfRooms .getNumberOfRooms()); // Asserts that the number of rooms returned matches the loop // amount } /** Tests that the initial QuestRoom returned is the same as the initial QuestRoom that is set. */ @Test public void testSameInitialRoom() { QuestHouse houseOfRooms = new QuestHouse(); houseOfRooms.setInitialRoom(mockRoom); assertSame( mockRoom, houseOfRooms.getInitialRoom()); // Asserts that the QuestRoom objects are the same } }
/** Tests for SubscriptionManager */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class SubscriptionManagerTest { @Mock TaskScheduler taskScheduler; @Mock NgsiClient ngsiClient = Mockito.mock(NgsiClient.class, RETURNS_SMART_NULLS); @Autowired @InjectMocks SubscriptionManager subscriptionManager; @Before public void setUp() throws URISyntaxException { MockitoAnnotations.initMocks(this); } @After public void after() { reset(ngsiClient); reset(taskScheduler); } @Test public void setConfigurationOK() throws Exception { // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Capture the arg of subscription and return the mocked future ArgumentCaptor<String> urlProviderArg = ArgumentCaptor.forClass(String.class); ArgumentCaptor<SubscribeContext> subscribeContextArg = ArgumentCaptor.forClass(SubscribeContext.class); when(ngsiClient.subscribeContext( urlProviderArg.capture(), eq(null), subscribeContextArg.capture())) .thenReturn(responseFuture); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); SubscribeContext subscribeContext = subscribeContextArg.getValue(); assertEquals("S.*", subscribeContext.getEntityIdList().get(0).getId()); assertEquals("TempSensor", subscribeContext.getEntityIdList().get(0).getType()); assertEquals(true, subscribeContext.getEntityIdList().get(0).getIsPattern()); assertEquals("temp", subscribeContext.getAttributeList().get(0)); assertEquals("PT1H", subscribeContext.getDuration()); assertEquals("http://iotAgent", urlProviderArg.getValue()); Set<Provider> providers = configuration.getEventTypeIns().get(0).getProviders(); for (Provider provider : providers) { assertEquals("12345678", provider.getSubscriptionId()); assertNotNull(provider.getSubscriptionDate()); } } @Test public void testUnsubscribeOnEventTypeRemoval() { // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); // Return the mocked future on subscription when(ngsiClient.subscribeContext(any(), any(), any())).thenReturn(responseFuture); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); // Mock future for unsubscribeContext ListenableFuture<UnsubscribeContextResponse> responseFuture2 = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture2).addCallback(successArg.capture(), any()); when(ngsiClient.unsubscribeContext(eq("http://iotAgent"), eq(null), eq("12345678"))) .thenReturn(responseFuture2); // Set a configuration without the eventType Configuration emptyConfiguration = new Configuration(); emptyConfiguration.setEventTypeIns(Collections.emptyList()); subscriptionManager.setConfiguration(emptyConfiguration); // Check that unsubsribe is called when a later configuration removed the event type Assert.notNull(successArg.getValue()); } @Test public void testUnsubscribeOnProviderRemoval() { // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); // Return the mocked future on subscription when(ngsiClient.subscribeContext(any(), any(), any())).thenReturn(responseFuture); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); // Mock future for unsubscribeContext ListenableFuture<UnsubscribeContextResponse> responseFuture2 = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture2).addCallback(successArg.capture(), any()); when(ngsiClient.unsubscribeContext(eq("http://iotAgent"), eq(null), eq("12345678"))) .thenReturn(responseFuture2); // Reset conf should trigger unsubsribeContext Configuration emptyConfiguration = getBasicConf(); emptyConfiguration.getEventTypeIns().get(0).setProviders(Collections.emptySet()); subscriptionManager.setConfiguration(emptyConfiguration); // Check that unsubsribe is called Assert.notNull(successArg.getValue()); } @Test public void testInvalideSubscription() { // Mock future for unsubscribeContext ListenableFuture<UnsubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(any(), any()); when(ngsiClient.unsubscribeContext(eq("http://iotAgent"), eq(null), eq("9999"))) .thenReturn(responseFuture); subscriptionManager.validateSubscriptionId("9999", "http://iotAgent"); } @Test public void testValidSubscription() { // add configuration // Mock the task scheduler and capture the runnable ArgumentCaptor<Runnable> runnableArg = ArgumentCaptor.forClass(Runnable.class); when(taskScheduler.scheduleWithFixedDelay(runnableArg.capture(), anyLong())) .thenReturn(Mockito.mock(ScheduledFuture.class)); // Mock the response to the subsribeContext ArgumentCaptor<SuccessCallback> successArg = ArgumentCaptor.forClass(SuccessCallback.class); ListenableFuture<SubscribeContextResponse> responseFuture = Mockito.mock(ListenableFuture.class); doNothing().when(responseFuture).addCallback(successArg.capture(), any()); Configuration configuration = getBasicConf(); subscriptionManager.setConfiguration(configuration); // Capture the arg of subscription and return the mocked future ArgumentCaptor<String> urlProviderArg = ArgumentCaptor.forClass(String.class); ArgumentCaptor<SubscribeContext> subscribeContextArg = ArgumentCaptor.forClass(SubscribeContext.class); when(ngsiClient.subscribeContext( urlProviderArg.capture(), eq(null), subscribeContextArg.capture())) .thenReturn(responseFuture); // Execute scheduled runnable runnableArg.getValue().run(); // Return the SubscribeContextResponse callSuccessCallback(successArg); // check ngsiClient.unsubscribe() is never called verify(ngsiClient, never()).unsubscribeContext(any(), any(), any()); subscriptionManager.validateSubscriptionId("12345678", "http://iotAgent"); } private void callSuccessCallback(ArgumentCaptor<SuccessCallback> successArg) { SubscribeContextResponse response = new SubscribeContextResponse(); SubscribeResponse subscribeResponse = new SubscribeResponse(); subscribeResponse.setSubscriptionId("12345678"); subscribeResponse.setDuration("PT1H"); response.setSubscribeResponse(subscribeResponse); successArg.getValue().onSuccess(response); } }