use of org.mockito.ArgumentCaptor in project che by eclipse.
the class MachineProviderImplTest method shouldAddCommonsSystemVolumesOnlyOnNonDevInstanceCreationFromSnapshot.
@Test
public void shouldAddCommonsSystemVolumesOnlyOnNonDevInstanceCreationFromSnapshot() throws Exception {
String[] bindMountVolumesFromMachine = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z" };
String[] volumesFromMachine = new String[] { "/projects", "/something", "/something/else" };
String[] allMachinesSystemVolumes = new String[] { "/some/thing/else:/home/some/thing/else", "/other/path:/home/other/path", "/home/other/path2" };
String[] devMachinesSystemVolumes = new String[] { "/etc:/tmp/etc:ro", "/some/thing:/home/some/thing", "/some/thing2:/home/some/thing2:ro,z", "/home/some/thing3" };
String[] expectedBindMountVolumes = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z", "/some/thing/else:/home/some/thing/else", "/other/path:/home/other/path" };
Map<String, Volume> expectedVolumes = Stream.of("/projects", "/something", "/something/else", "/home/other/path2").collect(toMap(Function.identity(), v -> new Volume()));
provider = new MachineProviderBuilder().setDevMachineVolumes(new HashSet<>(asList(devMachinesSystemVolumes))).setAllMachineVolumes(new HashSet<>(asList(allMachinesSystemVolumes))).build();
CheServiceImpl service = createService();
service.setVolumes(Stream.concat(Stream.of(bindMountVolumesFromMachine), Stream.of(volumesFromMachine)).collect(Collectors.toList()));
createInstanceFromSnapshot(service, false);
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
String[] actualBindMountVolumes = argumentCaptor.getValue().getContainerConfig().getHostConfig().getBinds();
Map<String, Volume> actualVolumes = argumentCaptor.getValue().getContainerConfig().getVolumes();
assertEquals(actualVolumes, expectedVolumes);
assertEqualsNoOrder(actualBindMountVolumes, expectedBindMountVolumes);
}
use of org.mockito.ArgumentCaptor in project che by eclipse.
the class MachineProviderImplTest method shouldAddBindMountAndRegularVolumesOnInstanceCreationFromSnapshot.
@Test
public void shouldAddBindMountAndRegularVolumesOnInstanceCreationFromSnapshot() throws Exception {
String[] bindMountVolumesFromMachine = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z" };
String[] volumesFromMachine = new String[] { "/projects", "/something", "/something/else" };
String[] expectedBindMountVolumes = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z" };
Map<String, Volume> expectedVolumes = Stream.of("/projects", "/something", "/something/else").collect(toMap(Function.identity(), v -> new Volume()));
provider = new MachineProviderBuilder().setDevMachineVolumes(emptySet()).setAllMachineVolumes(emptySet()).build();
CheServiceImpl service = createService();
service.setVolumes(Stream.concat(Stream.of(bindMountVolumesFromMachine), Stream.of(volumesFromMachine)).collect(Collectors.toList()));
createInstanceFromSnapshot(service, true);
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
String[] actualBindMountVolumes = argumentCaptor.getValue().getContainerConfig().getHostConfig().getBinds();
Map<String, Volume> actualVolumes = argumentCaptor.getValue().getContainerConfig().getVolumes();
assertEquals(actualVolumes, expectedVolumes);
assertEqualsNoOrder(actualBindMountVolumes, expectedBindMountVolumes);
}
use of org.mockito.ArgumentCaptor in project mockito by mockito.
the class CaptorAnnotationProcessor method process.
public Object process(Captor annotation, Field field) {
Class<?> type = field.getType();
if (!ArgumentCaptor.class.isAssignableFrom(type)) {
throw new MockitoException("@Captor field must be of the type ArgumentCaptor.\n" + "Field: '" + field.getName() + "' has wrong type\n" + "For info how to use @Captor annotations see examples in javadoc for MockitoAnnotations class.");
}
Class<?> cls = new GenericMaster().getGenericType(field);
return ArgumentCaptor.forClass(cls);
}
use of org.mockito.ArgumentCaptor in project stashbot by palantir.
the class MockGitCommandBuilderFactory method reset.
@SuppressWarnings("unchecked")
private void reset() {
// list of changesets in order
changesets = new ArrayList<String>();
blacklistedChangesets = new HashSet<String>();
// for each hash, list of branches that contain said hash
branchMap = new HashMap<String, List<String>>();
gcbf = Mockito.mock(GitCommandBuilderFactory.class);
grlb = Mockito.mock(GitRevListBuilder.class);
gscb = Mockito.mock(GitScmCommandBuilder.class);
branchCommandBuilder = Mockito.mock(GitScmCommandBuilder.class);
cmd = Mockito.mock(GitCommand.class);
branchCommand = Mockito.mock(GitCommand.class);
// RevList cmd
Mockito.when(gcbf.builder()).thenReturn(gscb);
Mockito.when(gcbf.builder(Mockito.any(Repository.class))).thenReturn(gscb);
Mockito.when(gscb.revList()).thenReturn(grlb);
final ArgumentCaptor<CommandOutputHandler<Object>> cohCaptor = (ArgumentCaptor<CommandOutputHandler<Object>>) (Object) ArgumentCaptor.forClass(CommandOutputHandler.class);
Mockito.when(grlb.build(cohCaptor.capture())).thenReturn(cmd);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CommandOutputHandler<Object> coh = cohCaptor.getValue();
List<String> finalCS = new ArrayList<String>();
for (String cs : changesets) {
if (!blacklistedChangesets.contains(cs)) {
finalCS.add(cs);
}
}
String str = StringUtils.join(finalCS, "\n") + "\n";
InputStream is = new ByteArrayInputStream(str.getBytes());
coh.process(is);
return null;
}
}).when(cmd).call();
// Branch cmd - returns list of all branches
final ArgumentCaptor<CommandOutputHandler<Object>> branchCOHCaptor = (ArgumentCaptor<CommandOutputHandler<Object>>) (Object) ArgumentCaptor.forClass(CommandOutputHandler.class);
Mockito.when(gscb.command("branch")).thenReturn(branchCommandBuilder);
Mockito.when(branchCommandBuilder.build(branchCOHCaptor.capture())).thenReturn(branchCommand);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CommandOutputHandler<Object> coh = branchCOHCaptor.getValue();
String output = "";
List<String> branches = new ArrayList<String>(branchMap.keySet());
for (String branch : branches) {
output = output + " " + branch + "\n";
}
InputStream is = new ByteArrayInputStream(output.getBytes());
coh.process(is);
return null;
}
}).when(branchCommand).call();
}
use of org.mockito.ArgumentCaptor in project Shuttle by timusus.
the class ShuttleUtilsTest method testOpenShuttleLinkMarketLink.
@Test
public void testOpenShuttleLinkMarketLink() throws Exception {
Activity mockActivity = mock(Activity.class);
String fakePackage = "fake.package.name";
// Call the method and capture the "fired" intent
ShuttleUtils.openShuttleLink(mockActivity, fakePackage);
ArgumentCaptor<Intent> intentCaptor = new ArgumentCaptor<>();
verify(mockActivity).startActivity(intentCaptor.capture());
Intent intent = intentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
// Also, I guess ShuttleUtils.isAmazonBuild() needs to be tested or we can't trust this test
if (ShuttleUtils.isAmazonBuild()) {
assertThat(intent.getData()).isEqualTo(Uri.parse("amzn://apps/android?p=" + fakePackage));
} else {
assertThat(intent.getData()).isEqualTo(Uri.parse("market://details?id=" + fakePackage));
}
}
Aggregations