### Question:
PluginPermissionManager { public JtalksPermission findPluginsBranchPermissionByName(String name) { PluginFilter filter = new TypeFilter(PluginWithBranchPermissions.class); List<Plugin> plugins = pluginLoader.getPlugins(filter); for (Plugin plugin : plugins) { if (plugin.isEnabled()) { JtalksPermission permission = ((PluginWithBranchPermissions)plugin).getBranchPermissionByName(name); if (permission != null) { return permission; } } } return null; } PluginPermissionManager(PluginLoader pluginLoader); List<JtalksPermission> getPluginsBranchPermissions(); JtalksPermission findPluginsBranchPermissionByMask(int mask); JtalksPermission findPluginsBranchPermissionByName(String name);  }### Answer:
@Test public void findPluginBranchPermissionByNameShouldReturnPermissionIfPluginEnabled() { JtalksPermission targetPermission = BranchPermission.VIEW_TOPICS; when(pluginWithBranchPermissions.getBranchPermissionByName(targetPermission.getName())).thenReturn(targetPermission); when(pluginWithBranchPermissions.isEnabled()).thenReturn(true); PluginPermissionManager pluginPermissionManager = new PluginPermissionManager(pluginLoader); JtalksPermission actual = pluginPermissionManager.findPluginsBranchPermissionByName(targetPermission.getName()); assertEquals(actual, targetPermission); }
@Test public void findPluginBranchPermissionByNameShouldReturnNullIfPluginDisabled() { JtalksPermission targetPermission = BranchPermission.VIEW_TOPICS; when(pluginWithBranchPermissions.getBranchPermissionByName(targetPermission.getName())).thenReturn(targetPermission); when(pluginWithBranchPermissions.isEnabled()).thenReturn(false); PluginPermissionManager pluginPermissionManager = new PluginPermissionManager(pluginLoader); JtalksPermission result = pluginPermissionManager.findPluginsBranchPermissionByName(targetPermission.getName()); assertNull(result); }
@Test public void findPluginBranchPermissionByNameShouldReturnNullIfNoPermissionFound() { when(pluginWithBranchPermissions.getBranchPermissionByName(anyString())).thenReturn(null); when(pluginWithBranchPermissions.isEnabled()).thenReturn(true); PluginPermissionManager pluginPermissionManager = new PluginPermissionManager(pluginLoader); JtalksPermission actual = pluginPermissionManager.findPluginsBranchPermissionByName("anyName"); assertNull(actual); }