Search in sources :

Example 51 with Capture

use of org.easymock.Capture in project android_frameworks_base by ParanoidAndroid.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    mAlarmManager = createMock(IAlarmManager.class);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    mService = new NetworkStatsService(mServiceContext, mNetManager, mAlarmManager, mTime, mStatsDir, mSettings);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsSummary(buildEmptyStats());
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) IAlarmManager(android.app.IAlarmManager) NetworkStatsService(com.android.server.net.NetworkStatsService) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager) Capture(org.easymock.Capture)

Example 52 with Capture

use of org.easymock.Capture in project intellij-community by JetBrains.

the class PyPullUpPresenterTest method testConflicts.

/**
   * Ensures that presenter displays conflicts if destination class already has that members
   */
public void testConflicts() throws Exception {
    final PyPullUpPresenterImpl sut = configureByClass("ChildWithConflicts");
    configureParent();
    final Collection<PyMemberInfo<PyElement>> infos = getMemberInfos(sut);
    final Capture<MultiMap<PyClass, PyMemberInfo<?>>> conflictCapture = new Capture<>();
    EasyMock.expect(myView.showConflictsDialog(EasyMock.capture(conflictCapture), EasyMock.<Collection<PyMemberInfo<?>>>anyObject())).andReturn(false).anyTimes();
    EasyMock.expect(myView.getSelectedMemberInfos()).andReturn(infos).anyTimes();
    final PyClass parent = getClassByName("ParentWithConflicts");
    EasyMock.expect(myView.getSelectedParent()).andReturn(parent).anyTimes();
    myMocksControl.replay();
    sut.okClicked();
    final MultiMap<PyClass, PyMemberInfo<?>> conflictMap = conflictCapture.getValue();
    Assert.assertTrue("No conflicts found, while it should", conflictMap.containsKey(parent));
    final Collection<String> conflictedMemberNames = Collections2.transform(conflictMap.get(parent), NameTransformer.INSTANCE);
    Assert.assertThat("Failed to find right conflicts", conflictedMemberNames, Matchers.containsInAnyOrder("extends Bar", "CLASS_FIELD", "self.instance_field", "my_func(self)", "__init__(self)"));
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) Collection(java.util.Collection) Capture(org.easymock.Capture)

Example 53 with Capture

use of org.easymock.Capture in project camel by apache.

the class XPathTransformTest method testXPathNamespaceLoggingDisabledJavaDSL.

public void testXPathNamespaceLoggingDisabledJavaDSL() throws Exception {
    Logger l = createNiceMock(Logger.class);
    expect(l.isInfoEnabled()).andReturn(true).anyTimes();
    Capture<String> captures = new Capture<String>(CaptureType.ALL);
    l.info(capture(captures), anyObject(Object.class));
    expectLastCall().anyTimes();
    replay(l);
    String body = "<aRoot xmlns:nsa=\"http://namespacec.net\"><nsa:a xmlns:nsa=\"http://namespacea.net\">Hello|there|Camel</nsa:a>" + "<nsb:a xmlns:nsb=\"http://namespaceb.net\">Hello|there|Camel</nsb:a><nsb:a xmlns:nsb=\"http://namespaceb.net\">Hello|there|Camel</nsb:a>" + "<a xmlns=\"http://defaultNamespace.net\">Hello|there|Camel</a><a>Hello|there|Camel</a></aRoot>";
    Document doc = context.getTypeConverter().convertTo(Document.class, body);
    Field logField = XPathBuilder.class.getDeclaredField("LOG");
    logField.setAccessible(true);
    Field modifiers = Field.class.getDeclaredField("modifiers");
    modifiers.setAccessible(true);
    modifiers.setInt(logField, logField.getModifiers() & ~Modifier.FINAL);
    logField.set(null, l);
    NodeList list = XPathBuilder.xpath("//*", NodeList.class).evaluate(context, doc, NodeList.class);
    assertNotNull(list);
    verify(l);
    for (String c : captures.getValues()) {
        if (c.contains("Namespaces discovered in message")) {
            throw new AssertionError("Did not expect LOG.info with 'Namespaces discovered in message'");
        }
    }
}
Also used : Field(java.lang.reflect.Field) NodeList(org.w3c.dom.NodeList) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Logger(org.slf4j.Logger) Document(org.w3c.dom.Document) Capture(org.easymock.Capture)

Example 54 with Capture

use of org.easymock.Capture in project android_frameworks_base by crdroidandroid.

the class NetworkStatsServiceTest method testStatsRebootPersist.

public void testStatsRebootPersist() throws Exception {
    assertStatsFilesExist(false);
    // pretend that wifi network comes online; service should ask about full
    // network state, and poll any existing interfaces before updating.
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkState(buildWifiState());
    expectNetworkStatsSummary(buildEmptyStats());
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectNetworkStatsPoll();
    expectBandwidthControlCheck();
    replay();
    mService.forceUpdateIfaces();
    // verify service has empty history for wifi
    assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
    verifyAndReset();
    // modify some number on wifi, and trigger poll event
    incrementCurrentTime(HOUR_IN_MILLIS);
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 1024L, 8L, 2048L, 16L));
    expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 2).addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 512L, 4L, 256L, 2L, 0L).addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 256L, 2L, 128L, 1L, 0L).addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 512L, 4L, 256L, 2L, 0L).addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 256L, 2L, 128L, 1L, 0L).addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 0L));
    expectNetworkStatsPoll();
    mService.setUidForeground(UID_RED, false);
    mService.incrementOperationCount(UID_RED, 0xFAAD, 4);
    mService.setUidForeground(UID_RED, true);
    mService.incrementOperationCount(UID_RED, 0xFAAD, 6);
    replay();
    forcePollAndWaitForIdle();
    // verify service recorded history
    assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
    assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
    assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, ROAMING_NO, 512L, 4L, 256L, 2L, 4);
    assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L, 6);
    assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
    verifyAndReset();
    // graceful shutdown system, which should trigger persist of stats, and
    // clear any values in memory.
    expectCurrentTime();
    expectDefaultSettings();
    replay();
    mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SHUTDOWN));
    verifyAndReset();
    assertStatsFilesExist(true);
    // boot through serviceReady() again
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mNetworkObserver = networkObserver.getValue();
    // after systemReady(), we should have historical stats loaded again
    assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
    assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
    assertUidTotal(sTemplateWifi, UID_RED, SET_DEFAULT, ROAMING_NO, 512L, 4L, 256L, 2L, 4);
    assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L, 6);
    assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
    verifyAndReset();
}
Also used : NetworkStats(android.net.NetworkStats) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Capture(org.easymock.Capture)

Example 55 with Capture

use of org.easymock.Capture in project felix by apache.

the class RepositoryAdminTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
    Bundle systemBundle = EasyMock.createMock(Bundle.class);
    BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);
    Activator.setContext(bundleContext);
    EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
    EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
    EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
    EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
    EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
    EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
    EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
    EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
    bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
    bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
    EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
    final Capture c = new Capture();
    EasyMock.expect(bundleContext.createFilter((String) capture(c))).andAnswer(new IAnswer() {

        public Object answer() throws Throwable {
            return FilterImpl.newInstance((String) c.getValue());
        }
    }).anyTimes();
    EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
    RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
    // force initialization && remove all initial repositories
    org.apache.felix.bundlerepository.Repository[] repos = repoAdmin.listRepositories();
    for (int i = 0; repos != null && i < repos.length; i++) {
        repoAdmin.removeRepository(repos[i].getURI());
    }
    return repoAdmin;
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Logger(org.apache.felix.utils.log.Logger) Capture(org.easymock.Capture) IAnswer(org.easymock.IAnswer) Repository(org.apache.felix.bundlerepository.Repository) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Capture (org.easymock.Capture)79 Test (org.junit.Test)42 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)12 File (java.io.File)10 Intent (android.content.Intent)8 IConnectivityManager (android.net.IConnectivityManager)8 INetworkManagementService (android.os.INetworkManagementService)8 TrustedTime (android.util.TrustedTime)8 IAnswer (org.easymock.IAnswer)7 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)6 EurekaEventListener (com.netflix.discovery.EurekaEventListener)6 Map (java.util.Map)6 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)6 UrlRewriteContext (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext)6 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5 Template (org.apache.knox.gateway.util.urltemplate.Template)5 EurekaClient (com.netflix.discovery.EurekaClient)4 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)4 URI (java.net.URI)4