feat(cli): set up project structure and main entry point (#1)

- Create Main.java with picocli integration and testable run() method
- Create BarnCommand as root command with all subcommands registered
- Add placeholder subcommands: run, status, describe, kill, clean, service, config
- Update package structure from org.media.samson to com.samsonmedia.barn
- Configure checkstyle to allow underscores in test method names
- Add comprehensive tests for all CLI commands (26 tests, 80%+ coverage)

Closes #1

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Daniel SamsonandClaude Opus 4.5 committed 2026-01-21 12:53:54 +00:00
1 parent e861e12058
commit 05937b1f7e
14 files changed
+609 -28

No files matched your search

@@ -0,0 +1,91 @@
package com.samsonmedia.barn;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Tests for the Main entry point.
*/
class MainTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
private final PrintStream originalErr = System.err;
@BeforeEach
void setUpStreams() {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
}
@AfterEach
void restoreStreams() {
System.setOut(originalOut);
System.setErr(originalErr);
}
@Test
void run_withHelpFlag_shouldReturnZeroExitCode() {
// Arrange & Act
int exitCode = Main.run(new String[]{"--help"});
// Assert
assertThat(exitCode).isZero();
}
@Test
void run_withVersionFlag_shouldReturnZeroExitCode() {
// Arrange & Act
int exitCode = Main.run(new String[]{"--version"});
// Assert
assertThat(exitCode).isZero();
}
@Test
void run_withNoArgs_shouldReturnZeroExitCode() {
// Arrange & Act
int exitCode = Main.run(new String[]{});
// Assert
assertThat(exitCode).isZero();
}
@Test
void run_withInvalidCommand_shouldReturnNonZeroExitCode() {
// Arrange & Act
int exitCode = Main.run(new String[]{"nonexistent-command"});
// Assert
assertThat(exitCode).isNotZero();
}
@Test
void run_withHelpFlag_shouldPrintUsageToStdout() {
// Arrange & Act
Main.run(new String[]{"--help"});
// Assert
String output = outContent.toString();
assertThat(output).contains("barn");
assertThat(output).contains("Usage:");
}
@Test
void run_withVersionFlag_shouldPrintVersionToStdout() {
// Arrange & Act
Main.run(new String[]{"--version"});
// Assert
String output = outContent.toString();
assertThat(output).contains("barn");
assertThat(output).contains("0.1.0");
}
}
@@ -0,0 +1,252 @@
package com.samsonmedia.barn.cli;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
/**
* Tests for the root BarnCommand.
*/
class BarnCommandTest {
private CommandLine commandLine;
private StringWriter outWriter;
private StringWriter errWriter;
@BeforeEach
void setUp() {
commandLine = new CommandLine(new BarnCommand());
outWriter = new StringWriter();
errWriter = new StringWriter();
commandLine.setOut(new PrintWriter(outWriter));
commandLine.setErr(new PrintWriter(errWriter));
}
@Test
void help_shouldDisplayCommandName() {
// Arrange & Act
commandLine.execute("--help");
// Assert
String output = outWriter.toString();
assertThat(output).contains("barn");
}
@Test
void help_shouldDisplayDescription() {
// Arrange & Act
commandLine.execute("--help");
// Assert
String output = outWriter.toString();
assertThat(output).contains("Cross-platform job daemon");
}
@Test
void help_shouldListSubcommands() {
// Arrange & Act
commandLine.execute("--help");
// Assert
String output = outWriter.toString();
assertThat(output).contains("run");
assertThat(output).contains("status");
assertThat(output).contains("describe");
assertThat(output).contains("kill");
assertThat(output).contains("clean");
assertThat(output).contains("service");
assertThat(output).contains("config");
}
@Test
void version_shouldDisplayVersionNumber() {
// Arrange & Act
commandLine.execute("--version");
// Assert
String output = outWriter.toString();
assertThat(output).contains("0.1.0");
}
@Test
void noArgs_shouldShowUsage() {
// Arrange & Act
int exitCode = commandLine.execute();
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Usage:");
}
@Test
void invalidSubcommand_shouldReturnNonZeroExitCode() {
// Arrange & Act
int exitCode = commandLine.execute("nonexistent");
// Assert
assertThat(exitCode).isNotZero();
}
@Test
void runSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("run", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("run");
}
@Test
void statusSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("status", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("status");
}
@Test
void describeSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("describe", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("describe");
}
@Test
void killSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("kill", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("kill");
}
@Test
void cleanSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("clean", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("clean");
}
@Test
void serviceSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("service", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("service");
}
@Test
void configSubcommand_shouldExist() {
// Arrange & Act
int exitCode = commandLine.execute("config", "--help");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("config");
}
@Test
void runSubcommand_shouldShowNotImplementedMessage() {
// Arrange & Act
int exitCode = commandLine.execute("run");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Run command not yet implemented");
}
@Test
void statusSubcommand_shouldShowNotImplementedMessage() {
// Arrange & Act
int exitCode = commandLine.execute("status");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Status command not yet implemented");
}
@Test
void describeSubcommand_shouldShowNotImplementedMessage() {
// Arrange & Act
int exitCode = commandLine.execute("describe");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Describe command not yet implemented");
}
@Test
void killSubcommand_shouldShowNotImplementedMessage() {
// Arrange & Act
int exitCode = commandLine.execute("kill");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Kill command not yet implemented");
}
@Test
void cleanSubcommand_shouldShowNotImplementedMessage() {
// Arrange & Act
int exitCode = commandLine.execute("clean");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Clean command not yet implemented");
}
@Test
void serviceSubcommand_shouldShowUsageByDefault() {
// Arrange & Act
int exitCode = commandLine.execute("service");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Usage:");
assertThat(output).contains("service");
}
@Test
void configSubcommand_shouldShowUsageByDefault() {
// Arrange & Act
int exitCode = commandLine.execute("config");
// Assert
assertThat(exitCode).isZero();
String output = outWriter.toString();
assertThat(output).contains("Usage:");
assertThat(output).contains("config");
}
}