### Question:
RestrictionsMergeOperation { public Optional<TypedRestrictions> applyMergeOperation(TypedRestrictions left, TypedRestrictions right, boolean useFinestGranularityAvailable) { return getMerger(left).merge(left, right, useFinestGranularityAvailable); } RestrictionsMergeOperation(LinearRestrictionsMerger linearMerger, StringRestrictionsMerger stringMerger, BooleanRestrictionsMerger booleanMerger); Optional<TypedRestrictions> applyMergeOperation(TypedRestrictions left, TypedRestrictions right, boolean useFinestGranularityAvailable);  }### Answer:
@Test void applyMergeOperation_withNumericRestrictions_shouldApplyRestriction(){ Optional<TypedRestrictions> expected = Optional.of(rightNumeric); when(linearMerger.merge(leftNumeric, rightNumeric, false)) .thenReturn(Optional.of(rightNumeric)); Optional<TypedRestrictions> result = operation.applyMergeOperation(leftNumeric, rightNumeric, false); Assert.assertEquals(expected, result); verify(linearMerger, times(1)).merge(any(), any(), anyBoolean()); verify(stringMerger, times(0)).merge(any(), any(), anyBoolean()); }
@Test void applyMergeOperation_withContradictoryNumericRestrictions_shouldPreventAnyValues(){ Optional<TypedRestrictions> expected = Optional.empty(); when(linearMerger.merge(leftNumeric, rightNumeric, false)) .thenReturn(Optional.empty()); Optional<TypedRestrictions> result = operation.applyMergeOperation(leftNumeric, rightNumeric, false); Assert.assertEquals(expected, result); verify(linearMerger, times(1)).merge(any(), any(), anyBoolean()); verify(stringMerger, times(0)).merge(any(), any(), anyBoolean()); }
@Test void applyMergeOperation_withStringRestrictions_shouldApplyRestriction(){ Optional<TypedRestrictions> expected = Optional.of(leftString); when(stringMerger.merge((StringRestrictions)leftString, (StringRestrictions)rightString, false)) .thenReturn(Optional.of((StringRestrictions)leftString)); Optional<TypedRestrictions> result = operation.applyMergeOperation(leftString, rightString, false); Assert.assertEquals(expected, result); verify(linearMerger, times(0)).merge(any(), any(), anyBoolean()); verify(stringMerger, times(1)).merge(any(), any(), anyBoolean()); }
@Test void applyMergeOperation_withContradictoryStringRestrictions_shouldPreventAnyValues(){ Optional<TypedRestrictions> expected = Optional.empty(); when(stringMerger.merge((StringRestrictions)leftString, (StringRestrictions)rightString, false)) .thenReturn(Optional.empty()); Optional<TypedRestrictions> result = operation.applyMergeOperation(leftString, rightString, false); Assert.assertEquals(expected, result); verify(linearMerger, times(0)).merge(any(), any(), anyBoolean()); verify(stringMerger, times(1)).merge(any(), any(), anyBoolean()); }
@Test void applyMergeOperation_withDateTimeRestrictions_shouldApplyRestriction(){ Optional<TypedRestrictions> expected = Optional.of(rightDateTime); when(linearMerger.merge(leftDateTime, rightDateTime, false)) .thenReturn(Optional.of(rightDateTime)); Optional<TypedRestrictions> result = operation.applyMergeOperation(leftDateTime, rightDateTime, false); Assert.assertEquals(result, result); verify(linearMerger, times(1)).merge(any(), any(), anyBoolean()); verify(stringMerger, times(0)).merge(any(), any(), anyBoolean()); }
@Test void applyMergeOperation_withContradictoryDateTimeRestrictions_shouldPreventAnyValues(){ Optional<TypedRestrictions> expected = Optional.empty(); when(linearMerger.merge(leftDateTime, rightDateTime, false)) .thenReturn(Optional.empty()); Optional<TypedRestrictions> result = operation.applyMergeOperation(leftDateTime, rightDateTime, false); Assert.assertEquals(expected, result); verify(linearMerger, times(1)).merge(any(), any(), anyBoolean()); verify(stringMerger, times(0)).merge(any(), any(), anyBoolean()); }