### Question:
CLIParser extends AbstractCLIParser { @Override public <T> boolean isApplicableTo(Attachment attachment, User user, T context) throws TException { AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment); return attachmentContent.getFilename().endsWith(XML_FILE_EXTENSION) && hasCLIRootElement(attachmentContent, user, context); } CLIParser(AttachmentConnector attachmentConnector, AttachmentContentProvider attachmentContentProvider); @Override boolean isApplicableTo(Attachment attachment, User user, T context); @Override List<LicenseInfoParsingResult> getLicenseInfos(Attachment attachment, User user, T context); @Override ObligationParsingResult getObligations(Attachment attachment, User user, T context);  }### Answer:
@Test public void testIsApplicableTo() throws Exception { when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE))); assertTrue(parser.isApplicableTo(attachment, new User(), new Project())); }
@Test public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception { AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml"); when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>"))); assertFalse(parser.isApplicableTo(attachment, new User(), new Project())); }
@Test public void testIsApplicableToFailsOnMalformedXML() throws Exception { AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml"); when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("this is not an xml file"))); assertFalse(parser.isApplicableTo(attachment, new User(), new Project())); }