use of org.hamcrest.Description in project druid by druid-io.
the class LookupCoordinatorManagerTest method testUpdateAllOnHostException.
@Test
public void testUpdateAllOnHostException() throws Exception {
final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
final SettableFuture<InputStream> future = SettableFuture.create();
future.set(new ByteArrayInputStream(new byte[0]));
EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
EasyMock.replay(client, responseHandler);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {
@Override
HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
returnCode.set(500);
reasonString.set("");
return responseHandler;
}
};
expectedException.expect(new BaseMatcher<Throwable>() {
@Override
public boolean matches(Object o) {
return o instanceof IOException && ((IOException) o).getMessage().startsWith("Bad update request");
}
@Override
public void describeTo(Description description) {
}
});
try {
manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
} finally {
EasyMock.verify(client, responseHandler);
}
}
use of org.hamcrest.Description in project druid by druid-io.
the class LookupCoordinatorManagerTest method testLookupDiscoverAllExceptional.
@Test
public void testLookupDiscoverAllExceptional() throws Exception {
final IOException ex = new IOException("some exception");
EasyMock.reset(discoverer);
EasyMock.expect(discoverer.discoverChildren(LookupCoordinatorManager.LOOKUP_LISTEN_ANNOUNCE_KEY)).andThrow(ex).once();
expectedException.expectCause(new BaseMatcher<Throwable>() {
@Override
public boolean matches(Object o) {
return o == ex;
}
@Override
public void describeTo(Description description) {
}
});
EasyMock.replay(discoverer);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig);
try {
manager.discoverTiers();
} finally {
EasyMock.verify(discoverer);
}
}
use of org.hamcrest.Description in project sonarqube by SonarSource.
the class DefaultHttpDownloaderTest method openStream_network_errors.
@Test(timeout = 10000)
public void openStream_network_errors() throws IOException, URISyntaxException {
// non routable address
String url = "http://10.255.255.1";
thrown.expect(SonarException.class);
thrown.expect(hasCause(new BaseMatcher<Exception>() {
@Override
public boolean matches(Object ex) {
return // Java 8
ex instanceof NoRouteToHostException || ex instanceof SocketException || // Java 7 or before
ex instanceof SocketTimeoutException;
}
@Override
public void describeTo(Description arg0) {
}
}));
DefaultHttpDownloader downloader = new DefaultHttpDownloader(new MapSettings(), 10, 50000);
downloader.openStream(new URI(url));
}
use of org.hamcrest.Description in project sonarqube by SonarSource.
the class HighlightingMediumTest method computeInvalidOffsets.
@Test
public void computeInvalidOffsets() throws IOException {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting");
FileUtils.write(xooFile, "Sample xoo\ncontent plop");
FileUtils.write(xoohighlightingFile, "0:10:s\n18:18:k");
exception.expect(IllegalStateException.class);
exception.expectMessage("Error processing line 2");
exception.expectCause(new TypeSafeMatcher<IllegalArgumentException>() {
@Override
public void describeTo(Description description) {
description.appendText("Invalid cause");
}
@Override
protected boolean matchesSafely(IllegalArgumentException e) {
return e.getMessage().contains("Unable to highlight file");
}
});
tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
}
use of org.hamcrest.Description in project freud by LMAX-Exchange.
the class ClassByteCodeMethodMatchers method containsInstructions.
public static FreudExtendedMatcher<ClassByteCodeMethod> containsInstructions(final Opcode... opcodes) {
return new FreudExtendedMatcher<ClassByteCodeMethod>() {
private Instruction found = null;
@Override
protected boolean matchesSafely(final ClassByteCodeMethod item) {
item.findInstruction(new AbstractInstructionVisitor() {
@Override
public void noArgInstruction(final Instruction instruction) {
for (int i = 0; i < opcodes.length; i++) {
Opcode opcode = opcodes[i];
if (instruction.getOpcode() == opcode) {
found = instruction;
break;
}
}
}
});
return found != null;
}
@Override
public void describeTo(final Description description) {
description.appendText("containsInstructions(");
for (int i = 0; i < opcodes.length; i++) {
Opcode opcode = opcodes[i];
description.appendText(opcode.name());
description.appendText(", ");
}
description.appendText(") found");
}
};
}
Aggregations