Search in sources :

Example 71 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project mockito by mockito.

the class TypeSafeMatchingTest method dontMatchesWithSubTypeExtendingGenericClass.

@Test
public void dontMatchesWithSubTypeExtendingGenericClass() {
    final AtomicBoolean wasCalled = new AtomicBoolean();
    abstract class GenericMatcher<T> implements ArgumentMatcher<T> {
    }
    class TestMatcher extends GenericMatcher<Integer> {

        @Override
        public boolean matches(Integer argument) {
            wasCalled.set(true);
            return true;
        }
    }
    wasCalled.set(false);
    matchesTypeSafe().apply(new TestMatcher(), 123);
    assertThat(wasCalled.get()).isTrue();
    wasCalled.set(false);
    matchesTypeSafe().apply(new TestMatcher(), "");
    assertThat(wasCalled.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArgumentMatcher(org.mockito.ArgumentMatcher) Test(org.junit.Test)

Example 72 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project mockito by mockito.

the class TypeSafeMatchingTest method passEveryArgumentTypeIfNoBridgeMethodWasGenerated.

@Test
public void passEveryArgumentTypeIfNoBridgeMethodWasGenerated() {
    final AtomicBoolean wasCalled = new AtomicBoolean();
    class GenericMatcher<T> implements ArgumentMatcher<T> {

        @Override
        public boolean matches(T argument) {
            wasCalled.set(true);
            return true;
        }
    }
    wasCalled.set(false);
    matchesTypeSafe().apply(new GenericMatcher<Integer>(), 123);
    assertThat(wasCalled.get()).isTrue();
    wasCalled.set(false);
    matchesTypeSafe().apply(new GenericMatcher<Integer>(), "");
    assertThat(wasCalled.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArgumentMatcher(org.mockito.ArgumentMatcher) Test(org.junit.Test)

Example 73 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project mockito by mockito.

the class InvocationMatcherTest method should_to_string_with_matchers.

@Test
public void should_to_string_with_matchers() throws Exception {
    ArgumentMatcher m = NotNull.NOT_NULL;
    InvocationMatcher notNull = new InvocationMatcher(new InvocationBuilder().toInvocation(), asList(m));
    ArgumentMatcher mTwo = new Equals('x');
    InvocationMatcher equals = new InvocationMatcher(new InvocationBuilder().toInvocation(), asList(mTwo));
    assertThat(notNull.toString()).contains("simpleMethod(notNull())");
    assertThat(equals.toString()).contains("simpleMethod('x')");
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) ArgumentMatcher(org.mockito.ArgumentMatcher) Test(org.junit.Test)

Example 74 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project neo4j by neo4j.

the class DBMSModuleTest method shouldNotRegisterUserServiceWhenAuthDisabled.

@SuppressWarnings("unchecked")
@Test
public void shouldNotRegisterUserServiceWhenAuthDisabled() throws Exception {
    WebServer webServer = mock(WebServer.class);
    Config config = mock(Config.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(false);
    DBMSModule module = new DBMSModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(anyList(), anyString(), anyCollection());
    verify(webServer, never()).addJAXRSClasses(Matchers.argThat(new ArgumentMatcher<List<String>>() {

        @Override
        public boolean matches(Object argument) {
            List<String> argumentList = (List<String>) argument;
            return argumentList.contains(UserService.class.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("<List containing " + UserService.class.getName() + ">");
        }
    }), anyString(), anyCollection());
}
Also used : Description(org.hamcrest.Description) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) UserService(org.neo4j.server.rest.dbms.UserService) Config(org.neo4j.kernel.configuration.Config) ArgumentMatcher(org.mockito.ArgumentMatcher) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 75 with ArgumentMatcher

use of org.mockito.ArgumentMatcher in project kafka-spout by HolmesNL.

the class KafkaSpoutConstructorTest method testDelegateCustomScheme.

@Test
public void testDelegateCustomScheme() {
    final Scheme scheme = new Scheme() {

        @Override
        public List<Object> deserialize(final byte[] bytes) {
            return Arrays.<Object>asList(new byte[] { bytes[0] }, Arrays.copyOfRange(bytes, 1, bytes.length));
        }

        @Override
        public Fields getOutputFields() {
            return new Fields("head", "tail");
        }
    };
    final OutputFieldsDeclarer declarer = mock(OutputFieldsDeclarer.class);
    // test for both constructors that accept a scheme
    new KafkaSpout(scheme).declareOutputFields(declarer);
    new KafkaSpout("topic", scheme).declareOutputFields(declarer);
    // Fields doesn't implement equals; match it manually
    verify(declarer, times(2)).declare(argThat(new ArgumentMatcher<Fields>() {

        @Override
        public boolean matches(final Object argument) {
            final Fields fields = (Fields) argument;
            return fields.size() == 2 && fields.get(0).equals("head") && fields.get(1).equals("tail");
        }
    }));
}
Also used : Scheme(backtype.storm.spout.Scheme) Fields(backtype.storm.tuple.Fields) ArgumentMatcher(org.mockito.ArgumentMatcher) OutputFieldsDeclarer(backtype.storm.topology.OutputFieldsDeclarer) Test(org.junit.Test)

Aggregations

ArgumentMatcher (org.mockito.ArgumentMatcher)104 Test (org.junit.Test)82 Appender (ch.qos.logback.core.Appender)23 Logger (org.slf4j.Logger)23 ArrayList (java.util.ArrayList)19 Context (android.content.Context)14 Channel (com.microsoft.azure.mobile.channel.Channel)13 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Intent (android.content.Intent)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)10 FeaturesService (org.apache.karaf.features.FeaturesService)10 ResolveInfo (android.content.pm.ResolveInfo)9 File (java.io.File)9 Repository (org.apache.karaf.features.Repository)9 Matchers.anyString (org.mockito.Matchers.anyString)9 UUID (java.util.UUID)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Log (com.microsoft.azure.mobile.ingestion.models.Log)7