UpdateTemplateInstance { private TemplateDefinition getTempalteDefinition(TemplateName templateName){ Map<UserId, User> usersMap = tenantManage.getUsers(); User userAdmin = null; Map<TemplateName, TemplateDefinition> definitionMap = new HashMap<TemplateName, TemplateDefinition>(); for (User user : usersMap.values()){ if (user.getUserRole().getValue().equals("admin")){ userAdmin = user; } } if (userAdmin!=null){ definitionMap = tenantManage.getTempalteDefinition(userAdmin.getUserId()); } return definitionMap.isEmpty()?null:definitionMap.get(templateName); } UpdateTemplateInstance(DataBroker dataBroker, TenantManage tenantManage); String checkTemplateInstance(UserId userId, TemplateInstance templateInstance);  }
@Test public void testGetTempalteDefinition() throws Exception { method = class1.getDeclaredMethod("getTempalteDefinition",new Class[]{ TemplateName.class }); method.setAccessible(true); UserId userId = mock(UserId.class); User user = mock(User.class); TemplateName templateName = new TemplateName("tename"); TemplateDefinition templateDefinition = mock(TemplateDefinition.class); Map<UserId, User> usersMap = new HashMap<UserId, User>(); Map<TemplateName, TemplateDefinition> templateMap = new HashMap<TemplateName, TemplateDefinition>(); usersMap.put(userId,user); templateMap.put(templateName,templateDefinition); when(tenantManage.getUsers()).thenReturn(usersMap); when(user.getUserRole()).thenReturn(new UserRoleName("admin")); when(user.getUserId()).thenReturn(userId); when(tenantManage.getTempalteDefinition(userId)).thenReturn(templateMap); Assert.assertTrue(method.invoke(updateTemplateInstance, templateName) != null); }