This is part of JavaUnitTestChallengeSolved -- DonWells
Now I create a test that uses the threads I used in the single-threaded tests to create one with both threads running at the same time.
public class BothThreadsTogether extends Test{ public BoundedBuffer buffer; public PutThread putThread; public TakeThread takeThread; public void setUp(){ buffer = new BoundedBuffer(); putThread = new PutThread(buffer); takeThread = new TakeThread(buffer);} public void runTest (){ TakeThread.resetOutput(); putThread.start(); takeThread.start(); waitForTakeToFinish(); should(TakeThread.doesOuputInclude(0, "a"), "first out should be a"); should(TakeThread.doesOuputInclude(1, "b"), "second out should be b"); should(TakeThread.doesOuputInclude(2, "c"), "third out should be c"); should(TakeThread.doesOuputInclude(3, "d"), "fourth out should be d"); should(TakeThread.doesOuputInclude(4, "e"), "last out should be e");} public void waitForTakeToFinish(){ try { takeThread.join(1000);} catch (InterruptedException exception) {};} }This one runs fine as well.