use of java.util.Observable in project mockito by mockito.
the class InlineByteBuddyMockMakerTest method is_type_mockable_allows_anonymous.
@Test
public void is_type_mockable_allows_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 android_frameworks_base by DirtyUnicorns.
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);
}
use of java.util.Observable in project intellij-community by JetBrains.
the class SelectCvsElementStep method createComponent.
@Override
protected JComponent createComponent() {
myCvsTree = new CvsTree(myProject, myAllowRootSelection, mySelectionMode, myShowModules, myShowFiles, e -> {
myErrors.set(Boolean.TRUE);
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(e.getMessage(), CvsBundle.message("error.title.cvs.error")), ModalityState.any());
});
myCvsTree.init();
myCvsTree.addSelectionObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
if (CvsTree.SELECTION_CHANGED.equals(arg)) {
getWizard().updateStep();
}
}
});
return myCvsTree;
}
use of java.util.Observable in project robovm by robovm.
the class ObservableTest method test_Constructor.
/**
* java.util.Observable#Observable()
*/
public void test_Constructor() {
// Test for method java.util.Observable()
try {
Observable ov = new Observable();
assertTrue("Wrong initial values.", !ov.hasChanged());
assertEquals("Wrong initial values.", 0, ov.countObservers());
} catch (Exception e) {
fail("Exception during test : " + e.getMessage());
}
}
use of java.util.Observable in project robovm by robovm.
the class ObservableTest method test_addObserverLjava_util_Observer.
/**
* java.util.Observable#addObserver(java.util.Observer)
*/
public void test_addObserverLjava_util_Observer() {
// Test for method void
// java.util.Observable.addObserver(java.util.Observer)
TestObserver test = new TestObserver();
observable.addObserver(test);
assertEquals("Failed to add observer", 1, observable.countObservers());
observable.addObserver(test);
assertEquals("Duplicate observer", 1, observable.countObservers());
Observable o = new Observable();
try {
o.addObserver(null);
fail("Expected adding a null observer to throw a NPE.");
} catch (NullPointerException ex) {
// expected;
} catch (Throwable ex) {
fail("Did not expect adding a new observer to throw a " + ex.getClass().getName());
}
}
Aggregations