@Override protected void close(JobContext context) { context.close(); } };
@Test public void testDestructionCallbackMissingAttribute() throws Exception { context.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("bar"); } }); context.close(); // Yes the callback should be called even if the attribute is missing - // for inner beans assertEquals(1, list.size()); }
@Test public void testDestructionCallbackSunnyDay() throws Exception { context.setAttribute("foo", "FOO"); context.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("bar"); } }); context.close(); assertEquals(1, list.size()); assertEquals("bar", list.get(0)); }
@Test public void testRegisterDestructionCallback() { final List<String> list = new ArrayList<>(); context.setAttribute("foo", "bar"); scope.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("foo"); } }); assertEquals(0, list.size()); // When the context is closed, provided the attribute exists the // callback is called... context.close(); assertEquals(1, list.size()); }
@Test public void testRegisterAnotherDestructionCallback() { final List<String> list = new ArrayList<>(); context.setAttribute("foo", "bar"); scope.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("foo"); } }); scope.registerDestructionCallback("foo", new Runnable() { @Override public void run() { list.add("bar"); } }); assertEquals(0, list.size()); // When the context is closed, provided the attribute exists the // callback is called... context.close(); assertEquals(2, list.size()); }
context.close(); fail("Expected RuntimeException");
@Override protected void close(JobContext context) { context.close(); } };
@Override protected void close(JobContext context) { context.close(); } };
@Override protected void close(JobContext context) { context.close(); } };