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();
}
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();
}
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')");
}
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());
}
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");
}
}));
}
Aggregations