### Question:
StudentRepository implements IUnitOfWork<Student> { @Override public void commit() { if (context == null || context.size() == 0) { return; } LOGGER.info("Commit started"); if (context.containsKey(UnitActions.INSERT.getActionValue())) { commitInsert(); } if (context.containsKey(UnitActions.MODIFY.getActionValue())) { commitModify(); } if (context.containsKey(UnitActions.DELETE.getActionValue())) { commitDelete(); } LOGGER.info("Commit finished."); } StudentRepository(Map<String, List<Student>> context, StudentDatabase studentDatabase); @Override void registerNew(Student student); @Override void registerModified(Student student); @Override void registerDeleted(Student student); @Override void commit();  }### Answer:
@Test public void shouldSaveAllLocalChangesToDb() { context.put(UnitActions.INSERT.getActionValue(), List.of(student1)); context.put(UnitActions.MODIFY.getActionValue(), List.of(student1)); context.put(UnitActions.DELETE.getActionValue(), List.of(student1)); studentRepository.commit(); verify(studentDatabase, times(1)).insert(student1); verify(studentDatabase, times(1)).modify(student1); verify(studentDatabase, times(1)).delete(student1); }
@Test public void shouldNotWriteToDbIfContextIsNull() { var studentRepository = new StudentRepository(null, studentDatabase); studentRepository.commit(); verifyNoMoreInteractions(studentDatabase); }
@Test public void shouldNotWriteToDbIfNothingToCommit() { var studentRepository = new StudentRepository(new HashMap<>(), studentDatabase); studentRepository.commit(); verifyZeroInteractions(studentDatabase); }
@Test public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() { context.put(UnitActions.MODIFY.getActionValue(), List.of(student1)); context.put(UnitActions.DELETE.getActionValue(), List.of(student1)); studentRepository.commit(); verify(studentDatabase, never()).insert(student1); }
@Test public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() { context.put(UnitActions.INSERT.getActionValue(), List.of(student1)); context.put(UnitActions.DELETE.getActionValue(), List.of(student1)); studentRepository.commit(); verify(studentDatabase, never()).modify(student1); }
@Test public void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() { context.put(UnitActions.INSERT.getActionValue(), List.of(student1)); context.put(UnitActions.MODIFY.getActionValue(), List.of(student1)); studentRepository.commit(); verify(studentDatabase, never()).delete(student1); }