From 2f9283890a99393e48275f936d461505c8a4107e Mon Sep 17 00:00:00 2001 From: Tomasz Wincencik Date: Sat, 11 Apr 2026 11:43:21 +0200 Subject: [PATCH 1/2] Adding the CI file: .github/workflows/github-actions.yml --- .github/workflows/github-actions.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 000000000..8fb587348 --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,15 @@ +name: CI for Java Invoice +on: [push] +jobs: + test: + name: Unit tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'adopt' + - name: Test + run: mvn test \ No newline at end of file From fa5dca66e02649c180f26e055b677c5361599e2d Mon Sep 17 00:00:00 2001 From: Tomasz Wincencik Date: Sat, 11 Apr 2026 13:24:02 +0200 Subject: [PATCH 2/2] Adding the checkstyle and Task0 --- checkstyle.xml | 298 ++++++++++++++++++ pom.xml | 18 ++ .../java/pl/edu/agh/mwo/invoice/Invoice.java | 13 + .../pl/edu/agh/mwo/invoice/InvoiceTest.java | 18 ++ 4 files changed, 347 insertions(+) create mode 100644 checkstyle.xml diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 000000000..fbcd05132 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2d40c3e8a..ed8c7a138 100644 --- a/pom.xml +++ b/pom.xml @@ -41,4 +41,22 @@ 1.3 + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.6.0 + + + + checkstyle + + + + + + + diff --git a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java index 72f4048d5..60e09a4b4 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java @@ -3,6 +3,7 @@ import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; +import java.util.Random; import pl.edu.agh.mwo.invoice.product.Product; @@ -41,4 +42,16 @@ public BigDecimal getGrossTotal() { } return totalGross; } + + static int NUMBER = 0; + private int number; + + public Invoice() { + this.number = NUMBER++; + } + + public int getNumber() { + + return number; + } } diff --git a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java index 50513171c..8eab23659 100644 --- a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java +++ b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java @@ -125,4 +125,22 @@ public void testInvoiceWithNegativeQuantity() { public void testAddingNullProduct() { invoice.addProduct(null); } + + @Test + public void testInvoiceHasNumberGreaterThamZero() { + int number = invoice.getNumber(); + Assert.assertThat(number, Matchers.greaterThanOrEqualTo(0));} + + public void testTwoInvoicesHaveDifferentNumbers() { + Invoice invoice1 = new Invoice(); + Invoice invoice2 = new Invoice(); + Assert.assertNotEquals(invoice1.getNumber(), invoice2.getNumber()); + } + + public void testInvoiceHasConsequentNumbers() { + Invoice invoice1 = new Invoice(); + Invoice invoice2 = new Invoice(); + Assert.assertEquals(invoice1.getNumber(), invoice2.getNumber()-1); + } + }