/** * If <code>propertyValue</code> is not null or empty, returns the result * of <code>KeyStoreFileType.fromPropertyValue(propertyValue)</code>. Else, * returns the result of <code>KeyStoreFileType.fromFileName(filename)</code>. * @param propertyValue property value describing the KeyStoreFileType, or * null/empty to auto-detect the type from the file * name. * @param filename file name of the key store file. The file extension is * used to auto-detect the KeyStoreFileType when * <code>propertyValue</code> is null or empty. * @return a KeyStoreFileType. * @throws IllegalArgumentException if <code>propertyValue</code> is not * one of "JKS", "PEM", or empty/null. * @throws IllegalArgumentException if <code>propertyValue</code>is empty * or null and the type could not be determined from the file name. */ public static KeyStoreFileType fromPropertyValueOrFileName(String propertyValue, String filename) { KeyStoreFileType result = KeyStoreFileType.fromPropertyValue(propertyValue); if (result == null) { result = KeyStoreFileType.fromFilename(filename); } return result; } }
@Test(expected = IllegalArgumentException.class) public void testFromPropertyValueThrowsOnBadPropertyValue() { KeyStoreFileType.fromPropertyValue("foobar"); }
@Test public void testFromPropertyValue() { Assert.assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromPropertyValue("PEM")); Assert.assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromPropertyValue("JKS")); Assert.assertNull(KeyStoreFileType.fromPropertyValue("")); Assert.assertNull(KeyStoreFileType.fromPropertyValue(null)); }
@Test public void testFromPropertyValueIgnoresCase() { Assert.assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromPropertyValue("pem")); Assert.assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromPropertyValue("jks")); Assert.assertNull(KeyStoreFileType.fromPropertyValue("")); Assert.assertNull(KeyStoreFileType.fromPropertyValue(null)); }