HierarchyTypeService { public HierarchyType getHierarchyTypeByName(String name) { return hierarchyTypeRepository.findByName(name); } @Autowired  HierarchyTypeService(HierarchyTypeRepository hierarchyTypeRepository); @Transactional HierarchyType createHierarchyType(HierarchyType hierarchyType); @Transactional HierarchyType updateHierarchyType(HierarchyType hierarchyType); HierarchyType getHierarchyTypeByName(String name); List<HierarchyType> getAllHierarchyTypes();  }
@Test public void testGetHierarchyTypeByName() { when(hierarchyTypeService.getHierarchyTypeByName("Test")).thenReturn(expectedHierarchyType); HierarchyType hierarchyType = hierarchyTypeService.getHierarchyTypeByName("Test"); assertTrue(hierarchyType.getName().equalsIgnoreCase(expectedHierarchyType.getName())); }