### Question:
RowSpecMerger { public Optional<RowSpec> merge(RowSpec left, RowSpec right) { Map<Field, FieldSpec> newMap = new HashMap<>(); for (Field field : left.getFields()) { Optional<FieldSpec> merge = fieldSpecMerger.merge(left.getSpecForField(field), right.getSpecForField(field), false); if (!merge.isPresent()){ return Optional.empty(); } newMap.put(field, merge.get()); } List<FieldSpecRelation> relations = new ArrayList<>( SetUtils.union(left.getRelations(), right.getRelations())); return Optional.of(new RowSpec(left.getFields(), newMap, relations)); } @Inject  RowSpecMerger(FieldSpecMerger fieldSpecMerger); Optional<RowSpec> merge(RowSpec left, RowSpec right);  }### Answer:
@Test void merge_notContradictoryForField() { RowSpec left = new RowSpec(fields, ImmutableMap.of(A, isNull), Collections.emptyList()); RowSpec right = new RowSpec(fields, ImmutableMap.of(A, isNull), Collections.emptyList()); RowSpec merged = rowSpecMerger.merge(left, right).get(); assertEquals(merged.getSpecForField(A), isNull); }
@Test void merge_contradictoryForField() { RowSpec left = new RowSpec(fields, ImmutableMap.of(A, isNull), Collections.emptyList()); RowSpec right = new RowSpec(fields, ImmutableMap.of(A, notNull), Collections.emptyList()); Optional<RowSpec> merged = rowSpecMerger.merge(left, right); assertEquals(merged, Optional.empty()); }
@Test void merge_twoFields() { RowSpec left = new RowSpec(fields, ImmutableMap.of(A, isNull), Collections.emptyList()); RowSpec right = new RowSpec(fields, ImmutableMap.of(B, notNull), Collections.emptyList()); RowSpec merged = rowSpecMerger.merge(left, right).get(); assertEquals(merged.getSpecForField(A), (isNull)); assertEquals(merged.getSpecForField(B), (notNull)); }