### Question:
TaskAdaptor extends QBeanSupport { protected void initService () throws Exception { QFactory factory = getServer().getFactory(); Element e = getPersist (); task = factory.newInstance (e.getChildTextTrim ("class")); factory.setLogger (task, e); } TaskAdaptor(); Object getObject();  }### Answer:
@Test public void testInitServiceThrowsNullPointerException() throws Throwable { TaskAdaptor taskAdaptor = new TaskAdaptor(); try { taskAdaptor.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.iso.TaskAdaptor.getServer()\" is null", ex.getMessage(), "ex.getMessage()"); } assertNull(taskAdaptor.task, "taskAdaptor.task"); assertTrue(taskAdaptor.isModified(), "taskAdaptor.isModified()"); } }
@Test public void testInitServiceThrowsNullPointerException1() throws Throwable { TaskAdaptor taskAdaptor = new TaskAdaptor(); String[] args = new String[0]; taskAdaptor.setServer(q2); try { taskAdaptor.initService(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jdom2.Element.getChildTextTrim(String)\" because \"e\" is null", ex.getMessage(), "ex.getMessage()"); } assertNull(taskAdaptor.task, "taskAdaptor.task"); assertFalse(taskAdaptor.isModified(), "taskAdaptor.isModified()"); } }