Created
March 24, 2012 13:04
-
-
Save abyx/2182545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void betterTest() throws Exception { | |
// Do some setup | |
// ... | |
final Exchanger<Exception> exchanger = new Exchanger<Exception>(); | |
new Thread() { | |
@Override | |
public void run() { | |
Exception thrown = null; | |
try { | |
int x = 0; | |
// Check a few things that change x | |
// ... | |
assertTrue("An error", x > 3); // This fails! | |
} catch (Exception e) { | |
thrown = e; | |
} | |
try { | |
exchanger.exchange(thrown); | |
} catch (InterruptedException ignored) {} | |
} | |
}.start(); | |
// Wait for other thread | |
Exception exception = exchanger.exchange(null); | |
if (exception != null) { | |
throw exception; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void buggieTest() throws Exception { | |
// Do some setup | |
// ... | |
new Thread() { | |
@Override | |
public void run() { | |
int x = 0; | |
// Check a few things that change x | |
// ... | |
assertTrue("An error", x > 3); // This fails! | |
} | |
}.start(); | |
// Wait for other thread | |
Thread.sleep(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment