Search in sources :

Example 31 with Observer

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

the class ParameterizedConstructorInstantiatorTest method should_instantiate_type_if_resolver_provide_matching_types.

@Test
public void should_instantiate_type_if_resolver_provide_matching_types() throws Exception {
    Observer observer = mock(Observer.class);
    Map map = mock(Map.class);
    given(resolver.resolveTypeInstances(ArgumentMatchers.<Class<?>[]>any())).willReturn(new Object[] { observer, map });
    new ParameterizedConstructorInstantiator(this, field("withMultipleConstructor"), resolver).instantiate();
    assertNotNull(withMultipleConstructor);
    assertNotNull(withMultipleConstructor.observer);
    assertNotNull(withMultipleConstructor.map);
}
Also used : ParameterizedConstructorInstantiator(org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator) Observer(java.util.Observer) Map(java.util.Map) Test(org.junit.Test)

Example 32 with Observer

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

the class ParameterizedConstructorInstantiatorTest method should_instantiate_type_with_vararg_constructor.

@Test
public void should_instantiate_type_with_vararg_constructor() throws Exception {
    Observer[] vararg = new Observer[] {};
    given(resolver.resolveTypeInstances(ArgumentMatchers.<Class<?>[]>any())).willReturn(new Object[] { "", vararg });
    new ParameterizedConstructorInstantiator(this, field("withVarargConstructor"), resolver).instantiate();
    assertNotNull(withVarargConstructor);
}
Also used : ParameterizedConstructorInstantiator(org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator) Observer(java.util.Observer) Test(org.junit.Test)

Example 33 with Observer

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

the class SubclassByteBuddyMockMakerTest method is_type_mockable_allow_anonymous.

@Test
public void is_type_mockable_allow_anonymous() {
    Observer anonymous = new Observer() {

        @Override
        public void update(Observable o, Object arg) {
        }
    };
    MockMaker.TypeMockability mockable = mockMaker.isTypeMockable(anonymous.getClass());
    assertThat(mockable.mockable()).isTrue();
    assertThat(mockable.nonMockableReason()).contains("");
}
Also used : Observer(java.util.Observer) MockMaker(org.mockito.plugins.MockMaker) Observable(java.util.Observable) Test(org.junit.Test)

Example 34 with Observer

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

the class FileNodeListenerTest method testUpdate.

@Test
public void testUpdate() throws InterruptedException {
    final CountDownLatch cdl = new CountDownLatch(1);
    String file = "/com/alibaba/druid/pool/ha/ha-with-prefix-datasource.properties";
    FileNodeListener listener = new FileNodeListener();
    listener.setFile(file);
    listener.setPrefix("prefix1");
    listener.setObserver(new Observer() {

        @Override
        public void update(Observable o, Object arg) {
            cdl.countDown();
            assertTrue(o instanceof FileNodeListener);
            assertTrue(arg instanceof NodeEvent[]);
            NodeEvent[] events = (NodeEvent[]) arg;
            assertEquals(1, events.length);
            assertEquals(NodeEventTypeEnum.ADD, events[0].getType());
            assertEquals("prefix1.foo", events[0].getNodeName());
            assertEquals("jdbc:derby:memory:foo1;create=true", events[0].getUrl());
        }
    });
    listener.init();
    listener.update();
    assertTrue(cdl.await(100, TimeUnit.MILLISECONDS));
}
Also used : Observer(java.util.Observer) CountDownLatch(java.util.concurrent.CountDownLatch) Observable(java.util.Observable) Test(org.junit.Test)

Example 35 with Observer

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

the class ZookeeperNodeListenerTest method testAddOneNode.

@Test
public void testAddOneNode() throws Exception {
    final CountDownLatch cdl = 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.ADD == 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());
                cdl.countDown();
            }
        }
    });
    listener.init();
    ZookeeperNodeRegister register = registerNodeAndReturnRegister();
    // Wait for the Node to be created.
    Thread.sleep(2000);
    cdl.await(10, TimeUnit.SECONDS);
    Properties properties = listener.getProperties();
    assertEquals(6, properties.size());
    assertEquals("sa", properties.getProperty("foo.test-foo.username"));
    assertEquals("", properties.getProperty("foo.test-foo.password"));
    assertEquals("127.0.0.1", properties.getProperty("foo.test-foo.host"));
    assertEquals("1234", properties.getProperty("foo.test-foo.port"));
    assertEquals("jdbc:mysql://127.0.0.1:1234/foo", properties.getProperty("foo.test-foo.url"));
    register.destroy();
    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)

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