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
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 2c1db0155..368d03f67 100644
--- a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java
+++ b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java
@@ -13,6 +13,16 @@ public class Invoice {
private Map products =
new HashMap<>();
+ private static int invoiceNumberNext = 1;
+ private int invoiceNumber;
+
+ public Invoice() {
+ this.invoiceNumber = invoiceNumberNext++;
+ }
+
+ public int getInvoiceNumber() {
+ return invoiceNumber;
+ }
public void addProduct(Product product) {
@@ -48,6 +58,17 @@ public BigDecimal getTax() {
}
+ public String getProductList() {
+ String productList = "Numer faktury: " + invoiceNumber + "\n";
+
+ for (Product product : products.keySet()) {
+ productList += product.getName() + "," + products.get(product) + ", " + product.getPrice() + "\n";
+ }
+ productList += "Liczba pozycji: " + products.size();
+
+ return productList;
+ }
+
public BigDecimal getTotal() {
BigDecimal value = BigDecimal.ZERO;
for (Product product : this.products.keySet()) {
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 7f4b6f795..d20a48e71 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,30 @@ public void testInvoiceWithNegativeQuantity() {
public void testAddingNullProduct() {
invoice.addProduct(null);
}
+
+ @Test
+ public void testProductListContainsInvoiceNumber() {
+ invoice.addProduct(new TaxFreeProduct("Chleb", new BigDecimal("5")), 2);
+
+ String productList = invoice.getProductList();
+
+ Assert.assertTrue(productList.contains("Numer faktury: " + invoice.getInvoiceNumber()));
+ }
+
+ @Test
+ public void testProductListContainsProductNameQuantityAndPrice() {
+ invoice.addProduct(new TaxFreeProduct("Chleb", new BigDecimal("5")), 2);
+ String productList = invoice.getProductList();
+ Assert.assertTrue(productList.contains("Chleb"));
+ Assert.assertTrue(productList.contains("2"));
+ Assert.assertTrue(productList.contains("5"));
+ }
+
+ @Test
+ public void testProductListContainsNumberOfPositions() {
+ invoice.addProduct(new TaxFreeProduct("Chleb", new BigDecimal("5")), 2);
+ invoice.addProduct(new DairyProduct("Pinezka", new BigDecimal("10")), 3);
+ String productList = invoice.getProductList();
+ Assert.assertTrue(productList.contains("Liczba pozycji: 2"));
+ }
}