@Test public void testUTF8ByteOrderMark() throws Exception { byte[] xml = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF, // UTF-8 BOM '<', '?', 'x', 'm', 'l', ' ', 'v', 'e', 'r', 's', 'i', 'o', 'n', '=', '"', '1', '.', '0', '"', '?', '>' }; ByteArrayInputStream in = new ByteArrayInputStream(xml); IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "/dummy/file"); assertSame(XMLAnalyzer.class, fa.getClass()); }
/** Test that we get the correct analyzer if the file name exactly matches a known extension. */ @Test public void testFileNameSameAsExtension() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream("#!/bin/sh\nexec /usr/bin/zip \"$@\"\n".getBytes("US-ASCII")); String file = "/dummy/path/to/source/zip"; IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, file); assertSame(ShAnalyzer.class, fa.getClass()); }
@Test public void testJar() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream jos = new JarOutputStream(baos); jos.putNextEntry(new JarEntry("dummy")); jos.closeEntry(); jos.close(); InputStream in = new ByteArrayInputStream(baos.toByteArray()); IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "dummy"); assertSame(JarAnalyzer.class, fa.getClass()); }
@Test public void testUTF8ByteOrderMarkPlainFile() throws Exception { byte[] bytes = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF, // UTF-8 BOM 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' }; ByteArrayInputStream in = new ByteArrayInputStream(bytes); IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "/dummy/file"); assertSame(PlainAnalyzer.class, fa.getClass()); }
@Test public void testPlainText() throws IOException { ByteArrayInputStream in = new ByteArrayInputStream("This is a plain text file.".getBytes("US-ASCII")); assertSame(PlainAnalyzer.class, AnalyzerGuru.getAnalyzer(in, "dummy").getClass()); }