### Question:
PluginsPermissionFactory implements PermissionFactory { @Override public List<Permission> buildFromNames(List<String> names) { List<Permission> resultingPermissions = new ArrayList<>(); for (String name : names) { Permission permission = pluginPermissionManager.findPluginsBranchPermissionByName(name); if (permission != null) { resultingPermissions.add(permission); } } return resultingPermissions; } PluginsPermissionFactory(PluginPermissionManager pluginPermissionManager); @Override Permission buildFromMask(int mask); @Override Permission buildFromName(String name); @Override List<Permission> buildFromNames(List<String> names);  }### Answer:
@Test public void buildFromNamesShouldReturnPermissionsAccordingNames() { List<String> names = Arrays.asList(BranchPermission.VIEW_TOPICS.getName(), BranchPermission.CLOSE_TOPICS.getName()); when(pluginPermissionManager.findPluginsBranchPermissionByName(BranchPermission.VIEW_TOPICS.getName())) .thenReturn(BranchPermission.VIEW_TOPICS); when(pluginPermissionManager.findPluginsBranchPermissionByName(BranchPermission.CLOSE_TOPICS.getName())) .thenReturn(BranchPermission.CLOSE_TOPICS); List<Permission> expected = Arrays.asList((Permission)BranchPermission.VIEW_TOPICS, (Permission)BranchPermission.CLOSE_TOPICS); PluginsPermissionFactory permissionFactory = new PluginsPermissionFactory(pluginPermissionManager); List<Permission> actual = permissionFactory.buildFromNames(names); assertEquals(actual, expected); }
@Test public void buildFromNamesResultShouldNotContainNullWhenPermissionNotFound() { List<String> names = Arrays.asList(BranchPermission.VIEW_TOPICS.getName(), BranchPermission.CLOSE_TOPICS.getName()); when(pluginPermissionManager.findPluginsBranchPermissionByName(BranchPermission.VIEW_TOPICS.getName())) .thenReturn(BranchPermission.VIEW_TOPICS); when(pluginPermissionManager.findPluginsBranchPermissionByName(BranchPermission.CLOSE_TOPICS.getName())).thenReturn(null); PluginsPermissionFactory permissionFactory = new PluginsPermissionFactory(pluginPermissionManager); List<Permission> result = permissionFactory.buildFromNames(names); assertFalse(result.contains(null)); }
@Test public void buildFromNamesShouldReturnEmptyListWhenNoPermissionsFound() { List<String> names = Arrays.asList(BranchPermission.VIEW_TOPICS.getName(), BranchPermission.CLOSE_TOPICS.getName()); when(pluginPermissionManager.findPluginsBranchPermissionByName(anyString())).thenReturn(null); PluginsPermissionFactory permissionFactory = new PluginsPermissionFactory(pluginPermissionManager); List<Permission> result = permissionFactory.buildFromNames(names); assertEquals(result, Collections.EMPTY_LIST); }