Search in sources :

Example 11 with ArgumentMatcher

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

the class TomcatConnectorsTest method test_max_post_size_for_http_connection.

@Test
public void test_max_post_size_for_http_connection() throws Exception {
    Properties properties = new Properties();
    Props props = new Props(properties);
    TomcatConnectors.configure(tomcat, props);
    verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {

        @Override
        public boolean matches(Object o) {
            Connector c = (Connector) o;
            return c.getMaxPostSize() == -1;
        }
    }));
}
Also used : Connector(org.apache.catalina.connector.Connector) ArgumentMatcher(org.mockito.ArgumentMatcher) Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 12 with ArgumentMatcher

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

the class TomcatConnectorsTest method bind_to_specific_address.

@Test
public void bind_to_specific_address() {
    Properties p = new Properties();
    p.setProperty("sonar.web.port", "9000");
    p.setProperty("sonar.web.host", "1.2.3.4");
    TomcatConnectors.configure(tomcat, new Props(p));
    verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher<Connector>() {

        @Override
        public boolean matches(Object o) {
            Connector c = (Connector) o;
            return c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("1.2.3.4");
        }
    }));
}
Also used : Connector(org.apache.catalina.connector.Connector) ArgumentMatcher(org.mockito.ArgumentMatcher) Properties(java.util.Properties) Props(org.sonar.process.Props) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 13 with ArgumentMatcher

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

the class NetworkScorerAppManagerTest method setScorers.

private void setScorers(List<ResolveInfoHolder> scorers) {
    List<ResolveInfo> receivers = new ArrayList<>();
    for (final ResolveInfoHolder scorer : scorers) {
        receivers.add(scorer.scorerResolveInfo);
        if (scorer.configActivityResolveInfo != null) {
            // This scorer has a config activity.
            Mockito.when(mMockPm.queryIntentActivities(Mockito.argThat(new ArgumentMatcher<Intent>() {

                @Override
                public boolean matches(Object object) {
                    Intent intent = (Intent) object;
                    return NetworkScoreManager.ACTION_CUSTOM_ENABLE.equals(intent.getAction()) && scorer.scorerResolveInfo.activityInfo.packageName.equals(intent.getPackage());
                }
            }), Mockito.eq(0))).thenReturn(Collections.singletonList(scorer.configActivityResolveInfo));
        }
        if (scorer.serviceResolveInfo != null) {
            // This scorer has a service to bind to
            Mockito.when(mMockPm.resolveService(Mockito.argThat(new ArgumentMatcher<Intent>() {

                @Override
                public boolean matches(Object object) {
                    Intent intent = (Intent) object;
                    return NetworkScoreManager.ACTION_SCORE_NETWORKS.equals(intent.getAction()) && scorer.scorerResolveInfo.activityInfo.packageName.equals(intent.getPackage());
                }
            }), Mockito.eq(0))).thenReturn(scorer.serviceResolveInfo);
        }
    }
    Mockito.when(mMockPm.queryBroadcastReceiversAsUser(Mockito.argThat(new ArgumentMatcher<Intent>() {

        @Override
        public boolean matches(Object object) {
            Intent intent = (Intent) object;
            return NetworkScoreManager.ACTION_SCORE_NETWORKS.equals(intent.getAction());
        }
    }), Mockito.eq(0), Mockito.eq(UserHandle.USER_SYSTEM))).thenReturn(receivers);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArgumentMatcher(org.mockito.ArgumentMatcher) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 14 with ArgumentMatcher

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

the class ToStringGenerator method generate.

public String generate(Object mock, Method method, Object[] arguments) {
    final List<ArgumentMatcher> matcherList = ArgumentsProcessor.argumentsToMatchers(arguments);
    final PrintSettings printSettings = new PrintSettings();
    MatchersPrinter matchersPrinter = new MatchersPrinter();
    String methodName = Whitebox.getUnproxyType(mock).getName() + "." + method.getName();
    String invocation = methodName + matchersPrinter.getArgumentsLine(matcherList, printSettings);
    if (printSettings.isMultiline() || (!matcherList.isEmpty() && invocation.length() > Whitebox.<Integer>getInternalState(PrintSettings.class, "MAX_LINE_LENGTH"))) {
        return methodName + matchersPrinter.getArgumentsBlock(matcherList, printSettings);
    } else {
        return invocation;
    }
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) PrintSettings(org.mockito.internal.reporting.PrintSettings) MatchersPrinter(org.mockito.internal.matchers.text.MatchersPrinter)

Example 15 with ArgumentMatcher

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

the class KafkaSpoutBufferBehaviourTest method testDeclarations.

@Test
public void testDeclarations() {
    final OutputFieldsDeclarer declarer = mock(OutputFieldsDeclarer.class);
    _subject.declareOutputFields(declarer);
    // verify the spout declares to output single-field tuples
    verify(declarer).declare(argThat(new ArgumentMatcher<Fields>() {

        @Override
        public boolean matches(final Object argument) {
            final Fields fields = (Fields) argument;
            return fields.size() == 1 && fields.get(0).equals("bytes");
        }
    }));
    // verify the spout will not provide component configuration
    assertNull(_subject.getComponentConfiguration());
}
Also used : Fields(backtype.storm.tuple.Fields) ArgumentMatcher(org.mockito.ArgumentMatcher) OutputFieldsDeclarer(backtype.storm.topology.OutputFieldsDeclarer) Test(org.junit.Test)

Aggregations

ArgumentMatcher (org.mockito.ArgumentMatcher)142 Test (org.junit.Test)116 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)36 Context (android.content.Context)26 Matchers.anyString (org.mockito.Matchers.anyString)26 HashMap (java.util.HashMap)25 Appender (ch.qos.logback.core.Appender)23 Logger (org.slf4j.Logger)23 ArrayList (java.util.ArrayList)19 UUID (java.util.UUID)19 Intent (android.content.Intent)18 File (java.io.File)15 ResolveInfo (android.content.pm.ResolveInfo)14 PackageManager (android.content.pm.PackageManager)13 Channel (com.microsoft.azure.mobile.channel.Channel)13 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 IOException (java.io.IOException)12 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)11 Activity (android.app.Activity)10