private T readFromDelegate() throws Exception { T item = delegate.read(); if(item instanceof ResourceAware){ ((ResourceAware) item).setResource(getCurrentResource()); } return item; }
@Test public void testGetCurrentResourceBeforeRead() throws Exception { tested.open(ctx); assertNull("There is no 'current' resource before read is called", tested.getCurrentResource()); }
@Test public void testGetCurrentResource() throws Exception { tested.open(ctx); assertEquals("1", tested.read()); assertSame(r1, tested.getCurrentResource()); assertEquals("2", tested.read()); assertSame(r1, tested.getCurrentResource()); assertEquals("3", tested.read()); assertSame(r1, tested.getCurrentResource()); assertEquals("4", tested.read()); assertSame(r2, tested.getCurrentResource()); assertEquals("5", tested.read()); assertSame(r2, tested.getCurrentResource()); assertEquals("6", tested.read()); assertSame(r4, tested.getCurrentResource()); assertEquals("7", tested.read()); assertSame(r5, tested.getCurrentResource()); assertEquals("8", tested.read()); assertSame(r5, tested.getCurrentResource()); assertEquals(null, tested.read()); assertSame(null, tested.getCurrentResource()); tested.close(); }
private T readFromDelegate() throws Exception { T item = delegate.read(); if(item instanceof ResourceAware){ ((ResourceAware) item).setResource(getCurrentResource()); } return item; }