AnalyzerGuruTest.java revision 200
package org.opensolaris.opengrok.analysis;
import java.io.ByteArrayInputStream;
import org.junit.Test;
import org.opensolaris.opengrok.analysis.plain.XMLAnalyzer;
import org.opensolaris.opengrok.analysis.sh.ShAnalyzer;
import static org.junit.Assert.*;
/**
* Tests for the functionality provided by the AnalyzerGuru class.
*/
public class AnalyzerGuruTest {
/**
* 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";
FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, file);
assertSame(ShAnalyzer.class, fa.getClass());
}
@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);
FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "/dummy/file");
assertSame(XMLAnalyzer.class, fa.getClass());
}
}