Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Katherine Soohoo committed Apr 24, 2024
0 parents commit 323bd58
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>edu.sjsu</groupId>
<artifactId>devopslab-java</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
9 changes: 9 additions & 0 deletions src/main/java/edu/sjsu/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions src/main/java/edu/sjsu/NameChecker.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
73 changes: 73 additions & 0 deletions src/test/java/edu/sjsu/NameCheckerTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit 323bd58

Please sign in to comment.