Search in sources :

Example 1 with Description

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);
    }
}
Also used : Description(org.hamcrest.Description) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) Duration(org.joda.time.Duration) AtomicReference(java.util.concurrent.atomic.AtomicReference) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) IOException(java.io.IOException) URL(java.net.URL) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with Description

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);
    }
}
Also used : Description(org.hamcrest.Description) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with Description

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));
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) MapSettings(org.sonar.api.config.MapSettings) NoRouteToHostException(java.net.NoRouteToHostException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with Description

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();
}
Also used : Description(org.hamcrest.Description) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) Test(org.junit.Test)

Example 5 with Description

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");
        }
    };
}
Also used : Description(org.hamcrest.Description) ClassByteCodeMethod(org.freud.analysed.classbytecode.method.ClassByteCodeMethod) Opcode(org.freud.analysed.classbytecode.method.instruction.Opcode) Instruction(org.freud.analysed.classbytecode.method.instruction.Instruction) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) AbstractInstructionVisitor(org.freud.analysed.classbytecode.method.instruction.AbstractInstructionVisitor)

Aggregations

Description (org.hamcrest.Description)117 Test (org.junit.Test)37 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)26 BaseMatcher (org.hamcrest.BaseMatcher)25 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6