Search in sources :

Example 11 with Observer

use of java.util.Observer in project mockito by mockito.

the class ParameterizedConstructorInstantiatorTest method should_fail_if_an_argument_instance_type_do_not_match_wanted_type.

@Test
public void should_fail_if_an_argument_instance_type_do_not_match_wanted_type() throws Exception {
    Observer observer = mock(Observer.class);
    Set<?> wrongArg = mock(Set.class);
    given(resolver.resolveTypeInstances(ArgumentMatchers.<Class<?>[]>any())).willReturn(new Object[] { observer, wrongArg });
    try {
        new ParameterizedConstructorInstantiator(this, field("withMultipleConstructor"), resolver).instantiate();
        fail();
    } catch (MockitoException e) {
        assertThat(e.getMessage()).contains("argResolver").contains("incorrect types");
    }
}
Also used : ParameterizedConstructorInstantiator(org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator) MockitoException(org.mockito.exceptions.base.MockitoException) Observer(java.util.Observer) Test(org.junit.Test)

Example 12 with Observer

use of java.util.Observer in project beam by apache.

the class ElementByteSizeObservableIterable method iterator.

/**
 * Returns a new iterator for this iterable. If an observer was set in a previous call to
 * setObserver(), it will observe the iterator returned.
 */
@Override
public InputT iterator() {
    InputT iterator = createIterator();
    for (Observer observer : observers) {
        iterator.addObserver(observer);
    }
    observers.clear();
    return iterator;
}
Also used : Observer(java.util.Observer)

Example 13 with Observer

use of java.util.Observer in project android by cSploit.

the class System method notifyTargetListChanged.

/**
 * notify that a specific target of the list has been changed
 * @param target  the changed target
 */
public static void notifyTargetListChanged(Target target) {
    Observer o;
    synchronized (System.class) {
        o = targetListObserver;
    }
    if (o == null)
        return;
    o.update(null, target);
}
Also used : Observer(java.util.Observer)

Example 14 with Observer

use of java.util.Observer in project druid by alibaba.

the class ZookeeperNodeListenerTest method testRemoveOneNode.

@Test
public void testRemoveOneNode() throws Exception {
    ZookeeperNodeRegister register = registerNodeAndReturnRegister();
    // Wait for the Node to be created.
    Thread.sleep(2000);
    final CountDownLatch addCDL = new CountDownLatch(1);
    final CountDownLatch removeCDL = new CountDownLatch(1);
    ZookeeperNodeListener listener = new ZookeeperNodeListener();
    listener.setZkConnectString(server.getConnectString());
    listener.setPath(PATH);
    listener.setUrlTemplate("jdbc:mysql://${host}:${port}/foo");
    listener.setPrefix("foo");
    listener.setObserver(new Observer() {

        @Override
        public void update(Observable o, Object arg) {
            NodeEvent[] events = (NodeEvent[]) arg;
            assertEquals(1, events.length);
            NodeEvent event = events[0];
            LOG.info("NodeEvent received: " + event);
            if (NodeEventTypeEnum.DELETE == event.getType()) {
                assertEquals("sa", event.getUsername());
                assertEquals("", event.getPassword());
                assertEquals("foo.test-foo", event.getNodeName());
                assertEquals("jdbc:mysql://127.0.0.1:1234/foo", event.getUrl());
                removeCDL.countDown();
            } else {
                addCDL.countDown();
            }
        }
    });
    listener.init();
    listener.update();
    addCDL.await(10, TimeUnit.SECONDS);
    Properties properties = listener.getProperties();
    assertEquals(6, properties.size());
    register.destroy();
    removeCDL.await(10, TimeUnit.SECONDS);
    assertTrue(properties.isEmpty());
    listener.destroy();
}
Also used : Observer(java.util.Observer) CountDownLatch(java.util.concurrent.CountDownLatch) Properties(java.util.Properties) Observable(java.util.Observable) Test(org.junit.Test)

Example 15 with Observer

use of java.util.Observer in project android_frameworks_base by ParanoidAndroid.

the class ContentQueryMapTest method testContentQueryMap.

@MediumTest
public void testContentQueryMap() throws Throwable {
    LooperThread thread = new LooperThread() {

        void go() {
            ContentResolver r = getContext().getContentResolver();
            Settings.System.putString(r, "test", "Value");
            Cursor cursor = r.query(Settings.System.CONTENT_URI, new String[] { Settings.System.NAME, Settings.System.VALUE }, null, null, null);
            final ContentQueryMap cqm = new ContentQueryMap(cursor, Settings.System.NAME, true, null);
            // Get the current state of the CQM. This forces a requery and means that the
            // call to getValues() below won't do a requery().
            cqm.getRows();
            // The cache won't notice changes until the loop runs.
            Settings.System.putString(r, "test", "New Value");
            ContentValues v = cqm.getValues("test");
            String value = v.getAsString(Settings.System.VALUE);
            assertEquals("Value", value);
            // Use an Observer to find out when the cache does update.
            cqm.addObserver(new Observer() {

                public void update(Observable o, Object arg) {
                    // Should have the new values by now.
                    ContentValues v = cqm.getValues("test");
                    String value = v.getAsString(Settings.System.VALUE);
                    assertEquals("New Value", value);
                    Looper.myLooper().quit();
                    cqm.close();
                    mSuccess = true;
                }
            });
            // Give up after a few seconds, if it doesn't.
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    fail("Timed out");
                }
            }, 5000);
        }
    };
    thread.start();
    thread.join();
    if (thread.mError != null)
        throw thread.mError;
    assertTrue(thread.mSuccess);
}
Also used : ContentValues(android.content.ContentValues) ContentQueryMap(android.content.ContentQueryMap) Observer(java.util.Observer) Handler(android.os.Handler) Cursor(android.database.Cursor) Observable(java.util.Observable) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

Observer (java.util.Observer)36 Observable (java.util.Observable)29 Test (org.junit.Test)12 ContentQueryMap (android.content.ContentQueryMap)6 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Cursor (android.database.Cursor)6 Handler (android.os.Handler)6 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Map (java.util.Map)2 Properties (java.util.Properties)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)2 Job (org.eclipse.core.runtime.jobs.Job)2 ITestActor (org.getopentest.contracts.ITestActor)2 IDataObject (org.jcryptool.core.operations.dataobject.IDataObject)2 KeyStoreAlias (org.jcryptool.crypto.keystore.backend.KeyStoreAlias)2 ParameterizedConstructorInstantiator (org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator)2 CvsBundle (com.intellij.CvsBundle)1