Search in sources :

Example 6 with Description

use of org.hamcrest.Description in project byte-buddy by raphw.

the class AgentBuilderRedefinitionStrategyResubmissionStrategyTest method testRedefinition.

@Test
@SuppressWarnings("unchecked")
public void testRedefinition() throws Exception {
    when(instrumentation.isModifiableClass(Foo.class)).thenReturn(true);
    when(redefinitionBatchAllocator.batch(Mockito.any(List.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return Collections.singleton(invocationOnMock.getArgumentAt(0, List.class));
        }
    });
    when(rawMatcher.matches(new TypeDescription.ForLoadedType(Foo.class), Foo.class.getClassLoader(), JavaModule.ofType(Foo.class), Foo.class, Foo.class.getProtectionDomain())).thenReturn(true);
    when(matcher.matches(error)).thenReturn(true);
    when(resubmissionScheduler.isAlive()).thenReturn(true);
    ClassFileLocator classFileLocator = mock(ClassFileLocator.class);
    when(locationStrategy.classFileLocator(Foo.class.getClassLoader(), JavaModule.ofType(Foo.class))).thenReturn(classFileLocator);
    when(classFileLocator.locate(Foo.class.getName())).thenReturn(new ClassFileLocator.Resolution.Explicit(new byte[] { 1, 2, 3 }));
    AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Installation installation = new AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled(resubmissionScheduler, matcher).install(instrumentation, locationStrategy, listener, installationListener, circularityLock, rawMatcher, AgentBuilder.RedefinitionStrategy.REDEFINITION, redefinitionBatchAllocator, redefinitionListener);
    installation.getInstallationListener().onInstall(instrumentation, classFileTransformer);
    installation.getListener().onError(Foo.class.getName(), Foo.class.getClassLoader(), JavaModule.ofType(Foo.class), false, error);
    ArgumentCaptor<Runnable> argumentCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(resubmissionScheduler).isAlive();
    verify(resubmissionScheduler).schedule(argumentCaptor.capture());
    argumentCaptor.getValue().run();
    verifyNoMoreInteractions(resubmissionScheduler);
    verify(instrumentation).isModifiableClass(Foo.class);
    verify(instrumentation).redefineClasses(Mockito.argThat(new BaseMatcher<ClassDefinition[]>() {

        @Override
        public boolean matches(Object o) {
            return ((ClassDefinition) o).getDefinitionClass() == Foo.class && Arrays.equals(((ClassDefinition) o).getDefinitionClassFile(), new byte[] { 1, 2, 3 });
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
    verifyNoMoreInteractions(instrumentation);
    verify(rawMatcher).matches(new TypeDescription.ForLoadedType(Foo.class), Foo.class.getClassLoader(), JavaModule.ofType(Foo.class), Foo.class, Foo.class.getProtectionDomain());
    verifyNoMoreInteractions(rawMatcher);
    verify(redefinitionBatchAllocator).batch(Collections.<Class<?>>singletonList(Foo.class));
    verifyNoMoreInteractions(redefinitionBatchAllocator);
    verify(listener).onError(Foo.class.getName(), Foo.class.getClassLoader(), JavaModule.ofType(Foo.class), false, error);
    verifyNoMoreInteractions(listener);
    verify(matcher).matches(error);
    verifyNoMoreInteractions(matcher);
}
Also used : Description(org.hamcrest.Description) TypeDescription(net.bytebuddy.description.type.TypeDescription) ClassDefinition(java.lang.instrument.ClassDefinition) ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) BaseMatcher(org.hamcrest.BaseMatcher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TypeDescription(net.bytebuddy.description.type.TypeDescription) List(java.util.List) Test(org.junit.Test)

Example 7 with Description

use of org.hamcrest.Description in project gocd by gocd.

the class GoConfigServiceTest method isAPipelineSelectionsInstanceWith.

private Matcher<PipelineSelections> isAPipelineSelectionsInstanceWith(final boolean isBlacklist, final String... pipelineSelectionsInInstance) {
    return new BaseMatcher<PipelineSelections>() {

        public boolean matches(Object o) {
            PipelineSelections pipelineSelections = (PipelineSelections) o;
            assertThat(pipelineSelections.isBlacklist(), is(isBlacklist));
            List<String> expectedSelectionsAsList = Arrays.asList(pipelineSelectionsInInstance);
            assertEquals(pipelineSelections.getSelections(), ListUtil.join(expectedSelectionsAsList, ","));
            return true;
        }

        public void describeTo(Description description) {
        }
    };
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) StringContains.containsString(org.hamcrest.core.StringContains.containsString)

Example 8 with Description

use of org.hamcrest.Description in project querydsl by querydsl.

the class PathMatcherTest method mismatch.

@Test
public void mismatch() {
    Car car = new Car();
    car.setHorsePower(123);
    Description mismatchDescription = new StringDescription();
    hasValue($.horsePower, equalTo(321)).describeMismatch(car, mismatchDescription);
    assertEquals("value \"car.horsePower\" was <123>", mismatchDescription.toString());
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) Test(org.junit.Test)

Example 9 with Description

use of org.hamcrest.Description in project JsonPath by jayway.

the class IsJsonFileTest method shouldDescribeMismatchOfValidJson.

@Test
public void shouldDescribeMismatchOfValidJson() {
    Matcher<File> matcher = isJsonFile(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeMismatch(BOOKS_JSON, description);
    assertThat(description.toString(), containsString(MISMATCHED_TEXT));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) File(java.io.File) JsonPathMatchers.isJsonFile(com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile) ResourceHelpers.resourceAsFile(com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile) Test(org.junit.Test)

Example 10 with Description

use of org.hamcrest.Description in project JsonPath by jayway.

the class IsJsonStringTest method shouldDescribeMismatchOfValidJson.

@Test
public void shouldDescribeMismatchOfValidJson() {
    Matcher<String> matcher = isJsonString(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeMismatch(BOOKS_JSON, description);
    assertThat(description.toString(), containsString(MISMATCHED_TEXT));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) JsonPathMatchers.isJsonString(com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonString) Test(org.junit.Test)

Aggregations

Description (org.hamcrest.Description)122 Test (org.junit.Test)38 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)29 BaseMatcher (org.hamcrest.BaseMatcher)27 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