### Question:
StatefulFilter implements ISOFilter, Configurable { public ISOMsg filter(ISOChannel iSOChannel, ISOMsg m, LogEvent evt) throws ISOFilter.VetoException { int[] key = getKey(); String keyPrefix = getKeyPrefix(); if (keyPrefix == null) throw new NullPointerException("key prefix can not be null"); StringBuilder b = new StringBuilder(keyPrefix); for (int aKey : key) { b.append("|"); b.append(m.getString(aKey)); } String skey = b.toString(); if(m.getDirection() == getMatchDirection()){ int[] savedFields = getSavedFields(); ISOMsg saved = (ISOMsg)( savedFields != null && savedFields.length != 0 ? m.clone(savedFields) : m.clone()); int[] ignoredFields = getIgnoredFields(); if (ignoredFields != null) saved.unset(ignoredFields); getSpace().out(skey, saved, getTimeout()); return m; } else { ISOMsg saved = (ISOMsg)getSpace().inp(skey); if (saved == null && isVetoUnmatched()) throw new VetoException("unmatched iso message"); else if(saved != null) { if (!isOverwriteOriginalFields()) m.merge(saved); else { saved.merge(m); m = saved; } } return m; } } StatefulFilter(); String getKeyPrefix(); void setKeyPrefix(String keyPrefix); void setConfiguration(Configuration cfg); void setSpace(String uri); ISOMsg filter(ISOChannel iSOChannel, ISOMsg m, LogEvent evt); boolean isVetoUnmatched(); void setVetoUnmatched(boolean vetoUnmatched); int getMatchDirection(); void setMatchDirection(int matchDirection); int getIgnoredField(int index); int[] getIgnoredFields(); void setIgnoredField(int index, int ignoredFields); void setIgnoredFields(int[] ignoredFields); int getSavedField(int index); int[] getSavedFields(); void setSavedField(int index, int savedFields); void setSavedFields(int[] savedFields); int getKey(int index); int[] getKey(); void setKey(int index, int key); void setKey(int[] key); long getTimeout(); void setTimeout(long timeout); boolean isOverwriteOriginalFields(); void setOverwriteOriginalFields(boolean overwriteOriginalFields);  }### Answer:
@Test public void testFilter() throws Throwable { int[] key = new int[0]; StatefulFilter statefulFilter = new StatefulFilter(); statefulFilter.setKey(key); statefulFilter.setMatchDirection(61); statefulFilter.setIgnoredFields(null); ISOMsg m = new ISOMsg("testStatefulFilterMti"); m.setDirection(61); ISOMsg result = statefulFilter.filter(null, m, null); assertSame(m, result, "result"); }
@Test public void testFilter1() throws Throwable { ISOMsg m = new ISOMsg("testStatefulFilterMti"); m.setDirection(1); ISOMsg result = new StatefulFilter().filter(new NACChannel(), m, new LogEvent()); assertSame(m, result, "result"); }
@Test public void testFilter5() throws Throwable { StatefulFilter statefulFilter = new StatefulFilter(); BASE24TCPChannel iSOChannel = mock(BASE24TCPChannel.class); LogEvent evt = mock(LogEvent.class); ISOMsg m = mock(ISOMsg.class); given(m.getString(11)).willReturn(null); given(m.getString(41)).willReturn(null); given(m.getDirection()).willReturn(0); ISOMsg result = statefulFilter.filter(iSOChannel, m, evt); assertSame(m, result, "result"); }