### Question:
ControlFieldExpression implements Expression<String, Document> { @Override public String evaluate(final Document target) { final String result = currentState.evaluate(target); return result != null && result.trim().length() > 0 ? result : null; } ControlFieldExpression(final String specs); @Override String evaluate(final Document target); @Override String specs(); @Override String toString();  }### Answer:
@Test public void fullSelector() { final Document document = newRecord(A_CONTROL_FIELD_NAME, A_CONTROL_FIELD_VALUE); final ControlFieldExpression expression = new ControlFieldExpression(A_CONTROL_FIELD_NAME); expression.xpath = new OXPath(); assertEquals(A_CONTROL_FIELD_VALUE, expression.evaluate(document)); }
@Test public void partialSelector() { int startIndex = 0; int endIndex = 5; final String expectedValue = A_CONTROL_FIELD_VALUE.substring(startIndex, endIndex + 1); final Document document = 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); expression.xpath = new OXPath(); assertEquals(expectedValue, expression.evaluate(document)); } }
@Test public void incompatibleControlFieldLength() { int endIndex = A_CONTROL_FIELD_VALUE.length() + 10; final Document document = 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); expression.xpath = new OXPath(); assertNull(expression.evaluate(document)); } }
@Test public void fullSelectorWithNoTargetField() { final Document document = newRecord(null, null); final ControlFieldExpression expression = new ControlFieldExpression(A_CONTROL_FIELD_NAME); expression.xpath = new OXPath(); assertNull(expression.evaluate(document)); }
@Test public void partialSelectorWithNoTargetField() { final Document document = newRecord(null, null); final ControlFieldExpression expression = new ControlFieldExpression(A_CONTROL_FIELD_NAME + "[00-05]"); expression.xpath = new OXPath(); assertNull(expression.evaluate(document)); }