@Test public void testReportComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" // "))); fileContents.reportCComment(1, 2, 1, 2); final Map<Integer, List<TextBlock>> comments = fileContents.getCComments(); assertEquals("Invalid comment", new Comment(new String[] {"/"}, 2, 1, 2).toString(), comments.get(1).get(0).toString()); }
@Test public void testReportCppComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" // "))); fileContents.reportCppComment(1, 2); final Map<Integer, TextBlock> cppComments = fileContents.getCppComments(); assertEquals("Invalid comment", new Comment(new String[] {" // "}, 2, 1, 6).toString(), cppComments.get(1).toString()); }
@Test public void testGetJavadocBefore() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" "))); final Map<Integer, TextBlock> javadoc = new HashMap<>(); javadoc.put(0, new Comment(new String[] {"// "}, 2, 1, 2)); Whitebox.setInternalState(fileContents, "javadocComments", javadoc); final TextBlock javadocBefore = fileContents.getJavadocBefore(2); assertEquals("Invalid before javadoc", new Comment(new String[] {"// "}, 2, 1, 2).toString(), javadocBefore.toString()); }
@Test public void testDeprecatedAbbreviatedMethod() { // just to make UT coverage 100% final FileContents fileContents = new FileContents("filename", "123", "456"); fileContents.reportCppComment(1, 1); fileContents.reportCComment(1, 1, 1, 1); final Comment cppComment = new Comment(new String[] {"23"}, 1, 1, 2); final Comment cComment = new Comment(new String[] {"2"}, 1, 1, 1); assertEquals("Invalid cpp comment", cppComment.toString(), fileContents.getCppComments().get(1).toString()); assertEquals("Invalid c comment", cComment.toString(), fileContents.getCComments().get(1).get(0).toString()); }
@Test public void testReportJavadocComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" /** */ "))); fileContents.reportCComment(1, 2, 1, 6); final TextBlock comment = fileContents.getJavadocBefore(2); assertEquals("Invalid comment", new Comment(new String[] {"/** *"}, 2, 1, 6).toString(), comment.toString()); }
@Test public void testToString() { final Comment comment = new Comment(new String[] {"value"}, 1, 2, 3); Assert.assertEquals("Invalid toString result", "Comment[text=[value], startLineNo=2, endLineNo=2, startColNo=1, endColNo=3]", comment.toString()); }
@Test public void testReportJavadocComment2() { final FileContents fileContents = new FileContents("filename", " /** */ "); fileContents.reportCComment(1, 2, 1, 6); final TextBlock comment = fileContents.getJavadocBefore(2); assertEquals("Invalid comment", new Comment(new String[] {"/** *"}, 2, 1, 6).toString(), comment.toString()); }