HierarchyTypeService { public List<HierarchyType> getAllHierarchyTypes() { return hierarchyTypeRepository.findAll(); } @Autowired  HierarchyTypeService(HierarchyTypeRepository hierarchyTypeRepository); @Transactional HierarchyType createHierarchyType(HierarchyType hierarchyType); @Transactional HierarchyType updateHierarchyType(HierarchyType hierarchyType); HierarchyType getHierarchyTypeByName(String name); List<HierarchyType> getAllHierarchyTypes();  }
@Test public void testGetAllHierarchyTypes() { when(hierarchyTypeService.getAllHierarchyTypes()).thenReturn( Arrays.asList(expectedHierarchyType1, expectedHierarchyType2)); List<HierarchyType> hierarchyTypes = hierarchyTypeService.getAllHierarchyTypes(); assertEquals(2, hierarchyTypes.size()); verify(hierarchyTypeRepository).findAll(); }