Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Nov 16, 2023
1 parent f298aaa commit 067e45b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Java CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 19
- run: ./mvnw clean test
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
<version>${jbock.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<repositories>
Expand Down Expand Up @@ -73,6 +80,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>
</project>
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/net/jbock/cp/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,44 @@
import net.jbock.Option;
import net.jbock.Parameter;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.Optional;
import java.util.StringJoiner;

/**
* Copy SOURCE to DEST
*/
@Command(name = "cp")
abstract class Args {
interface Args {

/**
* Path or file of directory to copy.
* @return SOURCE
*/
@Parameter(index = 0)
abstract Path source();
Path source();

/**
* Copy destination
* @return DEST
*/
@Parameter(index = 1)
abstract Path dest();
Path dest();

/**
* Copy directories recursively
*/
@Option(names = {"--recursive", "-r"})
abstract boolean recursive();
boolean recursive();

/**
* Make a backup of each existing destination file
*/
@Option(names = {"--backup", "-b"})
abstract boolean backup();
boolean backup();

/**
* Override the usual backup suffix
*/
@Option(names = {"--suffix", "-s"})
abstract Optional<String> suffix();
Optional<String> suffix();
}
16 changes: 16 additions & 0 deletions src/test/java/net/jbock/cp/ArgsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.jbock.cp;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ArgsTest {

@Test
void testPrint() {
Args result = new ArgsParser().parse(List.of("1", "2", "-rbs12")).getRight().orElseThrow();
assertEquals("{recursive: true, backup: true, suffix: Optional[12], source: 1, dest: 2}", result.toString());
}
}

0 comments on commit 067e45b

Please sign in to comment.