use of mockit.Delegate in project docker-maven-plugin by fabric8io.
the class VolumeServiceTest method testCreateVolumeConfig.
@Test
public void testCreateVolumeConfig() throws Exception {
final VolumeConfiguration config = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
new Expectations() {
{
// Use a 'delegate' to verify the argument given directly. No need
// for an 'intermediate' return method in the service just to check this.
docker.createVolume(with(new Delegate<VolumeCreateConfig>() {
void check(VolumeCreateConfig vcc) {
assertThat(vcc.getName(), is("testVolume"));
JSONObject vccJson = (JSONObject) JSONParser.parseJSON(vcc.toJson());
assertEquals(vccJson.get("Driver"), "test");
}
}));
result = "testVolume";
}
};
String volume = new VolumeService(docker).createVolume(config);
assertEquals(volume, "testVolume");
}
use of mockit.Delegate in project tutorials by eugenp.
the class ExpectationsIntegrationTest method testDelegate.
@Test
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
new Expectations() {
{
mock.methodForDelegate(anyInt);
result = new Delegate() {
public int delegate(int i) throws Exception {
if (i < 3) {
return 5;
} else {
throw new Exception();
}
}
};
}
};
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
try {
mock.methodForDelegate(3);
} catch (Exception e) {
}
}
use of mockit.Delegate in project streamline by hortonworks.
the class TopologyTestRunnerTest method setSucceedTopologyActionsExpectations.
private void setSucceedTopologyActionsExpectations() throws Exception {
new Expectations() {
{
topologyActions.runTest(withInstanceOf(TopologyLayout.class), withInstanceOf(TopologyTestRunHistory.class), anyString, withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Optional.class));
result = new Delegate<Object>() {
Object delegate(TopologyLayout topology, TopologyTestRunHistory testRunHistory, String mavenArtifacts, Map<String, TestRunSource> testRunSourcesForEachSource, Map<String, TestRunProcessor> testRunProcessorsForEachProcessor, Map<String, TestRunRulesProcessor> testRunRulesProcessorsForEachProcessor, Map<String, TestRunSink> testRunSinksForEachSink, Optional<Long> durationSecs) throws Exception {
Map<String, List<Map<String, Object>>> testOutputRecords = TopologyTestHelper.createTestOutputRecords(testRunSinksForEachSink.keySet());
testRunSinksForEachSink.entrySet().forEach(entry -> {
String sinkName = entry.getKey();
TestRunSink sink = entry.getValue();
try (FileWriter fw = new FileWriter(sink.getOutputFilePath())) {
List<Map<String, Object>> outputRecords = testOutputRecords.get(sinkName);
for (Map<String, Object> record : outputRecords) {
fw.write(objectMapper.writeValueAsString(record) + "\n");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return null;
}
};
}
};
}
Aggregations