@Test void testCreateGroups() { String id = "test"; Package aPackage = mock(Package.class); when(aPackage.getId()).thenReturn(id); when(aPackage.getLabel()).thenReturn(id); GroupValue groupValue = mock(GroupValue.class); when(groupValue.getName()).thenReturn("group"); Group group = mock(Group.class); Role editorRole = mock(Role.class); Role managerRole = mock(Role.class); RoleValue editorRoleValue = RoleValue.builder().setName("group_EDITOR").setLabel(EDITOR).build(); RoleValue managerRoleValue = RoleValue.builder().setName("group_MANAGER").setLabel(MANAGER).build(); when(groupValueFactory.createGroup(id, id, GroupService.DEFAULT_ROLES, "test")) .thenReturn(groupValue); when(groupFactory.create(groupValue)).thenReturn(group); when(editorRole.getName()).thenReturn("group_EDITOR"); when(editorRole.getLabel()).thenReturn(EDITOR); doReturn(editorRole).when(roleFactory).create(editorRoleValue); when(managerRole.getName()).thenReturn("group_MANAGER"); when(managerRole.getLabel()).thenReturn(MANAGER); doReturn(managerRole).when(roleFactory).create(managerRoleValue); Role defaultEditorRole = mock(Role.class); when(defaultEditorRole.getLabel()).thenReturn(EDITOR); Role defaultManagerRole = mock(Role.class); when(defaultManagerRole.getIncludes()).thenReturn(singletonList(defaultEditorRole)); when(groupValue.getRoles()).thenReturn(ImmutableList.of(editorRoleValue, managerRoleValue)); mockDefaultRoleQueries(defaultEditorRole, defaultManagerRole); groupPackageService.createGroups(singletonList(aPackage)); verify(dataService).add(GROUP, group); verify(dataService).add(eq(ROLE), roleCaptor.capture()); assertEquals(Set.of(managerRole, editorRole), roleCaptor.getValue().collect(toSet())); verify(managerRole).setGroup(group); verify(managerRole).setIncludes(asList(defaultManagerRole, editorRole)); verify(editorRole).setGroup(group); verify(editorRole).setIncludes(singletonList(defaultEditorRole)); }
@Override public void createGroups(List<Package> packages) { packages.forEach(this::createGroup); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroups(List<Package> packages) { packages.forEach(this::createGroup); } }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroups(List<Package> packages) { packages.forEach(this::createGroup); } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroups(List<Package> packages) { packages.forEach(this::createGroup); } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); @Override void createGroup(Package rootPackage); @Override void createGroups(List<Package> packages); @Override void deleteGroup(Package rootPackage); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void createGroups(List<Package> packages) { packages.forEach(this::createGroup); } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); @Override void createGroup(Package rootPackage); @Override void createGroups(List<Package> packages); @Override void deleteGroup(Package rootPackage);  }