### Question:
Q2 implements FileFilter, Runnable { protected Document decrypt (Document doc) throws GeneralSecurityException, IOException, JDOMException { Element root = doc.getRootElement (); if (PROTECTED_QBEAN.equals (root.getName ())) { Element data = root.getChild ("data"); if (data != null) { ByteArrayInputStream is = new ByteArrayInputStream ( dodes ( ISOUtil.hex2byte (data.getTextTrim()), Cipher.DECRYPT_MODE) ); SAXBuilder builder = createSAXBuilder(); doc = builder.build (is); } } return doc; } Q2(String[] args, BundleContext bundleContext);  Q2();  Q2(String deployDir);  Q2(String[] args); void start(); void stop(); void run(); void shutdown(); boolean running(); boolean ready(); boolean ready(long millis); void shutdown(boolean join); QClassLoader getLoader(); QFactory getFactory(); String[] getCommandLineArgs(); boolean accept(File f); File getDeployDir(); String getWatchServiceClassname(); static Q2 getQ2(); static Q2 getQ2(long timeout); void relax(long sleep); void relax(); Log getLog(); MBeanServer getMBeanServer(); long getUptime(); void displayVersion(); UUID getInstanceId(); static String getVersionString(); void deployElement(Element e, String fileName, boolean encrypt, boolean isTransient); Framework getOSGIFramework(); static void main(String[] args); static String getVersion(); static String getRevision(); static String getBranch(); static String getBuildTimestamp(); static String getRelease(); static String getAppVersionString(); boolean isDisableDynamicClassloader(); static final String DEFAULT_DEPLOY_DIR; static final String JMX_NAME; static final String LOGGER_NAME; static final String REALM; static final String LOGGER_CONFIG; static final String QBEAN_NAME; static final String Q2_CLASS_LOADER; static final String DUPLICATE_EXTENSION; static final String ERROR_EXTENSION; static final String ENV_EXTENSION; static final String LICENSEE; static final byte[] PUBKEYHASH; static final String PROTECTED_QBEAN; static final int SCAN_INTERVAL; static final long SHUTDOWN_TIMEOUT; }### Answer:
@Test public void testDecrypt() throws Throwable { String[] args = new String[2]; args[0] = "testString"; args[1] = "testString"; Q2 q2 = new Q2(args); Document doc = mock(Document.class); Element element = mock(Element.class); given(doc.getRootElement()).willReturn(element); given(element.getName()).willReturn("testString"); Document result = q2.decrypt(doc); assertSame(doc, result, "result"); q2.stop(); }
@Test public void testDecryptThrowsIllegalStateException() throws Throwable { try { m_q2.decrypt(new Document()); fail("Expected IllegalStateException to be thrown"); } catch (IllegalStateException ex) { assertEquals("Root element not set", ex.getMessage(), "ex.getMessage()"); } }