PayloadSizeExtractor implements Function<JAXBElement<? extends IdentifiableType>, Optional<String>> { @Override public Optional<String> apply(JAXBElement<? extends IdentifiableType> jaxbElement) { Optional<String> payloadSize = Optional.absent(); IdentifiableType value = jaxbElement.getValue(); if (value instanceof ExtrinsicObjectType) { ExtrinsicObjectType extrinsicObjectType = (ExtrinsicObjectType) value; payloadSize = JaxbDocumentUtils.findSlotType(extrinsicObjectType.getSlot(), DocumentConstants.EBXML_RESPONSE_SIZE_SLOTNAME); } else { LOG.warn("Passed in element has an unexpected type. Expecting ExtrinsicObjectType. Returning as absent."); } return payloadSize; }  @Override Optional<String> apply(JAXBElement<? extends IdentifiableType> jaxbElement);  }
@Test public void extract() { ExtrinsicObjectType extrinsicObject = createExtrinsicObject("size", "value"); JAXBElement<ExtrinsicObjectType> jaxbWrapper = wrapExtrinsicObject(extrinsicObject); PayloadSizeExtractor extractor = new PayloadSizeExtractor(); Optional<String> payloadSize = extractor.apply(jaxbWrapper); assertEquals("value", payloadSize.get()); }
@Test public void absent() { ExtrinsicObjectType extrinsicObject = createExtrinsicObject("test", "value"); JAXBElement<ExtrinsicObjectType> jaxbWrapper = wrapExtrinsicObject(extrinsicObject); PayloadSizeExtractor extractor = new PayloadSizeExtractor(); Optional<String> payloadSize = extractor.apply(jaxbWrapper); assertFalse(payloadSize.isPresent()); }