@Test public void punish() { PunishmentRepository repository = mock(PunishmentRepository.class); PlayerProfileRepository profileRepository = mock(PlayerProfileRepository.class); PunishmentService service = new PunishmentService( repository, profileRepository ); PunishmentParameters parameters = new PunishmentParameters( "target", "punisher", "reason", Duration.of(10, ChronoUnit.HOURS) ); PlayerProfile profile = mock(PlayerProfile.class); when(profileRepository.find(eq(new PlayerNameSpecification("target")))) .thenReturn(Optional.ofNullable(profile)); PunishResult result = service.punish(parameters, PunishmentType.KICK); Assert.assertEquals(PunishResultType.OK, result.getResultType()); assertNotNull(result.getPunishmentRecord()); PunishmentRecord punishmentRecord = result.getPunishmentRecord(); assertSame(profile, punishmentRecord.getTarget()); assertEquals("punisher", punishmentRecord.getPunisher()); Assert.assertEquals(PunishmentType.KICK, punishmentRecord.getPunishmentType()); }
public PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType) { return playerProfileRepository.find(new PlayerNameSpecification(punishmentParameters.getTargetName())) .map(playerProfile -> { PunishmentRecord punishmentRecord = new PunishmentRecord(punishmentParameters.getPunisher(), playerProfile, punishmentParameters.getReason(), punishmentType); punishmentRepository.savePunishment(punishmentRecord); return new PunishResult(punishmentRecord, PunishResultType.OK); }).orElse(PunishResult.NOT_FOUND); }
PunishmentService { public PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType) { return playerProfileRepository.find(new PlayerNameSpecification(punishmentParameters.getTargetName())) .map(playerProfile -> { PunishmentRecord punishmentRecord = new PunishmentRecord(punishmentParameters.getPunisher(), playerProfile, punishmentParameters.getReason(), punishmentType); punishmentRepository.savePunishment(punishmentRecord); return new PunishResult(punishmentRecord, PunishResultType.OK); }).orElse(PunishResult.NOT_FOUND); } }
PunishmentService { public PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType) { return playerProfileRepository.find(new PlayerNameSpecification(punishmentParameters.getTargetName())) .map(playerProfile -> { PunishmentRecord punishmentRecord = new PunishmentRecord(punishmentParameters.getPunisher(), playerProfile, punishmentParameters.getReason(), punishmentType); punishmentRepository.savePunishment(punishmentRecord); return new PunishResult(punishmentRecord, PunishResultType.OK); }).orElse(PunishResult.NOT_FOUND); }  }
PunishmentService { public PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType) { return playerProfileRepository.find(new PlayerNameSpecification(punishmentParameters.getTargetName())) .map(playerProfile -> { PunishmentRecord punishmentRecord = new PunishmentRecord(punishmentParameters.getPunisher(), playerProfile, punishmentParameters.getReason(), punishmentType); punishmentRepository.savePunishment(punishmentRecord); return new PunishResult(punishmentRecord, PunishResultType.OK); }).orElse(PunishResult.NOT_FOUND); }  PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType); }
PunishmentService { public PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType) { return playerProfileRepository.find(new PlayerNameSpecification(punishmentParameters.getTargetName())) .map(playerProfile -> { PunishmentRecord punishmentRecord = new PunishmentRecord(punishmentParameters.getPunisher(), playerProfile, punishmentParameters.getReason(), punishmentType); punishmentRepository.savePunishment(punishmentRecord); return new PunishResult(punishmentRecord, PunishResultType.OK); }).orElse(PunishResult.NOT_FOUND); }  PunishResult punish(PunishmentParameters punishmentParameters, PunishmentType punishmentType);  }