Skip to content

Commit ddb5c8b

Browse files
committed
added test to find no errors with code in javadoc comment
1 parent e6d766d commit ddb5c8b

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

src/test/java/edu/byu/cs240/checkstyle/readability/CommentedCodeTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public void should_FindNoErrors_when_commentInString() throws CheckstyleExceptio
6161
}
6262

6363

64+
@Test
65+
@DisplayName("Should find no errors in code that has javadoc comment")
66+
public void should_FindNoErrors_when_javadocComment() throws CheckstyleException {
67+
String fileName = "testInputs/commentedCode/should_FindNoErrors_when_javadocComment.java";
68+
testFiles(0, fileName);
69+
}
70+
71+
6472
@Test
6573
@DisplayName("Should find errors in code that has code comments")
6674
public void should_FindErrors_when_CodeComments() throws CheckstyleException {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.io.File;
2+
import java.io.IOException;
3+
import java.nio.file.Files;
4+
import java.nio.file.Path;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.stream.Stream;
8+
9+
class should_FindNoErrors_when_javadocComment {
10+
/**
11+
* Receives a path to a file/directory and maps all file names the associated absolute paths.
12+
* <br>
13+
* If the path provided leads to a directory, all the files in the directory are returned as a
14+
* mapping of their file names to their absolute paths. If the path provided leads not to a directory,
15+
* only the mapping of its file name and absolute path is returned.
16+
* <br><br><br>
17+
* For a <b>file</b> example, given the input of
18+
* {@code "autograder/phases/phase0/passoff/chess/ChessBoardTests.java"},
19+
* we get an output of:
20+
* <br>
21+
* <code>
22+
* {
23+
* "ChessBoardTests.java": "autograder/phases/phase0/passoff/chess/ChessBoardTests.java"
24+
* }
25+
* </code>
26+
* <br><br>
27+
* For a <b>directory</b> example, given the input of
28+
* {@code "autograder/phases/phase0/passoff/chess/"},
29+
* we get an output of:
30+
* <br>
31+
* <code>
32+
* {
33+
* "QueenMoveTests.java": "autograder/phases/phase0/passoff/chess/piecemoves/QueenMoveTests.java",
34+
* "EqualsTestingUtility.java": "autograder/phases/phase0/passoff/chess/EqualsTestingUtility.java",
35+
* "ChessPositionTests.java": "autograder/phases/phase0/passoff/chess/ChessPositionTests.java",
36+
* "TestUtilities.java": "autograder/phases/phase0/passoff/chess/TestUtilities.java",
37+
* "ChessMoveTests.java": "autograder/phases/phase0/passoff/chess/ChessMoveTests.java",
38+
* "ChessPieceTests.java": "autograder/phases/phase0/passoff/chess/ChessPieceTests.java",
39+
* "KnightMoveTests.java": "autograder/phases/phase0/passoff/chess/piecemoves/KnightMoveTests.java",
40+
* "ChessBoardTests.java": "autograder/phases/phase0/passoff/chess/ChessBoardTests.java",
41+
* "RookMoveTests.java": "autograder/phases/phase0/passoff/chess/piecemoves/RookMoveTests.java",
42+
* "BishopMoveTests.java": "autograder/phases/phase0/passoff/chess/piecemoves/BishopMoveTests.java",
43+
* "KingMoveTests.java": "autograder/phases/phase0/passoff/chess/piecemoves/KingMoveTests.java",
44+
* "PawnMoveTests.java": "autograder/phases/phase0/passoff/chess/piecemoves/PawnMoveTests.java"
45+
* }
46+
* </code>
47+
*
48+
* @param filePath The path to file/directory to find all the file names and the associated absolute paths
49+
* @return A map of the file names and the associated absolute paths given a path
50+
*/
51+
public static Map<String, String> getFileNamesToAbsolutePaths(Path filePath) throws GradingException {
52+
Map<String, String> fileNamesToAbsolutesPaths = new HashMap<>();
53+
try (Stream<Path> paths = Files.walk(filePath)) {
54+
for (Path path : paths.toList()) {
55+
File file = path.toFile();
56+
if (file.isFile()) {
57+
String fileName = file.getName();
58+
String absolutePath = file.getAbsolutePath();
59+
fileNamesToAbsolutesPaths.put(fileName, absolutePath);
60+
}
61+
}
62+
} catch (IOException e) {
63+
throw new GradingException(
64+
String.format("Could not find file names given %s: %s", filePath, e.getMessage())
65+
);
66+
}
67+
return fileNamesToAbsolutesPaths;
68+
}
69+
}

0 commit comments

Comments
 (0)