### Question:
OccurrenceExtensionTransform extends DoFn<ExtendedRecord, ExtendedRecord> { public static SingleOutput<ExtendedRecord, ExtendedRecord> create() { return ParDo.of(new OccurrenceExtensionTransform()); }  static SingleOutput<ExtendedRecord, ExtendedRecord> create(); void setCounterFn(SerializableConsumer<String> counterFn); @ProcessElement void processElement(@Element ExtendedRecord er, OutputReceiver<ExtendedRecord> out); void convert(ExtendedRecord er, Consumer<ExtendedRecord> resultConsumer);  }### Answer:
@Test public void extensionContainsOccurrenceTest() { String id = "1"; String somethingCore = "somethingCore"; String somethingExt = "somethingExt"; Map<String, String> ext1 = new HashMap<>(2); ext1.put(DwcTerm.occurrenceID.qualifiedName(), id); ext1.put(somethingExt, somethingExt); Map<String, String> ext2 = new HashMap<>(2); ext2.put(DwcTerm.occurrenceID.qualifiedName(), id); ext2.put(somethingExt, somethingExt); Map<String, String> ext3 = new HashMap<>(2); ext3.put(DwcTerm.occurrenceID.qualifiedName(), id); ext3.put(somethingExt, somethingExt); ExtendedRecord er = ExtendedRecord.newBuilder() .setId(id) .setCoreTerms(Collections.singletonMap(somethingCore, somethingCore)) .setExtensions( Collections.singletonMap( Occurrence.qualifiedName(), Arrays.asList(ext1, ext2, ext3))) .build(); final List<ExtendedRecord> expected = createCollection( false, false, id + "_" + somethingCore + "_" + somethingExt, id + "_" + somethingCore + "_" + somethingExt, id + "_" + somethingCore + "_" + somethingExt); PCollection<ExtendedRecord> result = p.apply(Create.of(er)).apply(OccurrenceExtensionTransform.create()); PAssert.that(result).containsInAnyOrder(expected); p.run(); }
@Test public void occurrenceExtensionIsEmptyTest() { String id = "1"; String somethingCore = "somethingCore"; Map<String, String> ext = new HashMap<>(2); ext.put(DwcTerm.occurrenceID.qualifiedName(), id); ext.put(somethingCore, somethingCore); ExtendedRecord er = ExtendedRecord.newBuilder() .setId(id) .setCoreTerms(ext) .setExtensions( Collections.singletonMap(Occurrence.qualifiedName(), Collections.emptyList())) .build(); final List<ExtendedRecord> expected = createCollection(true, false, id + "_" + somethingCore); PCollection<ExtendedRecord> result = p.apply(Create.of(er)).apply(OccurrenceExtensionTransform.create()); PAssert.that(result).containsInAnyOrder(expected); p.run(); }
@Test public void noOccurrenceExtensionTest() { String id = "1"; String somethingCore = "somethingCore"; Map<String, String> ext = new HashMap<>(2); ext.put(DwcTerm.occurrenceID.qualifiedName(), id); ext.put(somethingCore, somethingCore); ExtendedRecord er = ExtendedRecord.newBuilder().setId(id).setCoreTerms(ext).build(); final List<ExtendedRecord> expected = createCollection(false, false, id + "_" + somethingCore); PCollection<ExtendedRecord> result = p.apply(Create.of(er)).apply(OccurrenceExtensionTransform.create()); PAssert.that(result).containsInAnyOrder(expected); p.run(); }