JaxbDocumentUtils { public static Optional<String> findSlotType(List<SlotType1> slotList, final String expectedType) { Predicate<SlotType1> slotPredicate = new Predicate<SlotType1>() { @Override public boolean apply(SlotType1 slot) { return slot != null && expectedType.equals(slot.getName()) && slot.getValueList() != null && !slot.getValueList().getValue().isEmpty(); } }; Optional<SlotType1> slot = Iterables.tryFind(slotList, slotPredicate); if (!slot.isPresent()) { return Optional.absent(); } return Optional.of(slot.get().getValueList().getValue().get(0)); } private  JaxbDocumentUtils(); static Optional<String> findSlotType(List<SlotType1> slotList, final String expectedType);  }
@Test public void emptyEmptyList() { List<SlotType1> list = createList(); Optional<String> result = JaxbDocumentUtils.findSlotType(list, "expected"); assertEquals(Optional.absent(), result); }
@Test public void emptyValueList() { List<SlotType1> list = createList(); list.get(0).setValueList(new ValueListType()); Optional<String> result = JaxbDocumentUtils.findSlotType(list, "expected"); assertEquals(Optional.absent(), result); }
@Test public void realValueExpected() { List<SlotType1> list = createList(); ValueListType valueList = new ValueListType(); list.get(0).setValueList(valueList); valueList.getValue().add("value"); Optional<String> result = JaxbDocumentUtils.findSlotType(list, "expected"); assertEquals(result.get(), "value"); }