PersistentFailSanskrit implements Sanskrit { @Override public String getString(String key) throws SanskritException { failCheck(); try { return underlying.getString(key); } catch (Exception e) { failure = e; throw e; } } PersistentFailSanskrit(Sanskrit underlying); @Override void close(); @Override String getString(String key); @Override Long getLong(String key); @Override SanskritObject getObject(String key); @Override void applyChange(SanskritChange change); @Override MutableSanskritObject newMutableSanskritObject(); @Override void reset();  }
@Test public void readFromUnderlying() throws Exception { when(underlying.getString("A")).thenReturn("a"); PersistentFailSanskrit sanskrit = new PersistentFailSanskrit(underlying); assertEquals("a", sanskrit.getString("A")); }
@Test(expected = SanskritException.class) public void failOnceFailAgain() throws Exception { when(underlying.getString("A")).thenThrow(SanskritException.class).thenReturn("a"); PersistentFailSanskrit sanskrit = new PersistentFailSanskrit(underlying); try { sanskrit.getString("A"); fail("Expected exception"); } catch (SanskritException e) { } sanskrit.getString("A"); }