Skip to content

Commit

Permalink
Maven build Tool added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougnkong committed Dec 19, 2020
1 parent f0c030c commit 34c948c
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/
*.iml
*.iws
.DS_Store
log/
target/
16 changes: 12 additions & 4 deletions drinkAutomat.iml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand All @@ -23,5 +27,9 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.4.2" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.4.2" level="project" />
</component>
</module>
45 changes: 45 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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>groupId</groupId>
<artifactId>drinkAutomat</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
</dependency>
</dependencies>

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

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<!-- Build an executable JAR -->
<configuration>
<archive>
<manifest>
<mainClass>start_the_machine.StartDrinkMachine</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>

</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main.drinkautomat.common;
package common;

import main.drinkautomat.model.Coin;
import main.drinkautomat.model.CoinAndQuantity;
import model.Coin;
import model.CoinAndQuantity;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.drinkautomat.common;
package common;

/**
* The coin is initialised in cents.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.drinkautomat.common;
package common;

public class Drink extends ProductType {
public Drink(String name, double price) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main.drinkautomat.common;
package common;

public abstract class ProductType {
protected String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main.drinkautomat.model;
package model;

import main.drinkautomat.common.CoinValue;
import common.CoinValue;

public class Coin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main.drinkautomat.model;
package model;

import main.drinkautomat.common.CoinValue;
import common.CoinValue;

/**
* This class is used to store change coins.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main.drinkautomat.model;
package model;

import main.drinkautomat.common.ProductType;
import common.ProductType;

/**
* Generic class for compartment in the drink machine.
* Each compartment will take the name of specific drink.
*
* @param <T>
*/
public class Compartment<T extends ProductType> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main.drinkautomat.model;
package model;

import main.drinkautomat.common.CoinValue;
import main.drinkautomat.common.Drink;
import common.CoinValue;
import common.Drink;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main.drinkautomat.model;
package model;

import main.drinkautomat.common.Automat;
import main.drinkautomat.common.CoinValue;
import main.drinkautomat.common.Drink;
import common.Automat;
import common.CoinValue;
import common.Drink;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/start_the_machine/StartDrinkMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package start_the_machine;
public class StartDrinkMachine {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package main.drinkautomatTest;

import main.drinkautomat.common.CoinValue;
import main.drinkautomat.common.Drink;
import main.drinkautomat.model.*;
import common.CoinValue;
import common.Drink;
import model.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -12,7 +11,7 @@

import static org.junit.jupiter.api.Assertions.*;

public class testDrinkAutomat {
public class TestDrinkMachine {

public static final String COLA = "Cola";
public static final String BEER = "Beer";
Expand All @@ -28,7 +27,7 @@ public class testDrinkAutomat {
* And makes some initialization.
*/
@BeforeEach
private void init() {
public void init() {
cola = new Drink(COLA, 1.20);
beer = new Drink(BEER, 2);
colaCompartment = new Compartment<>(cola, 2);
Expand All @@ -44,7 +43,8 @@ private void init() {
*/
@Test
public void testReturnDrink() {
DrinkMachine drinkAutomat = new DrinkMachine(compartments);
init();
DrinkMachine drinkMachine = new DrinkMachine(compartments);
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.FIFTY_CENT));
inputCoins.add(new Coin(CoinValue.FIFTY_CENT));
Expand All @@ -53,11 +53,11 @@ public void testReturnDrink() {
CoinAndQuantity coin_50 = new CoinAndQuantity(CoinValue.FIFTY_CENT, 6);
CoinAndQuantity coin_20 = new CoinAndQuantity(CoinValue.TWENTY_CENT, 2);
CoinAndQuantity coin_10 = new CoinAndQuantity(CoinValue.TEN_CENT, 2);
drinkAutomat.addAvailableCoinForChange(coin_10);
drinkAutomat.addAvailableCoinForChange(coin_20);
drinkAutomat.addAvailableCoinForChange(coin_50);
drinkMachine.addAvailableCoinForChange(coin_10);
drinkMachine.addAvailableCoinForChange(coin_20);
drinkMachine.addAvailableCoinForChange(coin_50);

DrinkAndChange drinkAndChange = drinkAutomat.buy(beer, inputCoins);
DrinkAndChange drinkAndChange = drinkMachine.buy(beer, inputCoins);

assertEquals(beer.getName(), drinkAndChange.getDrinkName());
assertEquals(0, drinkAndChange.getChange().size());
Expand All @@ -73,6 +73,7 @@ public void testReturnDrink() {
*/
@Test
public void testReturnChange() {
init();
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.TWO_EURO));

Expand Down Expand Up @@ -108,7 +109,7 @@ public void testReturnChange() {
*/
@Test
public void testNoExistingDrink() {

init();
HashMap<String, Compartment> compartments = new HashMap<>();

List<Coin> inputCoins = new ArrayList<>();
Expand All @@ -126,6 +127,7 @@ public void testNoExistingDrink() {
*/
@Test
public void testNotEnoughCoinForDrink() {
init();
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.ONE_EURO));

Expand All @@ -143,6 +145,7 @@ public void testNotEnoughCoinForDrink() {
*/
@Test
public void testFillInChangeCoins() {
init();
List<Coin> inputCoins = new ArrayList<>();

inputCoins.add(new Coin(CoinValue.TEN_CENT));
Expand Down

0 comments on commit 34c948c

Please sign in to comment.