From 8e10d1a7446b303ae3b4b22181ebfe292f1e686d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Wed, 19 Jan 2022 11:15:40 +0100 Subject: [PATCH 01/11] feat: unit tests --- .../com/geekshubs/calculator/Calculator.java | 21 ++++++++++++++++ .../geekshubs/calculator/CalculatorTest.java | 25 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/main/java/com/geekshubs/calculator/Calculator.java b/src/main/java/com/geekshubs/calculator/Calculator.java index 9f099f2..11e690c 100644 --- a/src/main/java/com/geekshubs/calculator/Calculator.java +++ b/src/main/java/com/geekshubs/calculator/Calculator.java @@ -2,4 +2,25 @@ public class Calculator { + int _x; + int _y; + int _result; + + public Calculator(int x, int y, int result) { + _x = x; + _y = y; + _result = result; + } + + public int getX() { + return _x; + } + + public int getY() { + return _y; + } + + public int getResult() { + return _result; + } } diff --git a/src/test/java/com/geekshubs/calculator/CalculatorTest.java b/src/test/java/com/geekshubs/calculator/CalculatorTest.java index 32f3b9f..815f3a1 100644 --- a/src/test/java/com/geekshubs/calculator/CalculatorTest.java +++ b/src/test/java/com/geekshubs/calculator/CalculatorTest.java @@ -1,5 +1,30 @@ package com.geekshubs.calculator; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class CalculatorTest { + @Test + public void testSum() { + assertEquals(34, new Calculator(8, 26, 8 + 26).getResult()); + } + + @Test + public void testSub() { + assertEquals(4, new Calculator(12, 8, 12 - 8).getResult()); + } + + @Test + public void testMul() { + assertEquals(88, new Calculator(11, 8, 11 * 8).getResult()); + } + + @Test + public void testDiv() { + assertEquals(1, new Calculator(12, 12, 12 / 12).getResult()); + } } From 2aec5533c64b23271529a2c7a802633ff7e76da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Wed, 19 Jan 2022 11:29:07 +0100 Subject: [PATCH 02/11] feat: Continuous testing github actions --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++++++++ README.md | 18 +++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4aa72f5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: 'CI' + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + continuous-testing: + runs-on: ubuntu-latest + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + # Runs a single command using the runners shell + - name: Set up JDK 1.11 + uses: actions/setup-java@v2.5.0 + with: + java-version: '11' + distribution: 'zulu' + cache: 'maven' + - name: Compile + run: mvn compile + - name: Test + run: mvn verify + - name: Upload test results + uses: actions/upload-artifact@v2 # upload test results + if: success() || failure() # run this step even if previous step failed + with: + name: test-results + path: target/surefire-reports/TEST*.xml diff --git a/README.md b/README.md index 1433fac..bbf8b06 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,23 @@ $ ./mvnw clean test ## 2. Automatically Build and Test -**TODO** +[Github action ci](.github/workflows/ci.yml) step definition: +```yaml +steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + # Runs a single command using the runners shell + - name: Set up JDK 1.11 + uses: actions/setup-java@v2.5.0 + with: + java-version: '11' + distribution: 'zulu' + cache: 'maven' + - name: Compile + run: mvn compile + - name: Test + run: mvn verify +``` ## 3. Containerize Your Web App From 74c9779ba55c4f46ffe4098ae7d7ba3c7d5b84a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Wed, 19 Jan 2022 11:34:17 +0100 Subject: [PATCH 03/11] feat: Remove unused dependency --- pom.xml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/pom.xml b/pom.xml index 4453f86..e28fa82 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,6 @@ 3.9.0 3.2.0 2.22.2 - 0.8.7 @@ -71,25 +70,6 @@ - - org.jacoco - jacoco-maven-plugin - ${jacoco.maven.plugin.version} - - - - prepare-agent - - - - report - test - - report - - - - From efc32327b829b7c02e68b88de0592127b7017104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Wed, 19 Jan 2022 11:36:32 +0100 Subject: [PATCH 04/11] fix: Maven package application --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e28fa82..940c7c3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.geekshubs.javawebapp java-maven-calculator-web-app - war + jar 1.1-SNAPSHOT Calculator Web A Java Maven Calculator Web Application From 253523a65c73afbaf9906c5b9aca28a5818e0832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Wed, 19 Jan 2022 11:37:36 +0100 Subject: [PATCH 05/11] feat: Enable tests report parser --- .github/workflows/test-report.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/test-report.yml diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml new file mode 100644 index 0000000..0fe69f3 --- /dev/null +++ b/.github/workflows/test-report.yml @@ -0,0 +1,16 @@ +name: 'Test Report' +on: + workflow_run: + workflows: ['CI'] # runs after CI workflow + types: + - completed +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: dorny/test-reporter@v1 + with: + artifact: test-results # artifact name + name: Test Results # Name of the check run which will be created + path: '*.xml' # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results From 19a0ad2490c9a77644b71723ec36f028e94563b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Thu, 25 Jan 2024 22:39:05 +0100 Subject: [PATCH 06/11] feat: update ci workflow to build branches with main --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aa72f5..9b52002 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,9 +7,9 @@ name: 'CI' on: # Triggers the workflow on push or pull request events but only for the master branch push: - branches: [ master ] + branches: + - main pull_request: - branches: [ master ] jobs: continuous-testing: From 7e946b2d7526392619ec6ad3ea83e83f4e390b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Wed, 19 Jun 2024 20:24:14 +0200 Subject: [PATCH 07/11] chore: enable run workflow manually --- .github/workflows/ci.yml | 3 +++ .github/workflows/test-report.yml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b52002..bdf89d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ name: 'CI' # Controls when the action will run. on: + workflow_call: + workflow_dispatch: + # Triggers the workflow on push or pull request events but only for the master branch push: branches: diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml index 0fe69f3..5abf5eb 100644 --- a/.github/workflows/test-report.yml +++ b/.github/workflows/test-report.yml @@ -1,5 +1,7 @@ name: 'Test Report' on: + workflow_call: + workflow_dispatch: workflow_run: workflows: ['CI'] # runs after CI workflow types: From 16a96296f39660301c57f373f1ffccbe5e017340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Thu, 20 Jan 2022 23:28:46 +0000 Subject: [PATCH 08/11] feat: enable gitpod --- .gitpod.Dockerfile | 7 +++++++ .gitpod.yml | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 .gitpod.Dockerfile create mode 100644 .gitpod.yml diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 0000000..eb553cb --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,7 @@ +FROM gitpod/workspace-full + +USER gitpod + +RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \ + sdk install java 17.0.9-tem && \ + sdk default java 17.0.9-tem" diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..0c92254 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,24 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +image: + file: .gitpod.Dockerfile + +tasks: + - init: mvn package -DskipTests=false + +vscode: + extensions: + - redhat.java + - vscjava.vscode-java-debug + - vscjava.vscode-maven + +# Ports to expose on workspace startup +ports: + - port: 8080 + onOpen: open-preview + name: Calculator API + description: Calculator API init + visibility: private + protocol: http From b15b3995fd84ce960cb27b126f0cf0601f266b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Fri, 21 Jun 2024 14:52:14 +0000 Subject: [PATCH 09/11] feat: update calculator requirements --- README.md | 1 + .../java/com/geekshubs/calculator/CalculatorTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbf8b06..6ba5d2b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Create calculator App * Substract: substract two numbers and return result * Multiply: multiply two numbers and return result * Divide: divide two numbers and return result + * divide by zero should return error message ## System requirements diff --git a/src/test/java/com/geekshubs/calculator/CalculatorTest.java b/src/test/java/com/geekshubs/calculator/CalculatorTest.java index 815f3a1..93e8871 100644 --- a/src/test/java/com/geekshubs/calculator/CalculatorTest.java +++ b/src/test/java/com/geekshubs/calculator/CalculatorTest.java @@ -2,9 +2,8 @@ import org.junit.jupiter.api.Test; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class CalculatorTest { @@ -27,4 +26,9 @@ public void testMul() { public void testDiv() { assertEquals(1, new Calculator(12, 12, 12 / 12).getResult()); } + + @Test + public void testDivByZero() { + assertThrows(ArithmeticException.class, () -> new Calculator(12, 0, 12 / 0).getResult()); + } } From e63a8464992a6cbf79f965f6ac0e65aec1dfb703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Fri, 21 Jun 2024 14:57:16 +0000 Subject: [PATCH 10/11] chore: enable test execution on ci --- .github/workflows/ci.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdf89d7..85fa07b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,21 +20,20 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # Runs a single command using the runners shell - - name: Set up JDK 1.11 - uses: actions/setup-java@v2.5.0 + - name: Set up JDK 1.17 + uses: actions/setup-java@v4 with: - java-version: '11' - distribution: 'zulu' + java-version: '17' + distribution: 'temu' cache: 'maven' - name: Compile run: mvn compile - name: Test run: mvn verify - - name: Upload test results - uses: actions/upload-artifact@v2 # upload test results - if: success() || failure() # run this step even if previous step failed + - uses: dorny/test-reporter@v1 with: - name: test-results - path: target/surefire-reports/TEST*.xml + name: Test Results + path: 'target/**/TEST*.xml' + reporter: java-junit From e917b1971c31f44a849f6e365d362d90a5dcece0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Fri, 21 Jun 2024 14:59:16 +0000 Subject: [PATCH 11/11] chore: update jdk distribution --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85fa07b..7679f0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,9 @@ jobs: - name: Set up JDK 1.17 uses: actions/setup-java@v4 with: - java-version: '17' - distribution: 'temu' - cache: 'maven' + distribution: "liberica" + java-version: "17" + cache: "maven" - name: Compile run: mvn compile - name: Test @@ -35,5 +35,5 @@ jobs: - uses: dorny/test-reporter@v1 with: name: Test Results - path: 'target/**/TEST*.xml' + path: "target/**/TEST*.xml" reporter: java-junit