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("");
}
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));
}
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();
}
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);
}
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();
}
Aggregations