PermissionAdmin implements PermissionAdminMBean { public String[] getPermissions(String location) throws IOException { if (location == null) { throw new IOException("Location cannot be null"); } PermissionInfo[] permissions = permAdmin.getPermissions(location); if (permissions != null) { String[] encoded = new String[permissions.length]; for (int i = 0; i < permissions.length; i++) { PermissionInfo info = permissions[i]; encoded[i] = info.getEncoded(); } return encoded; } return null; } PermissionAdmin(org.osgi.service.permissionadmin.PermissionAdmin permAdmin); String[] getPermissions(String location); String[] listDefaultPermissions(); String[] listLocations(); void setDefaultPermissions(String[] encodedPermissions); void setPermissions(String location, String[] encodedPermissions);  }
@Test public void testGetPermissions() throws IOException { PermissionInfo info = new PermissionInfo("Admin", "test", "get"); PermissionInfo[] permInfos = new PermissionInfo[] { info, info }; Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(permInfos); String[] permissions = mbean.getPermissions("test"); Assert.assertNotNull(permissions); Assert.assertEquals(2, permissions.length); Assert.assertArrayEquals("Checks encoded permissions", new String[] { info.getEncoded(), info.getEncoded() }, permissions); Mockito.reset(permAdmin); Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(null); String[] permissions2 = mbean.getPermissions("test"); Assert.assertNull(permissions2); }