assertEquals("Joe Walnes:XStream", converter.toString(software));
assertEquals(software, converter.fromString("Joe Walnes:XStream"));
}
public void testConcurrentConversion() throws InterruptedException {
final SingleValueConverter converter = new PropertyEditorCapableConverter(
SoftwarePropertyEditor.class, Software.class);
final Map exceptions = new HashMap();
final ThreadGroup tg = new ThreadGroup(getName()) {
public void uncaughtException(Thread t, Throwable e) {
exceptions.put(e, t.getName());
super.uncaughtException(t, e);
}
};
final Map references = new HashMap();
final int[] counter = new int[1];
counter[0] = 0;
final Thread[] threads = new Thread[10];
for (int i = 0; i < threads.length; ++i) {
final String name = "JUnit Thread:" + i;
references.put(name, new Software("JUnit Thread", Integer.toString(i)));
threads[i] = new Thread(tg, name) {
public void run() {
int i = 0;
try {
synchronized (this) {
notifyAll();
wait();
}
final Software software = (Software)references.get(Thread
.currentThread()
.getName());
while (i < 1000 && !interrupted()) {
String formatted = converter.toString(software);
Thread.yield();
assertEquals(software, converter.fromString(formatted));
++i;
}
} catch (InterruptedException e) {
fail("Unexpected InterruptedException");
}