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