### Question:
NewIsTheBestMergeBehaviourImpl implements MergeBehaviour<SyncObject> { @Override public MergeResult<SyncObject> resolveDiff(Class<? extends SyncObject> clazz, SyncObject local, SyncObject foreign) { return resolveConflict(local, foreign); }  @Override MergeResult<SyncObject> resolveDiff(Class<? extends SyncObject> clazz, SyncObject local, SyncObject foreign);  }### Answer:
@Test public void resolveDiff_shouldReturnSuccessIfDateChangedNotExitAndChooseTheLocal() { SyncObject localObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged (null, false, false)); SyncObject foreignObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( null, false, false)); MergeResult actual = newIsTheBestMergeBehaviour.resolveDiff(SyncObject.class, localObj, foreignObj); Assert.assertTrue(actual instanceof MergeSuccess); Assert.assertEquals(MergeMessageEnum.LOCAL_SAVE_MESSAGE, actual.getMessage()); Assert.assertTrue(((MergeSuccess) actual).shouldUpdateLocal()); Assert.assertFalse(((MergeSuccess) actual).shouldUpdateForeign()); }
@Test public void resolveDiff_shouldReturnSuccessIfOnlyLocalHasDateChanged() { SyncObject localObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( LATER_DATE, true, false)); SyncObject foreignObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( null, false, false)); MergeResult actual = newIsTheBestMergeBehaviour.resolveDiff(SyncObject.class, localObj, foreignObj); Assert.assertTrue(actual instanceof MergeSuccess); Assert.assertEquals(MergeMessageEnum.LOCAL_SAVE_MESSAGE, actual.getMessage()); Assert.assertTrue(((MergeSuccess) actual).shouldUpdateLocal()); Assert.assertFalse(((MergeSuccess) actual).shouldUpdateForeign()); }
@Test public void resolveDiff_shouldReturnSuccessAndChooseTheNewest() { SyncObject localObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( LATER_DATE, true, false)); SyncObject foreignObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( EARLIER_DATE, true, false)); MergeResult actual = newIsTheBestMergeBehaviour.resolveDiff(SyncObject.class, localObj, foreignObj); Assert.assertTrue(actual instanceof MergeSuccess); Assert.assertEquals(MergeMessageEnum.LOCAL_SAVE_MESSAGE, actual.getMessage()); Assert.assertTrue(((MergeSuccess) actual).shouldUpdateLocal()); Assert.assertFalse(((MergeSuccess) actual).shouldUpdateForeign()); }
@Test public void resolveDiff_shouldReturnSuccessAndChooseLocalIfDatesAreTheSame() { SyncObject localObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( EARLIER_DATE, true, false)); SyncObject foreignObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( EARLIER_DATE, true, false)); MergeResult actual = newIsTheBestMergeBehaviour.resolveDiff(SyncObject.class, localObj, foreignObj); Assert.assertTrue(actual instanceof MergeSuccess); Assert.assertEquals(MergeMessageEnum.LOCAL_SAVE_MESSAGE, actual.getMessage()); Assert.assertTrue(((MergeSuccess) actual).shouldUpdateLocal()); Assert.assertFalse(((MergeSuccess) actual).shouldUpdateForeign()); }
@Test public void resolveDiff_shouldReturnMergeConflictIfInvalidDateFormat() { SyncObject localObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( EARLIER_DATE, true, false)); SyncObject foreignObj = getSyncObject(SimpleObjectMother.createInstanceWithDateChanged( INVALID_DATE, true, false)); MergeResult actual = newIsTheBestMergeBehaviour.resolveDiff(SyncObject.class, localObj, foreignObj); Assert.assertTrue(actual instanceof MergeConflict); Assert.assertEquals(MergeMessageEnum.CONFLICT, actual.getMessage()); }