@Test public void testEnqueue() { final String[] putSomethingHere = new String[] {null}; final String something = "Something"; Runnable myRunnable = new Runnable() { public void run() { synchronized (this) { putSomethingHere[0] = something; this.notify(); } } }; try { RunnableQueue.enqueue(myRunnable); synchronized (myRunnable) { while (putSomethingHere[0] == null) { myRunnable.wait(); } } } catch (InterruptedException e) { throw new AssertionError("Thread unexpectedly interrupted during enqueue"); } assertEquals(putSomethingHere[0], something); }
@Test public void testExceptionProof() { Runnable myRunnable = new Runnable() { public void run() { int[] a = new int[] {1, 2, 3}; @SuppressWarnings("unused") int b = a[a.length]; } }; try { RunnableQueue.enqueue(myRunnable); } catch (InterruptedException e) { throw new AssertionError("Thread unexpectedly interrupted during enqueue"); } testEnqueue(); }