### Question:
DelayFilter implements ISOFilter, Configurable { public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) { evt.addMessage ("<delay-filter delay=\""+delay+"\"/>"); if (delay > 0) { try { Thread.sleep (delay); } catch (InterruptedException e) { } } return m; } DelayFilter();  DelayFilter(int delay); void setConfiguration(Configuration cfg); ISOMsg filter(ISOChannel channel, ISOMsg m, LogEvent evt);  }### Answer:
@Test public void testFilter() throws Throwable { DelayFilter delayFilter = new DelayFilter(0); LogEvent evt = new LogEvent("testDelayFilterTag", "testString"); ISOChannel channel = new CSChannel(new Base1SubFieldPackager(), new ServerSocket()); ISOMsg result = delayFilter.filter(channel, m, evt); assertEquals(2, evt.getPayLoad().size(), "evt.payLoad.size()"); assertEquals("<delay-filter delay=\"0\"/>", evt.getPayLoad().get(1), "evt.payLoad.get(1)"); assertSame(m, result, "result"); }
@Test public void testFilter1() throws Throwable { LogEvent evt = new LogEvent(new BASE24TCPChannel("testDelayFilterHost", 100, new Base1SubFieldPackager()), "testDelayFilterTag", null); ISOMsg result = new DelayFilter(1).filter(new PADChannel(), null, evt); assertEquals(2, evt.getPayLoad().size(), "evt.payLoad.size()"); assertEquals("<delay-filter delay=\"1\"/>", evt.getPayLoad().get(1), "evt.payLoad.get(1)"); assertNull(result, "result"); }
@Test public void testFilter2() throws Throwable { DelayFilter delayFilter = new DelayFilter(-1); ISOChannel channel = new PADChannel(new CTCSubFieldPackager()); LogEvent evt = new LogEvent("testDelayFilterTag", ""); ISOMsg result = delayFilter.filter(channel, m, evt); assertEquals(2, evt.getPayLoad().size(), "evt.payLoad.size()"); assertEquals("<delay-filter delay=\"-1\"/>", evt.getPayLoad().get(1), "evt.payLoad.get(1)"); assertSame(m, result, "result"); }
@Test public void testFilterThrowsNullPointerException() throws Throwable { try { new DelayFilter(0).filter(new NACChannel(), new ISOMsg("testDelayFilterMti"), null); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.util.LogEvent.addMessage(Object)\" because \"evt\" is null", ex.getMessage(), "ex.getMessage()"); } } }