Search in sources :

Example 46 with Observable

use of java.util.Observable 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 47 with Observable

use of java.util.Observable 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 48 with Observable

use of java.util.Observable 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)

Example 49 with Observable

use of java.util.Observable in project jbosstools-hibernate by jbosstools.

the class GraphNodeEditPart method deactivate.

public void deactivate() {
    super.deactivate();
    Observable o = (Observable) getModel();
    o.deleteObserver(this);
}
Also used : Observable(java.util.Observable)

Example 50 with Observable

use of java.util.Observable in project jbosstools-hibernate by jbosstools.

the class GraphNodeEditPart method activate.

public void activate() {
    super.activate();
    Observable o = (Observable) getModel();
    o.addObserver(this);
    // to be in sync with the models connections
    refreshSourceConnections();
    // cannot just call refresh as that makes the connections available twice
    refreshTargetConnections();
}
Also used : Observable(java.util.Observable)

Aggregations

Observable (java.util.Observable)50 Observer (java.util.Observer)28 Test (org.junit.Test)8 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)4 LinkedList (java.util.LinkedList)3 MessagePanel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.MessagePanel)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 TreeMap (java.util.TreeMap)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