From 12b5e3d133120ba565211e1f98605a6b1eb9d56d Mon Sep 17 00:00:00 2001 From: Pawel Kruszewski Date: Fri, 13 Oct 2023 11:30:00 +0200 Subject: [PATCH] feat: initial commit for Java OpenSlava 2023 BalloonChallenge CodeFix --- .gitignore | 3 + README.adoc | 80 +++++++++++++++++++ README.md | 2 - pom.xml | 54 +++++++++++++ .../codefix/BalloonChallenge.java | 34 ++++++++ .../ableneo/openslava2023/donotfix/Order.java | 16 ++++ .../donotfix/OrderRepository.java | 15 ++++ .../openslava2023/donotfix/Product.java | 28 +++++++ .../codefix/BalloonChallengeTest.java | 40 ++++++++++ 9 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 README.adoc delete mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/sk/ableneo/openslava2023/codefix/BalloonChallenge.java create mode 100644 src/main/java/sk/ableneo/openslava2023/donotfix/Order.java create mode 100644 src/main/java/sk/ableneo/openslava2023/donotfix/OrderRepository.java create mode 100644 src/main/java/sk/ableneo/openslava2023/donotfix/Product.java create mode 100644 src/test/java/sk/ableneo/openslava2023/codefix/BalloonChallengeTest.java diff --git a/.gitignore b/.gitignore index 524f096..3e5565f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.idea/ +target/ +*.iml # Compiled class file *.class diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..14352ff --- /dev/null +++ b/README.adoc @@ -0,0 +1,80 @@ +== Win a Thrilling Balloon Flight at OpenSlava 2023! +:toc: + +*🎈 BalloonChallenge CodeFix 🎈* + +=== Welcome to the Skyward BalloonChallenge CodeFix Project! 🚀 + +=== 🎉 Win a Thrilling Balloon Flight! 🎉 + +Embark on a coding adventure and get the chance to soar high in the sky in a hot air balloon! 🌍🎈 This repository is the gateway to a challenge where your code-fixing skills could win you an unforgettable balloon flight experience. + +''' + +=== 🛠 Challenge Overview: + +==== The Task: + +* *Repair the Despair*: Dive into our code repository and get your hands on bugs, inefficiencies, and areas that need enhancement. + +* *Limited Time Magic*: Make meaningful contributions by fixing code within a specified time frame at ableneo booth. + +==== The Reward: + +* *Fly High*: The coder with the best fix will be awarded a spectacular hot air balloon flight. + +''' + +=== 🚀 How to Participate: + +. *Check in @ ableneo booth*: Visit ableneo booth and check in to the challenge. + +. *Code & Commit*: Implement your fix and commit your changes. + +. *Pull & Pray*: Make a pull request back to the original repository. Ensure your PR has a descriptive title and thorough explanation of the fixes made. + +. *Wait & See*: Judges will evaluate the solutions and announce the winner once the challenge ends. + +''' + +=== 🏆 Judging Criteria: + +* *Efficiency*: The simplicity and computational efficiency of your fix. + +* *Readability*: How clean and understandable your code is. + +* *Impact*: The significance of the bug/issue you resolved. + +* *Explanation*: The clarity of your explanation and documentation for the fix. + +* *Tests*: The tests suite passes. + +''' + +=== 📅 Important Dates: + +* *Coding stand*: @ableneo booth, OpenSlava 2023, *19.10.2023*, Bratislava, Slovakia https://www.openslava.sk/2023 + +* *Winners Unveiled*: Winner will be declared on *19.10.2023 16:30* at our ableneo booth. The winner will be contacted via email. + +''' + +=== 💌 Stay Connected: + +* *Ask Me Anything*: Reach out to us at out https://github.com/ableneo/ama[AMA] project for any questions or feedback. + +* *Issues*: Use the `Issues` tab for queries or to interact with the community. + +* *Social Media*: Join us on https://twitter.com/ableneo[Twitter] and https://www.linkedin.com/company/ableneoie/[LinkedIn] for more insights and updates. + +''' + +=== 📜 License: + +This project is licensed under the MIT License. See the link:LICENSE[LICENSE] file for details. + +''' + +🚀 *Join the BalloonChallenge CodeFix and let your coding skills take you to the skies!* 🎈 + +''' diff --git a/README.md b/README.md deleted file mode 100644 index 398e285..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# openslava-2023-BalloonChallenge-CodeFix- -Win a Thrilling Balloon Flight at OpenSlava 2023! diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0e5b02c --- /dev/null +++ b/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + sk.ableneo + BalloonChallenge + 0.1-SNAPSHOT + + sk.ableneo.openslava2023.codefix.BalloonChallenge-CodeFix + + + 17 + 17 + 5.10.0 + 5.6.0 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + org.mockito + mockito-junit-jupiter + ${mockito.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + diff --git a/src/main/java/sk/ableneo/openslava2023/codefix/BalloonChallenge.java b/src/main/java/sk/ableneo/openslava2023/codefix/BalloonChallenge.java new file mode 100644 index 0000000..9b3e0a3 --- /dev/null +++ b/src/main/java/sk/ableneo/openslava2023/codefix/BalloonChallenge.java @@ -0,0 +1,34 @@ +package sk.ableneo.openslava2023.codefix; + +import sk.ableneo.openslava2023.donotfix.Order; +import sk.ableneo.openslava2023.donotfix.OrderRepository; +import sk.ableneo.openslava2023.donotfix.Product; + +import java.util.ArrayList; +import java.util.LinkedList; + +// TODO: fix the class +public class BalloonChallenge { + + public LinkedList findOrdersForProduct(Product p, boolean debug) { + ArrayList l = new ArrayList(); + ArrayList list = getAllOrders(); + for (int i = 0; i < list.size(); i++) { + Order order = (Order) list.get(i); + boolean found = false; + if (order.getProducts().size() > 0) { + for (int j = 0; j <= order.getProducts().size(); j++) { + Product p2 = (Product) order.getProducts().get(j); + found = (p2 == p); + } + if (found && order != null) + l.add(order); + } + } + return new LinkedList(l); + } + + public ArrayList getAllOrders() { + return new ArrayList(OrderRepository.getAllOrders()); + } +} diff --git a/src/main/java/sk/ableneo/openslava2023/donotfix/Order.java b/src/main/java/sk/ableneo/openslava2023/donotfix/Order.java new file mode 100644 index 0000000..9c1dbae --- /dev/null +++ b/src/main/java/sk/ableneo/openslava2023/donotfix/Order.java @@ -0,0 +1,16 @@ +package sk.ableneo.openslava2023.donotfix; + +import java.util.ArrayList; +import java.util.List; + +public class Order { + private final List products = new ArrayList<>(); + + public Order(List products) { + this.products.addAll(products); + } + + public List getProducts() { + return products; + } +} diff --git a/src/main/java/sk/ableneo/openslava2023/donotfix/OrderRepository.java b/src/main/java/sk/ableneo/openslava2023/donotfix/OrderRepository.java new file mode 100644 index 0000000..f9fd5ee --- /dev/null +++ b/src/main/java/sk/ableneo/openslava2023/donotfix/OrderRepository.java @@ -0,0 +1,15 @@ +package sk.ableneo.openslava2023.donotfix; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class OrderRepository { + public static List getAllOrders() { + return Arrays.asList( + new Order(new ArrayList<>(Arrays.asList(new Product("hot air balloon")))), + new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))), + new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))) + ); + } +} diff --git a/src/main/java/sk/ableneo/openslava2023/donotfix/Product.java b/src/main/java/sk/ableneo/openslava2023/donotfix/Product.java new file mode 100644 index 0000000..7a278f5 --- /dev/null +++ b/src/main/java/sk/ableneo/openslava2023/donotfix/Product.java @@ -0,0 +1,28 @@ +package sk.ableneo.openslava2023.donotfix; + +public class Product { + private String name; + + public Product(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Product product = (Product) o; + + return getName().equals(product.getName()); + } + + @Override + public int hashCode() { + return getName().hashCode(); + } +} diff --git a/src/test/java/sk/ableneo/openslava2023/codefix/BalloonChallengeTest.java b/src/test/java/sk/ableneo/openslava2023/codefix/BalloonChallengeTest.java new file mode 100644 index 0000000..25c2fbe --- /dev/null +++ b/src/test/java/sk/ableneo/openslava2023/codefix/BalloonChallengeTest.java @@ -0,0 +1,40 @@ +package sk.ableneo.openslava2023.codefix; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import sk.ableneo.openslava2023.donotfix.Order; +import sk.ableneo.openslava2023.donotfix.Product; + +import java.util.ArrayList; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) +class BalloonChallengeTest { + + @Mock + private BalloonChallenge balloonChallenge; + + @BeforeEach + void setUp() { + when(balloonChallenge.getAllOrders()).thenReturn( + new ArrayList(Arrays.asList( + new Order(new ArrayList<>(Arrays.asList(new Product("hot air balloon")))), + new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))), + new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))) + )) + ); + when(balloonChallenge.findOrdersForProduct(any(),anyBoolean())).thenCallRealMethod(); + } + @Test + void findOrdersForProduct() { + assertEquals(1, balloonChallenge.findOrdersForProduct(new Product("hot air balloon"), false).size()); + assertEquals(2, balloonChallenge.findOrdersForProduct(new Product("gas balloon"), false).size()); + } +}