diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml new file mode 100644 index 0000000..3ed6a29 --- /dev/null +++ b/.github/workflows/java.yml @@ -0,0 +1,38 @@ +# Name of the workflow +name: DevOps Lab - Java + +# Specifies what triggers the workflow +on: [push] + +# Jobs to run in the workflow +jobs: + # First job to run in the workflow + build: + # Define the type of machine for the job to run on + runs-on: ubuntu-latest + # Sequence of steps to run + steps: + # Checkout the repository + - name: Checkout + uses: actions/checkout@v4 + # Setup environment + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + cache: maven + # Verify tools + - name: Verify Java version + run: java -version + - name: Verify Maven version + run: mvn -version + # TODO: Build application with Maven + - name: Build with Maven + run: echo '🛠️ build me please 🛠️' + # Upload artifacts + - name: Archive + uses: actions/upload-artifact@v4 + with: + name: JAR + path: target/*.jar \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b0752ef --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# DevOpsLab - Java + +A sample Java project to try out DevOps with GitHub Actions. + +## Prerequisites + +- Java 17+ +- Maven 3+ + +## Build + +``` +mvn clean package +``` +* Removes files from previous builds +* Compiles source code +* Runs tests +* Packages compiled code into a JAR + +For more information about Maven's build lifecycle, see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f3e0419 --- /dev/null +++ b/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + edu.sjsu + devopslab-java + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + UTF-8 + + + + + org.junit.jupiter + junit-jupiter-api + 5.10.2 + test + + + + \ No newline at end of file diff --git a/src/main/java/edu/sjsu/Main.java b/src/main/java/edu/sjsu/Main.java new file mode 100644 index 0000000..97397e5 --- /dev/null +++ b/src/main/java/edu/sjsu/Main.java @@ -0,0 +1,9 @@ +package edu.sjsu; + +public class Main { + public static void main(String[] args) { + boolean result = NameChecker.check(args[0]); + + System.out.println("Result: " + result); + } +} \ No newline at end of file diff --git a/src/main/java/edu/sjsu/NameChecker.java b/src/main/java/edu/sjsu/NameChecker.java new file mode 100644 index 0000000..5c262c6 --- /dev/null +++ b/src/main/java/edu/sjsu/NameChecker.java @@ -0,0 +1,18 @@ +package edu.sjsu; + +public class NameChecker { + /** + * Checks if a given string is a valid name following these rules: + * - Between 2 to 40 characters + * - Contains only alphabetic characters, non-consecutive hyphens, or a single quote + * - Cannot start with a hyphen or single quote + * + * @param input Name to check + * @return True if input is a valid name, else false + */ + public static boolean check(String input) { + // TODO: implement + + return false; + } +} diff --git a/src/test/java/edu/sjsu/NameCheckerTest.java b/src/test/java/edu/sjsu/NameCheckerTest.java new file mode 100644 index 0000000..77e7de1 --- /dev/null +++ b/src/test/java/edu/sjsu/NameCheckerTest.java @@ -0,0 +1,73 @@ +package edu.sjsu; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public class NameCheckerTest { + + @Test + public void testValidName() { + assertTrue(NameChecker.check("John")); + } + + @Test + public void testInvalidNameWithSpecialCharacter() { + assertFalse(NameChecker.check("John$")); + } + + @Test + public void testInvalidNameWithNumbers() { + assertFalse(NameChecker.check("John123")); + } + + @Test + public void testValidNameWithApostrophe() { + assertTrue(NameChecker.check("O'Brien")); + } + + @Test + public void testValidNameWithHyphen() { + assertTrue(NameChecker.check("Smith-Jones")); + } + + @Test + public void testInvalidNameWithTooManyCharacters() { + assertFalse(NameChecker.check("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); + } + + @Test + public void testInvalidNameWithDoubleHyphen() { + assertFalse(NameChecker.check("John--Doe")); + } + + @Test + public void testInvalidNameWithQuotes() { + assertFalse(NameChecker.check("'John'")); + } + + @Test + public void testValidNameWithQuotesWithinAllowedLength() { + assertTrue(NameChecker.check("O'Neil")); + } + + @Test + public void testInvalidNameWithQuotesBeyondAllowedLength() { + assertFalse(NameChecker.check("O'Connolly'")); + } + + @Test + public void testInvalidNameWithSpaces() { + assertFalse(NameChecker.check("John Smith")); + } + + @Test + public void testInvalidNameWithFirstCharacterHyphen() { + assertFalse(NameChecker.check("-John")); + } + + public void testInvalidNameWithFirstCharacterApostrophe() { + assertFalse(NameChecker.check("'John")); + } +}