### Question:
AisBStaticDataReportPartA extends AbstractAisBStaticDataReport { @VisibleForTesting static Optional<String> extractName(AisExtractor extractor) { String value = extractor.getString(40, 160); if(NAME_NOT_AVAILABLE.contentEquals(value)) { return Optional.absent(); } else { return Optional.of(value); } } AisBStaticDataReportPartA(String message, int padBits);  AisBStaticDataReportPartA(String message, String source, int padBits);  AisBStaticDataReportPartA(AisExtractorFactory factory, String message, String source,
            int padBits); Optional<String> getName(); @Override String toString();  }### Answer:
@Test public void testName() { final String shipName = "Ship name"; AisExtractor ex = createMock(AisExtractor.class); expect(ex.getString(anyInt(), anyInt())).andReturn(shipName).atLeastOnce(); replay(ex); Optional<String> name = AisBStaticDataReportPartA.extractName(ex); assertEquals(shipName, name.get()); verify(ex); }
@Test public void testNameNotAvailable() { final String shipName = "@@@@@@@@@@@@@@@@@@@@"; AisExtractor ex = createMock(AisExtractor.class); expect(ex.getString(anyInt(), anyInt())).andReturn(shipName).atLeastOnce(); replay(ex); Optional<String> name = AisBStaticDataReportPartA.extractName(ex); assertFalse(name.isPresent()); verify(ex); }