### Question:
PriorityServiceImpl implements PriorityService { @Override public Comparator<Entity> getEntityPriorityComparator() { return entityPriorityComparator; }  @Override void prioritizeEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity); @Override void deprioritizeEntity(final InternalDataDefinition dataDefinition, final Object databaseEntity); @Override void move(final InternalDataDefinition dataDefinition, final Object databaseEntity, final int position,
            final int offset); @Override Comparator<Entity> getEntityPriorityComparator();  }### Answer:
@Test public final void shouldComparatorFindPriorityFieldAndCompareEntities() throws Exception { final String priorityFieldName = "priority123field"; Comparator<Entity> entityPriorityComparator = priorityServiceImpl.getEntityPriorityComparator(); mockPriorityFieldDefinition(firstEntity, priorityFieldName); mockPriorityFieldDefinition(secondEntity, priorityFieldName); given(firstEntity.getField(priorityFieldName)).willReturn(1); given(secondEntity.getField(priorityFieldName)).willReturn(2); int comparationResult = entityPriorityComparator.compare(firstEntity, secondEntity); verify(firstEntity).getField(priorityFieldName); verify(secondEntity).getField(priorityFieldName); Assert.assertEquals(-1, comparationResult); }
@Test public final void shouldThrowExceptionIfEntityDoNotHavePriorityFields() throws Exception { Comparator<Entity> entityPriorityComparator = priorityServiceImpl.getEntityPriorityComparator(); DataDefinition dataDefinition = mock(DataDefinition.class); given(firstEntity.getDataDefinition()).willReturn(dataDefinition); given(secondEntity.getDataDefinition()).willReturn(dataDefinition); given(dataDefinition.getPriorityField()).willReturn(null); boolean success = false; try { entityPriorityComparator.compare(firstEntity, secondEntity); } catch (NullPointerException e) { success = true; } Assert.assertTrue(success); }