ReferenceToPicOutConverter implements Serializable { public Tuple2<String, PicOut> convertToPicOut(Tuple2<String, Iterable<Reference>> srcDocIdReferences) { Preconditions.checkNotNull(srcDocIdReferences); Preconditions.checkNotNull(srcDocIdReferences._1()); Preconditions.checkNotNull(srcDocIdReferences._2()); String srcDocId = srcDocIdReferences._1(); PicOut.Builder picOutB = PicOut.newBuilder(); picOutB.setDocId(srcDocId); for (Reference reference : srcDocIdReferences._2()) { picOutB.addRefs(reference); } return new Tuple2<>(srcDocId, picOutB.build()); }  Tuple2<String, PicOut> convertToPicOut(Tuple2<String, Iterable<Reference>> srcDocIdReferences);  }
@Test(expectedExceptions=NullPointerException.class) public void convertToPicOut_Null_srcDocIdReferences() { referenceToPicOutConverter.convertToPicOut(null); }
@Test(expectedExceptions=NullPointerException.class) public void convertToPicOut_Null_srcDocId() { Reference ref1 = createReference(1, "X"); List<Reference> refs = Lists.newArrayList(ref1); Tuple2<String, Iterable<Reference>> srcDocIdReferences = new Tuple2<>(null, refs); referenceToPicOutConverter.convertToPicOut(srcDocIdReferences); }
@Test(expectedExceptions=NullPointerException.class) public void convertToPicOut_Null_refs() { Tuple2<String, Iterable<Reference>> srcDocIdReferences = new Tuple2<>("XYZ", null); referenceToPicOutConverter.convertToPicOut(srcDocIdReferences); }
@Test public void convertToPicOut() { Reference ref1 = createReference(1, "X"); Reference ref2 = createReference(2, "C"); Reference ref3 = createReference(3, "Z"); List<Reference> refs = Lists.newArrayList(ref1, ref2, ref3); Tuple2<String, Iterable<Reference>> srcDocIdReferences = new Tuple2<>("XYZ", refs); Tuple2<String, PicOut> srcDocIdPicOut = referenceToPicOutConverter.convertToPicOut(srcDocIdReferences); assertEquals(srcDocIdPicOut._1(), "XYZ"); assertEquals(srcDocIdPicOut._2().getDocId(), "XYZ"); assertEquals(srcDocIdPicOut._2().getRefsCount(), refs.size()); assertTrue(srcDocIdPicOut._2().getRefs(0) == ref1); assertTrue(srcDocIdPicOut._2().getRefs(1) == ref2); assertTrue(srcDocIdPicOut._2().getRefs(2) == ref3); }