### Question:
KeyStoreManagement implements DynamicMBean { public static KeyStoreManagement getKeyStoreManagement(String type, Resource source, String pass) throws Exception { if (type == null) { throw new IllegalArgumentException("type cannot be null"); } KeyStore store = KeyStore.getInstance(type); if (source == null || source.getFilename().equals(PropertyConfigurer.NO_DEFAULT)) { return null; } InputStream is = source.getInputStream(); try { store.load(is, pass.toCharArray()); } finally { if (is != null) { is.close(); } } return new KeyStoreManagement(store, source, type); } private  KeyStoreManagement(KeyStore keyStore, Resource source, String type); static KeyStoreManagement getKeyStoreManagement(String type, Resource source, String pass); KeyStore getKeyStore(); @Override void setAttribute(Attribute attribute); @Override AttributeList setAttributes(AttributeList attributes); @Override Object invoke(String actionName, Object[] params, String[] signature); @Override MBeanInfo getMBeanInfo(); @Override Object getAttribute(String attribute); @Override AttributeList getAttributes(String[] attributes);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void typeNull() throws Exception { KeyStoreManagement ksm = KeyStoreManagement.getKeyStoreManagement(null, null, PropertyConfigurer.NO_DEFAULT); assertNull(ksm); }
@Test public void resourceNull() throws Exception { KeyStoreManagement ksm = KeyStoreManagement.getKeyStoreManagement("JKS", null, PropertyConfigurer.NO_DEFAULT); assertNull(ksm); }
@Test public void resourceNotSpecified() throws Exception { KeyStoreManagement ksm = KeyStoreManagement.getKeyStoreManagement("JKS", new FileSystemResource(PropertyConfigurer.NO_DEFAULT), PropertyConfigurer.NO_DEFAULT); assertNull(ksm); }
@Test public void keystore() throws Exception { KeyStoreManagement ksm = KeyStoreManagement.getKeyStoreManagement("JKS", new FileSystemResource(getKeystorePath()), "password"); assertNotNull(ksm); }
@Test(expected = IOException.class) public void keystoreInvalidType() throws Exception { KeyStoreManagement ksm = KeyStoreManagement.getKeyStoreManagement("PKCS12", new FileSystemResource(getKeystorePath()), "password"); assertNotNull(ksm); }
@Test public void truststore() throws Exception { KeyStoreManagement ksm = KeyStoreManagement.getKeyStoreManagement("JKS", new FileSystemResource(getTruststorePath()), "password"); assertNotNull(ksm); }
@Test(expected = IOException.class) public void truststoreInvalidPassword() throws Exception { KeyStoreManagement.getKeyStoreManagement("JKS", new FileSystemResource(getTruststorePath()), "wibble"); }