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