NoOpLockedResourceRepository implements LockedResourceRepository { @Override public PersistentPreparation tryLock(String preparationId, String userId, String displayName) { PersistentPreparation preparation = preparationRepository.get(preparationId, PersistentPreparation.class); if (preparation == null) { throw new TDPException(PREPARATION_DOES_NOT_EXIST, build().put("id", preparationId)); } return preparation; } NoOpLockedResourceRepository(); @Override PersistentPreparation tryLock(String preparationId, String userId, String displayName); @Override void unlock(String preparationId, String userId);  }
@Test public void tryLock() { String preparationId = "preparation id"; PersistentPreparation preparationMock = mock(PersistentPreparation.class); when(preparationRepository.get(preparationId, PersistentPreparation.class)).thenReturn(preparationMock); PersistentPreparation preparation = noOpLockedResourceRepository.tryLock(preparationId, "Toto", "toto de Charleville-Mézières"); assertEquals(preparationMock, preparation); verify(preparationRepository).get(preparationId, PersistentPreparation.class); }
@Test public void tryLock_nullPrepThenException() { String preparationId = "preparation id"; when(preparationRepository.get(preparationId, Preparation.class)).thenReturn(null); try { noOpLockedResourceRepository.tryLock(preparationId, "toto", "Toto de Charleville-Mézières"); fail(); } catch (TDPException e) { assertEquals(e.getCode(), PREPARATION_DOES_NOT_EXIST); } verify(preparationRepository).get(preparationId, PersistentPreparation.class); }