Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
999e3a7
Added notes for App.java.
maple-johnson May 13, 2025
e5a8fa2
Added notes to the ConsoleColor section
Gabby-Moon May 15, 2025
bc95f58
Added initial notes for ColorPrinter/ColorPrinterTest.
maple-johnson May 15, 2025
50a34cc
Added notes on TruffulaOptions and TruffulaOptionsTest
Gabby-Moon May 15, 2025
011cddc
Added notes for TrufflaPrinter/TruffulaPrinterTest.
maple-johnson May 15, 2025
ffa90bd
Added notes for AlphabeticalFileSorter
Gabby-Moon May 15, 2025
0914263
Completed the print method for Wave 1.
maple-johnson May 15, 2025
655b1eb
Completed the TruffulaOptions with String[] args method, and passed e…
maple-johnson May 15, 2025
08a139a
Made additional tests for ColorPrinter
Gabby-Moon May 15, 2025
616d04b
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
Gabby-Moon May 15, 2025
ec6c52a
Added IllegalArgumentException functionality, and adjusted path handl…
maple-johnson May 16, 2025
63fa2d0
Added tests for TruffulaOptions
Gabby-Moon May 16, 2025
4ebf122
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
Gabby-Moon May 16, 2025
419ca29
Fixed tests and added another for TruffulaOptions
Gabby-Moon May 16, 2025
4c11e4c
Appended exception handling to pathway checking.
maple-johnson May 16, 2025
26f03c0
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
maple-johnson May 16, 2025
23aaec8
Successfully printed out options.
maple-johnson May 16, 2025
43bbd20
Fixed directory bug.
maple-johnson May 16, 2025
6932d37
Added try/catch
maple-johnson May 16, 2025
77a7761
First iteration of printTree in TruffulaPrinter
Gabby-Moon May 16, 2025
411a6ec
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
Gabby-Moon May 16, 2025
e27abc7
Set up initial testing for wave 4.
maple-johnson May 16, 2025
c537064
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
maple-johnson May 16, 2025
5f0f21a
Fixed coloring on test.
maple-johnson May 16, 2025
56a12d4
Fixed reset, and semicolon bug in the testPrintTree_NoHidden_NoColor …
maple-johnson May 16, 2025
4255399
Fixed the helper method for printTree
Gabby-Moon May 16, 2025
3951bf8
Added untested version of hidden handeling
Gabby-Moon May 19, 2025
3504e42
Added two tests testing hidden vs not hidden.
maple-johnson May 19, 2025
7d6507a
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
maple-johnson May 19, 2025
9f0eb31
Fixed the show hidden test.
maple-johnson May 19, 2025
d07e862
Added untested color handeling
Gabby-Moon May 19, 2025
b123a3f
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
Gabby-Moon May 19, 2025
10e03eb
Added two tests checking for alternating color settings with and with…
maple-johnson May 19, 2025
128c504
Start of a bug fix
Gabby-Moon May 19, 2025
9f68f4d
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
Gabby-Moon May 19, 2025
9670e8e
Fixed color printing on printTreeHelper
Gabby-Moon May 19, 2025
5b34b81
Fixed bug with the color tests, ensuring they are tested for color.
maple-johnson May 19, 2025
78e07da
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
maple-johnson May 19, 2025
0c6e72d
Fixed a bug with the two color tests ensuring the appropriate color a…
maple-johnson May 19, 2025
a73b11e
Small bug fix
Gabby-Moon May 19, 2025
e27ebde
Merge branch 'main' of https://github.com/Gabby-Moon/truffula
Gabby-Moon May 19, 2025
c5d6ce3
Added file sorter to printTree and printTreeHelper
Gabby-Moon May 19, 2025
a693671
Fixed bug with setting options from terminal
Gabby-Moon May 20, 2025
ce262ba
Added testInvalidArgs test to check incorrect string args.
maple-johnson May 26, 2025
31e6c82
Fixed comment header.
maple-johnson May 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,40 @@ As part of Wave 0, please fill out notes for each of the below files. They are i
PLEASE MAKE FREQUENT COMMITS AS YOU FILL OUT THIS FILE.

## App.java
- This is where we will compile our overall tree output
- It will contain a path, and may contain flags in the argument
- Flag for colored text
- Flag for hidden files
- We'll create a truffulaOptions object that is passed to the truffulaPrinter

## ConsoleColor.java
- Stores codes for colors that can be printed on the console
- Can give the code of a certain color

## ColorPrinter.java / ColorPrinterTest.java
- Sets up the color output within the terminal
- Takes the ConsoleColor enum of colors, and applies them to a specific String either permanently or temporarily.
- Tests will verify the effectiveness of the methods by verifying color output.

## TruffulaOptions.java / TruffulaOptionsTest.java
- Uses two flags in any order and path needs to be at the end
- Has methods for showing the variables
- Has a toString showing all the variables
- Has a constructor that uses the command-line and one using set variables
- The command-line constructor can throw two exceptions for missing path and incorrect directory
- The test makes a directory and gets the path from it
- And it also tests wether the hidden files and no color are being followed

## TruffulaPrinter.java / TruffulaPrinterTest.java
- Compiles our ColorPrinter and TruffulaOptions files into the TruffulaPrinter.
- This gives access to both color settings and file settings
- Everything is combined to output a tree of file data
- Case-insensitive, but sorted lexicographically
- Hidden files shown or not shown
- Specific color settings, including default options
- Testing will check if windows or hidden, and test the compiled output structure of files & colors.
- Testing setup will be extensive for TruffulaPrinter, as each file and folder needs to individually be set up, along with the color coding for each.

## AlphabeticalFileSorter.java
## AlphabeticalFileSorter.java
- Passed in an array of the type File and it compares the name (ignoring the case) and sorts them
- It returns the sorted files array
16 changes: 11 additions & 5 deletions src/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ public class App {
*
* Error messages will be shown for illegal arguments or a not found file
*/
public static void main(String[] args) throws Exception {
// TODO: Implement this
// You should create a TruffulaOptions object using the args and
// pass it to a new TruffulaPrinter that uses System.out
// Then, call printTree on the TruffulaPrinter
public static void main(String[] args) throws Exception
{
try {
TruffulaOptions options = new TruffulaOptions(args);
TruffulaPrinter setup = new TruffulaPrinter(options);
setup.printTree();
} catch (Exception e) {
throw new Exception(e);
}

}

}
6 changes: 4 additions & 2 deletions src/ColorPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public void print(String message) {
* @param message the message to print
* @param reset if true, resets the color after printing; if false, keeps the current color
*/
public void print(String message, boolean reset) {
// TODO: Implement this!
public void print(String message, boolean reset)
{
if (reset) printStream.print(currentColor.getCode() + message + ConsoleColor.RESET);
else printStream.print(currentColor.getCode() + message);
}

/**
Expand Down
144 changes: 144 additions & 0 deletions src/ColorPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,148 @@ void testPrintlnWithRedColorAndReset() {
// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintlnWithGreenColorAndNoReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream);
printer.setCurrentColor(ConsoleColor.GREEN);

// Act: Print the message
String message = "I am the color GREEN";
printer.println(message, false);

String expectedOutput = ConsoleColor.GREEN + "I am the color GREEN" + System.lineSeparator();

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintWithPurpleColorAndReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream);
printer.setCurrentColor(ConsoleColor.PURPLE);

// Act: Print the message
String message = "Why am I purple?";
printer.print(message);

String expectedOutput = ConsoleColor.PURPLE + "Why am I purple?" + ConsoleColor.RESET;

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintWithCyanColorAndNoReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream);
printer.setCurrentColor(ConsoleColor.CYAN);

// Act: Print the message
String message = "Tickle cuddle fish number 17-5.";
printer.print(message, false);

String expectedOutput = ConsoleColor.CYAN + "Tickle cuddle fish number 17-5.";

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintlnTwoParamsWithYellowColorAndReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream, ConsoleColor.YELLOW);

// Act: Print the message
String message = "Hello? Monster under the bed? Your rent is due!";
printer.println(message);

String expectedOutput = ConsoleColor.YELLOW + "Hello? Monster under the bed? Your rent is due!" + System.lineSeparator() + ConsoleColor.RESET;

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintlnTwoParamsWithBlueColorAndNoReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream, ConsoleColor.BLUE);

// Act: Print the message
String message = "I... don't wanna think about the... genetic structure of a cup.";
printer.println(message, false);

String expectedOutput = ConsoleColor.BLUE + "I... don't wanna think about the... genetic structure of a cup." + System.lineSeparator();

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintTwoParamsWithBackColorAndReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream, ConsoleColor.BLACK);

// Act: Print the message
String message = "Would you like a cup of tea?";
printer.print(message);

String expectedOutput = ConsoleColor.BLACK + "Would you like a cup of tea?" + ConsoleColor.RESET;

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testPrintTwoParamsWithWhiteColorAndNoReset() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream, ConsoleColor.WHITE);

// Act: Print the message
String message = "Ma'am, as you said earlier, I am a sponge.";
printer.print(message, false);

String expectedOutput = ConsoleColor.WHITE + "Ma'am, as you said earlier, I am a sponge.";

// Assert: Verify the printed output
assertEquals(expectedOutput, outputStream.toString());
}

@Test
void testGetCurrentColor() {
// Arrange: Capture the printed output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);

ColorPrinter printer = new ColorPrinter(printStream);

// Act: Change the Color
printer.setCurrentColor(ConsoleColor.RED);

// Assert: Verify the color
assertEquals(ConsoleColor.RED, printer.getCurrentColor());
}
}
35 changes: 30 additions & 5 deletions src/TruffulaOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,36 @@ public boolean isUseColor() {
* @throws IllegalArgumentException if unknown arguments are provided or the path is missing
* @throws FileNotFoundException if the directory cannot be found or if the path points to a file
*/
public TruffulaOptions(String[] args) throws IllegalArgumentException, FileNotFoundException {
// TODO: Replace the below lines with your implementation
root = null;
showHidden = false;
useColor = false;
public TruffulaOptions(String[] args) throws IllegalArgumentException, FileNotFoundException
{
if (args == null) throw new IllegalArgumentException();

// Set up variables to check input
String path = "";
boolean hidden = false;
boolean color = true;

// Setting up path or throwing an exception
if (!args[args.length -1].equals("-nc") && !args[args.length - 1].equals("-h"))
{
path = args[args.length - 1];
}
else throw new IllegalArgumentException();

// Go through each input and set the flag variables
for (String option : args)
{
if (option.equals("-nc")) color = false;
else if (option.equals("-h")) hidden = true;
}

// Verify the input directory exists, then set the flags from the variables
File directory = new File(path);
if (!directory.isDirectory() || !directory.exists()) throw new FileNotFoundException();
else this.root = directory;
this.useColor = color;
this.showHidden = hidden;

}

/**
Expand Down
104 changes: 104 additions & 0 deletions src/TruffulaOptionsTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -26,4 +27,107 @@ void testValidDirectoryIsSet(@TempDir File tempDir) throws FileNotFoundException
assertTrue(options.isShowHidden());
assertFalse(options.isUseColor());
}

@Test
void testValidDirectoryPathFirst(@TempDir File tempDir) throws IllegalArgumentException, FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String directoryPath = directory.getAbsolutePath();
String[] args = {directoryPath, "-nc", "-h"};

// Assert: Check that its passing a IllegalArgument
assertThrows(IllegalArgumentException.class, () -> new TruffulaOptions(args));
}

@Test
void testInvalidDirectoryPath(@TempDir File tempDir) throws FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String directoryPath = directory.getAbsolutePath() + "/child";
String[] args = {"-nc", "-h", directoryPath};

// Assert: Check that its passing a IllegalArgument
assertThrows(FileNotFoundException.class, () -> new TruffulaOptions(args));
}

@Test
void testValidDirectoryHiddenThenNoColor(@TempDir File tempDir) throws FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String directoryPath = directory.getAbsolutePath();
String[] args = {"-h", "-nc", directoryPath};

// Act: Create TruffulaOptions instance
TruffulaOptions options = new TruffulaOptions(args);

// Assert: Check that the root directory is set correctly
assertEquals(directory.getAbsolutePath(), options.getRoot().getAbsolutePath());
assertTrue(options.isShowHidden());
assertFalse(options.isUseColor());
}

@Test
void testValidDirectoryNoColor(@TempDir File tempDir) throws FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String directoryPath = directory.getAbsolutePath();
String[] args = {"-nc", directoryPath};

// Act: Create TruffulaOptions instance
TruffulaOptions options = new TruffulaOptions(args);

// Assert: Check that the root directory is set correctly
assertEquals(directory.getAbsolutePath(), options.getRoot().getAbsolutePath());
assertFalse(options.isShowHidden());
assertFalse(options.isUseColor());
}

@Test
void testValidDirectory(@TempDir File tempDir) throws FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String directoryPath = directory.getAbsolutePath();
String[] args = {directoryPath};

// Act: Create TruffulaOptions instance
TruffulaOptions options = new TruffulaOptions(args);

// Assert: Check that the root directory is set correctly
assertEquals(directory.getAbsolutePath(), options.getRoot().getAbsolutePath());
assertFalse(options.isShowHidden());
assertTrue(options.isUseColor());
}

@Test
void testValidNoDirectory(@TempDir File tempDir) throws IllegalArgumentException, FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String[] args = {"-nc", "-h"};

// Assert: Check that its passing a IllegalArgument
assertThrows(IllegalArgumentException.class, () -> new TruffulaOptions(args));
}
@Test
void testInvalidArgs(@TempDir File tempDir) throws FileNotFoundException {
// Arrange: Prepare the arguments with the temp directory
File directory = new File(tempDir, "subfolder");
directory.mkdir();
String directoryPath = directory.getAbsolutePath();
String[] args = {"-hi", "", directoryPath};

// Act: Create TruffulaOptions instance
TruffulaOptions options = new TruffulaOptions(args);

// Assert: Check that the root directory is set correctly
assertEquals(directory.getAbsolutePath(), options.getRoot().getAbsolutePath());
assertFalse(options.isShowHidden());
assertTrue(options.isUseColor());
}

}
Loading