package bluej.parser;


| Test the unit testing parse code. | | @author Andrew Patterson | public class UnitTestAnalyzerTest extends junit.framework.TestCase{ private String testSrc = "class IgnoreMe extends junit.framework.TestCase {" + "\n" + " protected void testYYY() { }" + "\n" + "}" + "\n" + "public class TestSrc extends junit.framework.TestCase {" + "\n" + " private int x = 55;" + "\n" + " java.util.HashMap h = new HashMap()," + "\n" + " i," + "\n" + " j = null;" + "\n" + "" + "\n" + " /**" + "\n" + " * Should be ignored because of the parameter" + "\n" + " */" + "\n" + " protected void setUp(int a)" + "\n" + " {" + "\n" + " for (int i=0; i<10; i++) { ; }" + "\n" + " }" + "\n" + "" + "\n" + " protected void setUp()" + "\n" + " {" + "\n" + " for (int i=0; i<10; i++) { ; }" + "\n" + " }" + "\n" + "" + "\n" + " // variables and method names are in a different scope" + "\n" + " public String testXXX;" + "\n" + "" + "\n" + " /**" + "\n" + " * Here is an attached comment" + "\n" + " */" + "\n" + " protected void testXXX()" + "\n" + " {" + "\n" + " System.out.println(\"Hello\");" + "\n" + " }" + "\n" + "}" + "\n"; private UnitTestAnalyzer uta;
| Sets up the test fixture. | | Called before every test case method. | protected void setUp() throws Exception { uta = new UnitTestAnalyzer(new java.io.StringReader(testSrc)); }
| Tears down the test fixture. | | Called after every test case method. | protected void tearDown() { }
| A sample test case method | public void testFindingVariables() { java.util.List<SourceSpan> variables = uta.getFieldSpans(); SourceSpan xSpan = (SourceSpan) variables.get(0); assertEquals(5, xSpan.getStartLine()); assertEquals(5, xSpan.getStartColumn()); assertEquals(5, xSpan.getEndLine()); assertEquals(24, xSpan.getEndColumn()); SourceSpan hashmapSpan = (SourceSpan) variables.get(1); assertEquals(6, hashmapSpan.getStartLine()); assertEquals(5, hashmapSpan.getStartColumn()); assertEquals(8, hashmapSpan.getEndLine()); assertEquals(32, hashmapSpan.getEndColumn()); SourceSpan testXXXSpan = (SourceSpan) variables.get(2); assertEquals(24, testXXXSpan.getStartLine()); assertEquals(5, testXXXSpan.getStartColumn()); assertEquals(24, testXXXSpan.getEndLine()); assertEquals(27, testXXXSpan.getEndColumn()); } public void testFindingMethods() { SourceSpan setUpSpan = uta.getMethodBlockSpan("setUp"); assertEquals(19, setUpSpan.getStartLine()); assertEquals(5, setUpSpan.getStartColumn()); assertEquals(21, setUpSpan.getEndLine()); assertEquals(6, setUpSpan.getEndColumn()); SourceSpan testXXXSpan = uta.getMethodBlockSpan("testXXX"); assertEquals(30, testXXXSpan.getStartLine()); assertEquals(5, testXXXSpan.getStartColumn()); assertEquals(32, testXXXSpan.getEndLine()); assertEquals(7, testXXXSpan.getEndColumn()); } public void testMethodInsertion() { SourceLocation insertLocation = uta.getNewMethodInsertLocation(); assertEquals(33, insertLocation.getLine()); assertEquals(1, insertLocation.getColumn()); } public void testFixtureInsertion() { SourceLocation insertLocation = uta.getFixtureInsertLocation(); assertEquals(4, insertLocation.getLine()); assertEquals(55, insertLocation.getColumn()); } }
top, use, map, class UnitTestAnalyzerTest

.   setUp
.   tearDown
.   testFindingVariables
.   testFindingMethods
.   testMethodInsertion
.   testFixtureInsertion




113 neLoCode + 7 LoComm