public static void assertMapEntryIsUnmodifiable(Entry<?, ?> entry) { try { entry.setValue(null); fail("setValue on unmodifiable Map.Entry succeeded"); } catch (UnsupportedOperationException expected) { } }
/** * Verifies that an Iterator is unmodifiable. * * <p>This test only works with iterators that iterate over a finite set. */ public static void assertIteratorIsUnmodifiable(Iterator<?> iterator) { while (iterator.hasNext()) { iterator.next(); try { iterator.remove(); fail("Remove on unmodifiable iterator succeeded"); } catch (UnsupportedOperationException expected) { } } }
@Override protected void doStop() { fail(); } }
@Override protected void doStop() { fail(); } }
@Override protected void doStop() { fail(); } }
@Override protected void doStop() { fail(); } }
@Override public void onSuccess(String result) { fail("Was not expecting onSuccess() to be called."); }
@Override public int read(char[] cbuf, int off, int len) throws IOException { // if a buffer isn't being cleared correctly, this method will eventually start being called // with a len of 0 forever if (len <= 0) { fail("read called with a len of " + len); } // read fewer than the max number of chars to read // shouldn't be a problem unless the buffer is shrinking each call return in.read(cbuf, off, Math.max(len - 1024, 0)); } };
@Override public void run() { lock.lock(); try { locked.countDown(); finishLatch.await(1, TimeUnit.MINUTES); } catch (InterruptedException e) { fail(e.toString()); } finally { lock.unlock(); } }
@Override public Integer computeNext() { if (alreadyCalledEndOfData) { fail("Should not have been invoked again"); } alreadyCalledEndOfData = true; return endOfData(); } };
@Override public Integer computeNext() { if (haveBeenCalled) { fail("Should not have been called again"); } else { haveBeenCalled = true; sneakyThrow(new SomeCheckedException()); } return null; // never reached } };
@Override public Integer apply(Integer from) { if (++calls > 1) { fail(); } throw new MyRuntimeException(); } };
void check() { try { runTester(); } catch (AssertionFailedError expected) { return; } fail("Should have failed because enum has no constant"); } }
@Override public Integer computeNext() { if (haveBeenCalled) { fail("Should not have been called again"); } else { haveBeenCalled = true; sneakyThrow(new SomeCheckedException()); } return null; // never reached } };
@Override public void run() { try { service.awaitTerminated(); fail("Expected an IllegalStateException"); } catch (Throwable t) { exception.set(t); } } };
@Override public Integer apply(Integer from) { if (++calls > 1) { fail(); } throw new MyError(); } };
@Override public Integer computeNext() { switch (rep++) { case 0: return 0; case 1: return 1; case 2: return endOfData(); default: fail("Should not have been invoked again"); return null; } } };
@Override public Integer computeNext() { switch (rep++) { case 0: return 0; case 1: return 1; case 2: return endOfData(); default: fail("Should not have been invoked again"); return null; } } };
@Override public Integer computeNext() { switch (rep++) { case 0: return 0; case 1: return 1; case 2: return endOfData(); default: fail("Should not have been invoked again"); return null; } } };
void check() { runTester(); NullRejectingFromTo<?, ?> defaultFunction = (NullRejectingFromTo<?, ?>) getDefaultParameterValue(0); assertNotNull(defaultFunction); try { defaultFunction.apply(null); fail("Proxy Should have rejected null"); } catch (NullPointerException expected) { } } }