use of org.mockito.Mock in project flue2ent by DefinityLabs.
the class WaiterPluginTest method expectedCondition_until_callsWaitUntil.
@Test
public void expectedCondition_until_callsWaitUntil() {
WaiterPlugin waiter = new WaiterPlugin(website);
WebElement mockedElement = mock(WebElement.class);
when(wait.until(any())).thenReturn(mockedElement);
ExpectedCondition<WebElement> expectedCondition = driver -> mockedElement;
WebElement element = waiter.until(expectedCondition);
verify(wait).until(same(expectedCondition));
assertThat(element).isSameAs(mockedElement);
}
use of org.mockito.Mock in project smarthome by eclipse.
the class HomeAssistantMQTTImplementationTests method parseHATree.
@Test
public void parseHATree() throws InterruptedException, ExecutionException, TimeoutException {
MqttChannelTypeProvider channelTypeProvider = mock(MqttChannelTypeProvider.class);
final Map<String, AbstractComponent> haComponents = new HashMap<String, AbstractComponent>();
ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(4);
DiscoverComponents discover = spy(new DiscoverComponents(ThingChannelConstants.testHomeAssistantThing, scheduler, channelStateUpdateListener, new Gson()));
// The DiscoverComponents object calls ComponentDiscovered callbacks.
// In the following implementation we add the found component to the `haComponents` map
// and add the types to the channelTypeProvider, like in the real Thing handler.
final CountDownLatch latch = new CountDownLatch(1);
ComponentDiscovered cd = (haID, c) -> {
haComponents.put(haID.getChannelGroupID(), c);
c.addChannelTypes(channelTypeProvider);
channelTypeProvider.setChannelGroupType(c.groupTypeUID(), c.type());
latch.countDown();
};
// Start the discovery for 100ms. Forced timeout after 300ms.
HaID haID = new HaID(testObjectTopic);
CompletableFuture<Void> future = discover.startDiscovery(connection, 100, haID, cd).thenRun(() -> {
}).exceptionally(e -> {
failure = e;
return null;
});
assertTrue(latch.await(300, TimeUnit.MILLISECONDS));
future.get(100, TimeUnit.MILLISECONDS);
// No failure expected and one discoverd result
assertNull(failure);
assertThat(haComponents.size(), is(1));
// For the switch component we should have one channel group type and one channel type
verify(channelTypeProvider, times(1)).setChannelGroupType(any(), any());
verify(channelTypeProvider, times(1)).setChannelType(any(), any());
// We expect a switch component with an OnOff channel with the initial value UNDEF:
State value = haComponents.get(haID.getChannelGroupID()).channelTypes().get(ComponentSwitch.switchChannelID).channelState.getCache().getChannelState();
assertThat(value, is(UnDefType.UNDEF));
haComponents.values().stream().map(e -> e.start(connection, scheduler, 100)).reduce(CompletableFuture.completedFuture(null), (a, v) -> a.thenCompose(b -> v)).exceptionally(e -> {
failure = e;
return null;
}).get();
// We should have received the retained value, while subscribing to the channels MQTT state topic.
verify(channelStateUpdateListener, times(1)).updateChannelState(any(), any());
// Value should be ON now.
value = haComponents.get(haID.getChannelGroupID()).channelTypes().get(ComponentSwitch.switchChannelID).channelState.getCache().getChannelState();
assertThat(value, is(OnOffType.ON));
}
use of org.mockito.Mock in project checkstyle-idea by jshiell.
the class RelativeFileConfigurationLocationTest method setUp.
@Before
public void setUp() {
ProjectPaths projectPaths = mock(ProjectPaths.class);
Function<File, String> absolutePathOf = file -> {
// a nasty hack to pretend we're on a Windows box when required...
if (file.getPath().startsWith("c:")) {
return file.getPath().replace('/', '\\').replaceAll("\\\\\\\\", "\\\\");
}
return FilenameUtils.separatorsToUnix(file.getPath());
};
ProjectFilePaths testProjectFilePaths = new ProjectFilePaths(project, '/', absolutePathOf, projectPaths);
when(project.getService(ProjectFilePaths.class)).thenReturn(testProjectFilePaths);
when(projectBase.getPath()).thenReturn(PROJECT_BASE_PATH);
when(projectPaths.projectPath(project)).thenReturn(projectBase);
underTest = new RelativeFileConfigurationLocation(project);
underTest.setLocation("aLocation");
underTest.setDescription("aDescription");
}
use of org.mockito.Mock in project datashare by ICIJ.
the class BatchDownloadRunnerEncryptedIntTest method test_zip_with_password_should_encrypt_file_and_send_mail.
@Test
public void test_zip_with_password_should_encrypt_file_and_send_mail() throws Exception {
new IndexerHelper(es.client).indexFile("mydoc.txt", "content", fs);
BatchDownload batchDownload = createBatchDownload("*");
MailSender mailSender = mock(MailSender.class);
new BatchDownloadRunner(indexer, createProvider(), batchDownload, updateCallback, (uri) -> mailSender).call();
assertThat(new net.lingala.zip4j.ZipFile(batchDownload.filename.toFile()).isEncrypted()).isTrue();
ArgumentCaptor<Mail> mailCaptor = ArgumentCaptor.forClass(Mail.class);
verify(mailSender).send(mailCaptor.capture());
assertThat(mailCaptor.getValue().from).isEqualTo("engineering@icij.org");
assertThat(mailCaptor.getValue().toRecipientList).containsExactly("foo@bar.com");
assertThat(mailCaptor.getValue().subject).isEqualTo("[datashare] " + batchDownload.filename.getFileName());
}
use of org.mockito.Mock in project android_packages_apps_Settings by omnirom.
the class HibernatedAppsPreferenceControllerTest method setUp.
@Before
public void setUp() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
MockitoAnnotations.initMocks(this);
DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_APP_HIBERNATION_ENABLED, "true", false);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(AppHibernationManager.class)).thenReturn(mAppHibernationManager);
when(mContext.getSystemService(UsageStatsManager.class)).thenReturn(new UsageStatsManager(mContext, mIUsageStatsManager));
PreferenceManager manager = new PreferenceManager(mContext);
mPreferenceScreen = manager.createPreferenceScreen(mContext);
Preference preference = mock(Preference.class);
when(preference.getKey()).thenReturn(KEY);
mPreferenceScreen.addPreference(preference);
mController = new HibernatedAppsPreferenceController(mContext, KEY, command -> command.run(), command -> command.run());
}
Aggregations