@Test public void findCcDivisions_correct_order() { CommonCourtDivision ccDivisionOne = new CommonCourtDivision(); ccDivisionOne.setCode("0001"); ccDivisionOne.setName("I Wydział Cywilny"); CommonCourtDivision ccDivisionTwo = new CommonCourtDivision(); ccDivisionTwo.setCode("0002"); ccDivisionTwo.setName("IV Wydział Karny"); CommonCourtDivision ccDivisionThree = new CommonCourtDivision(); ccDivisionThree.setCode("0003"); ccDivisionThree.setName("IX Wydział Penitencjarny i Nadzoru nad Wykonywaniem Orzeczeń Karnych"); SimpleEntity simpleCcDivisionOne = new SimpleEntity(); simpleCcDivisionOne.setName("I Wydział Cywilny"); SimpleEntity simpleCcDivisionTwo = new SimpleEntity(); simpleCcDivisionTwo.setName("IV Wydział Karny"); SimpleEntity simpleCcDivisionThree = new SimpleEntity(); simpleCcDivisionThree.setName("IX Wydział Penitencjarny i Nadzoru nad Wykonywaniem Orzeczeń Karnych"); List<CommonCourtDivision> divisionsWrongOrder = Arrays.asList(ccDivisionThree, ccDivisionOne, ccDivisionTwo); List<CommonCourtDivision> divisionsRightOrder = Arrays.asList(ccDivisionOne, ccDivisionTwo, ccDivisionThree); when(ccDivisionRepository.findAllByCourtId(1)).thenReturn(divisionsWrongOrder); when(simpleEntityConverter.convertCcDivisions(divisionsRightOrder)) .thenReturn(Arrays.asList(simpleCcDivisionOne, simpleCcDivisionTwo, simpleCcDivisionThree)); List<SimpleEntity> divisions = ccListService.findCcDivisions(1); assertEquals(3, divisions.size()); assertEquals(divisions.get(0).getName(), ccDivisionOne.getName()); assertEquals(divisions.get(1).getName(), ccDivisionTwo.getName()); assertEquals(divisions.get(2).getName(), ccDivisionThree.getName()); }
@Cacheable(DICTIONARIES) public List<SimpleEntity> findCcDivisions(long courtId) { List<CommonCourtDivision> courtDivisions = ccDivisionRepository.findAllByCourtId(courtId); Collections.sort(courtDivisions, new CcDivisionComparator()); return simpleEntityConverter.convertCcDivisions(courtDivisions); }
CcListService { @Cacheable(DICTIONARIES) public List<SimpleEntity> findCcDivisions(long courtId) { List<CommonCourtDivision> courtDivisions = ccDivisionRepository.findAllByCourtId(courtId); Collections.sort(courtDivisions, new CcDivisionComparator()); return simpleEntityConverter.convertCcDivisions(courtDivisions); } }
CcListService { @Cacheable(DICTIONARIES) public List<SimpleEntity> findCcDivisions(long courtId) { List<CommonCourtDivision> courtDivisions = ccDivisionRepository.findAllByCourtId(courtId); Collections.sort(courtDivisions, new CcDivisionComparator()); return simpleEntityConverter.convertCcDivisions(courtDivisions); }  }
CcListService { @Cacheable(DICTIONARIES) public List<SimpleEntity> findCcDivisions(long courtId) { List<CommonCourtDivision> courtDivisions = ccDivisionRepository.findAllByCourtId(courtId); Collections.sort(courtDivisions, new CcDivisionComparator()); return simpleEntityConverter.convertCcDivisions(courtDivisions); }  @Cacheable(DICTIONARIES) List<SimpleCommonCourt> findCommonCourts(); @Cacheable(DICTIONARIES) List<SimpleEntity> findCcDivisions(long courtId); @Autowired void setCommonCourtRepository(CommonCourtRepository ccRepository); @Autowired void setCcDivisionRepository(CcDivisionRepository ccDivisionRepository); @Autowired void setSimpleEntityConverter(SimpleEntityConverter simpleEntityConverter); @Autowired void setSimpleCommonCourtConverter(SimpleCommonCourtConverter simpleCommonCourtConverter); }
CcListService { @Cacheable(DICTIONARIES) public List<SimpleEntity> findCcDivisions(long courtId) { List<CommonCourtDivision> courtDivisions = ccDivisionRepository.findAllByCourtId(courtId); Collections.sort(courtDivisions, new CcDivisionComparator()); return simpleEntityConverter.convertCcDivisions(courtDivisions); }  @Cacheable(DICTIONARIES) List<SimpleCommonCourt> findCommonCourts(); @Cacheable(DICTIONARIES) List<SimpleEntity> findCcDivisions(long courtId); @Autowired void setCommonCourtRepository(CommonCourtRepository ccRepository); @Autowired void setCcDivisionRepository(CcDivisionRepository ccDivisionRepository); @Autowired void setSimpleEntityConverter(SimpleEntityConverter simpleEntityConverter); @Autowired void setSimpleCommonCourtConverter(SimpleCommonCourtConverter simpleCommonCourtConverter);  }