### Question:
KeyStoreAdaptor extends QBeanSupport implements KeyStoreAdaptorMBean { protected void initService () throws Exception { Element e = getPersist (); QFactory factory = getServer().getFactory(); ks = (SecureKeyStore) factory.newInstance (getImpl ()); factory.setLogger (ks, e); factory.setConfiguration (ks, e); NameRegistrar.register (getName (), ks); } KeyStoreAdaptor(); void setImpl(String clazz); String getImpl(); static final String DEFAULT_IMPL; }### Answer:
@Test public void testInitServiceThrowsNullPointerException() throws Throwable { String[] args = new String[0]; KeyStoreAdaptor keyStoreAdaptor = new KeyStoreAdaptor(); keyStoreAdaptor.setServer(q2); try { keyStoreAdaptor.initService(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.q2.QFactory.newInstance(String)\" because \"factory\" is null", ex.getMessage(), "ex.getMessage()"); } assertFalse(keyStoreAdaptor.isModified(), "keyStoreAdaptor.isModified()"); assertNull(keyStoreAdaptor.ks, "keyStoreAdaptor.ks"); } }
@Test public void testInitServiceThrowsNullPointerException1() throws Throwable { KeyStoreAdaptor keyStoreAdaptor = new KeyStoreAdaptor(); try { keyStoreAdaptor.initService(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.q2.Q2.getFactory()\" because the return value of \"org.jpos.q2.security.KeyStoreAdaptor.getServer()\" is null", ex.getMessage(), "ex.getMessage()"); } assertFalse(keyStoreAdaptor.isModified(), "keyStoreAdaptor.isModified()"); assertNull(keyStoreAdaptor.ks, "keyStoreAdaptor.ks"); } }