### Question:
ControlFieldExpression implements Expression<String, Record> { @Override public String evaluate(final Record target) { return currentState.evaluate(target); } ControlFieldExpression(final String specs); @Override String evaluate(final Record target); @Override String specs();  }### Answer:
@Test public void incompatibleControlFieldLength() { int endIndex = A_CONTROL_FIELD_VALUE.length() + 10; final Record record = newRecord(A_CONTROL_FIELD_NAME, A_CONTROL_FIELD_VALUE); final String [] expressions = { A_CONTROL_FIELD_NAME + "[00-" + endIndex + "]", A_CONTROL_FIELD_NAME + " [ 00 - " + endIndex + " ]", A_CONTROL_FIELD_NAME + " [ 00 - " + endIndex + " ]"}; for (final String specs : expressions) { final ControlFieldExpression expression = new ControlFieldExpression(specs); assertNull(expression.evaluate(record)); } }
@Test public void fullSelectorWithNoTargetField() { final Record record = newRecord(null, null); final ControlFieldExpression expression = new ControlFieldExpression(A_CONTROL_FIELD_NAME); assertNull(expression.evaluate(record)); }
@Test public void partialSelectorWithNoTargetField() { final Record record = newRecord(null, null); final ControlFieldExpression expression = new ControlFieldExpression(A_CONTROL_FIELD_NAME + "[00-05]"); assertNull(expression.evaluate(record)); }
@Test public void fullSelector() { final Record record = newRecord(A_CONTROL_FIELD_NAME, A_CONTROL_FIELD_VALUE); final ControlFieldExpression expression = new ControlFieldExpression(A_CONTROL_FIELD_NAME); assertEquals(A_CONTROL_FIELD_VALUE, expression.evaluate(record)); }
@Test public void partialSelector() { int startIndex = 0; int endIndex = 5; final String expectedValue = A_CONTROL_FIELD_VALUE.substring(startIndex, endIndex + 1); final Record record = newRecord(A_CONTROL_FIELD_NAME, A_CONTROL_FIELD_VALUE); final String [] expressions = { A_CONTROL_FIELD_NAME + "[00-" + endIndex + "]", A_CONTROL_FIELD_NAME + " [ 00 - " + endIndex + " ]", A_CONTROL_FIELD_NAME + " [ 00 - " + endIndex + " ]"}; for (final String specs : expressions) { final ControlFieldExpression expression = new ControlFieldExpression(specs); assertEquals(expectedValue, expression.evaluate(record)); } }