@Test public void findOneAndEnrich_Found() { when(judgmentRepository.findOneAndInitialize(judgment.getId())).thenReturn(judgment); EnrichmentTag enrichmentTag1 = new EnrichmentTag(); enrichmentTag1.setTagType("TAG_TYPE_1"); when(enrichmentTagRepository.findAllByJudgmentId(judgment.getId())).thenReturn(Lists.newArrayList(enrichmentTag1)); EnrichmentTagApplier enrichmentTagApplier1 = mock(EnrichmentTagApplier.class); when(enrichmentTagApplierManager.getEnrichmentTagApplier(enrichmentTag1.getTagType())).thenReturn(enrichmentTagApplier1); Judgment enrichedJudgment = judgmentEnrichmentService.findOneAndEnrich(judgment.getId()); assertNotNull(enrichedJudgment); assertTrue(enrichedJudgment == judgment); verify(judgmentRepository).findOneAndInitialize(judgment.getId()); verify(enrichmentTagApplierManager).getEnrichmentTagApplier(enrichmentTag1.getTagType()); verify(enrichmentTagApplier1).applyEnrichmentTag(judgment, enrichmentTag1); verify(entityManager).detach(judgment); }
public <T extends Judgment> T findOneAndEnrich(long judgmentId) { T judgment = judgmentRepository.findOneAndInitialize(judgmentId); if (judgment == null) { return null; } entityManager.detach(judgment); enrich(judgment); return judgment; }
JudgmentEnrichmentService { public <T extends Judgment> T findOneAndEnrich(long judgmentId) { T judgment = judgmentRepository.findOneAndInitialize(judgmentId); if (judgment == null) { return null; } entityManager.detach(judgment); enrich(judgment); return judgment; } }
JudgmentEnrichmentService { public <T extends Judgment> T findOneAndEnrich(long judgmentId) { T judgment = judgmentRepository.findOneAndInitialize(judgmentId); if (judgment == null) { return null; } entityManager.detach(judgment); enrich(judgment); return judgment; }  }
JudgmentEnrichmentService { public <T extends Judgment> T findOneAndEnrich(long judgmentId) { T judgment = judgmentRepository.findOneAndInitialize(judgmentId); if (judgment == null) { return null; } entityManager.detach(judgment); enrich(judgment); return judgment; }  T findOneAndEnrich(long judgmentId); void unenrichAndSave(Judgment judgment); void enrich(T judgment); void enrich(T judgment, List<EnrichmentTag> enrichmentTags); void enrich(T judgment, EnrichmentTag enrichmentTag); @Autowired void setJudgmentRepository(JudgmentRepository judgmentRepository); @Autowired void setEnrichmentTagRepository(EnrichmentTagRepository enrichmentTagRepository); @Autowired void setEnrichmentTagApplierManager(EnrichmentTagApplierManager enrichmentTagApplierManager); @Autowired void setEntityManager(EntityManager entityManager); }
JudgmentEnrichmentService { public <T extends Judgment> T findOneAndEnrich(long judgmentId) { T judgment = judgmentRepository.findOneAndInitialize(judgmentId); if (judgment == null) { return null; } entityManager.detach(judgment); enrich(judgment); return judgment; }  T findOneAndEnrich(long judgmentId); void unenrichAndSave(Judgment judgment); void enrich(T judgment); void enrich(T judgment, List<EnrichmentTag> enrichmentTags); void enrich(T judgment, EnrichmentTag enrichmentTag); @Autowired void setJudgmentRepository(JudgmentRepository judgmentRepository); @Autowired void setEnrichmentTagRepository(EnrichmentTagRepository enrichmentTagRepository); @Autowired void setEnrichmentTagApplierManager(EnrichmentTagApplierManager enrichmentTagApplierManager); @Autowired void setEntityManager(EntityManager entityManager);  }