Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add junit testing suite #4

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ProductInventoryLab.iml

This file was deleted.

10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
<artifactId>ProductInventoryLab</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/models/Sneaker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package models;

public class Sneaker {

private int id;
private String name;
private String brand;
private String sport;
private float size;
private int qty;
private float price;

public Sneaker(int id, String name, String brand, String sport, float size, int quantity, float price){
this.id = id;
this.name = name;
this.brand = brand;
this.sport = sport;
this.size = size;
this.qty = quantity;
this.price = price;
}

public void setName(String name) { this.name = name;}

public String getName() { return this.name; }

public String getBrand() { return this.brand; }

public void setBrand(String brand) { this.brand = brand; }

public void setSport(String sport) { this.sport = sport; }

public String getSport() { return this.sport; }

public float getSize() { return this.size; }

public void setSize(float size) { this.size = size; }

public int getQty() { return this.qty; }

public void setQty(int qty) { this.qty = qty; }

public float getPrice() { return this.price; }

public void setPrice(float price) { this.price = price; }

public int getId() { return this.id; }
}
37 changes: 37 additions & 0 deletions src/main/java/models/Whiskey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package models;

public class Whiskey {

private String brand;
private int id;
private int qty;
private float price;



public Whiskey(String brand, int id, int quantity, float price){
this.brand = brand;
this.id = id;
this.qty = quantity;
this.price = price;
}

public String getBrand() { return this.brand; }

public void setBrand(String brand) { this.brand = brand; }

public int getQty() { return this.qty; }

public void setQty(int qty) { this.qty = qty; }

public int getId() { return this.id; }

public void setId(int id) { this.id = id; }
public float getPrice() {
return this.price;
}

public void setPrice(float price) {
this.price = price;
}
}
24 changes: 24 additions & 0 deletions src/main/java/services/SneakerService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package services;

import models.Sneaker;

import java.util.ArrayList;

public class SneakerService {

private static int nextId = 1;
private ArrayList<Sneaker> inventory = new ArrayList<>();


public Sneaker create(String name, String brand, String sport, float size, int quantity, float price) {

// (2)
Sneaker createdSneaker = new Sneaker(nextId++, name, brand, sport, size, quantity, price);

// (3)
inventory.add(createdSneaker);

// (4)
return createdSneaker;
}
}
24 changes: 24 additions & 0 deletions src/main/java/services/WhiskeyService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package services;

import models.Whiskey;

import java.util.ArrayList;

public class WhiskeyService {

private static int nextId = 1;
private ArrayList<Whiskey> inventory = new ArrayList<>();


public Whiskey create(String brand, int quantity, float price) {

// (2)
Whiskey createdWhiskey = new Whiskey(brand, nextId++ ,quantity, price);

// (3)
this.inventory.add(createdWhiskey);

// (4)
return createdWhiskey;
}
}
86 changes: 86 additions & 0 deletions src/test/java/models/SneakerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package models;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SneakerTest {

int expectedId = 6;
String expectedName = "Stan Smith";
String expectedBrand = "Adidas";
String expectedSport = "Tennnis";
float expectedSize = 10.5f;
int expectedQty = 10;
float expectedPrice = 80.00f;

Sneaker testSneaker = new Sneaker(expectedId,expectedName,expectedBrand,expectedSport,expectedSize,expectedQty,expectedId);

@Test
public void testSetGetName() {
String expected = "oleg";

testSneaker.setName(expected);
Assertions.assertEquals(expected, testSneaker.getName());

}

@Test
public void testSetGetBrand() {
String expected = "valentin";

testSneaker.setBrand(expected);
Assertions.assertEquals(expected, testSneaker.getBrand());

}

@Test
public void testSetGetSize(){
float expected = 23f;

testSneaker.setSize(expected);
Assertions.assertEquals(expected,testSneaker.getSize());
}

@Test
public void testSetGetQty(){
int expected = 32;

testSneaker.setQty(expected);
Assertions.assertEquals(expected,testSneaker.getQty());
}

@Test
public void testSetGetPrice(){
float expected = 120.00f;

testSneaker.setPrice(expected);
Assertions.assertEquals(expected,testSneaker.getPrice());
}

@Test
public void testSetGetSport(){
String expected = "Soccer";

testSneaker.setSport(expected);
Assertions.assertEquals(expected,testSneaker.getSport());
}

@Test // (1)
public void constructorTest(){

// (2)


// (3)
Sneaker testSneaker = new Sneaker(expectedId, expectedName, expectedBrand,
expectedSport, expectedSize, expectedQty,expectedPrice);

// (4)
Assertions.assertEquals(expectedId, testSneaker.getId());
Assertions.assertEquals(expectedName, testSneaker.getName());
Assertions.assertEquals(expectedBrand, testSneaker.getBrand());
Assertions.assertEquals(expectedSport, testSneaker.getSport());
Assertions.assertEquals(expectedQty, testSneaker.getQty());
Assertions.assertEquals(expectedPrice, testSneaker.getPrice());
}
}
48 changes: 48 additions & 0 deletions src/test/java/models/WhiskeyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package models;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;


public class WhiskeyTest {

private String expectedBrand = "Johnny";
private int expectedId = 1;
private int expectedQty = 2;
private float expectedPrice = 50f;
Whiskey testWhiskey = new Whiskey(expectedBrand,expectedId,expectedQty,expectedPrice);

@Test
public void testSetGetBrand() {
String expected = "valentin";

testWhiskey.setBrand(expected);
Assertions.assertEquals(expected, testWhiskey.getBrand());

}

@Test
public void testSetGetQty(){
int expected = 32;

testWhiskey.setQty(expected);
Assertions.assertEquals(expected,testWhiskey.getQty());
}

@Test
public void testSetGetId(){
int expected = 32097;

testWhiskey.setId(expected);
Assertions.assertEquals(expected,testWhiskey.getId());
}

@Test
public void testConstructor(){
Whiskey newTest = new Whiskey(expectedBrand,expectedId,expectedQty,expectedPrice);
Assertions.assertEquals(expectedPrice,testWhiskey.getPrice());
Assertions.assertEquals(expectedBrand,testWhiskey.getBrand());
Assertions.assertEquals(expectedId,testWhiskey.getId());
Assertions.assertEquals(expectedQty,testWhiskey.getQty());
}
}
43 changes: 43 additions & 0 deletions src/test/java/services/SneakerServicesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package services;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import models.Sneaker;

public class SneakerServicesTest {
@Test
public void createTest(){

// (1)
String expectedName = "Stan Smith";
String expectedBrand = "Adidas";
String expectedSport = "Tennis";
float expectedSize = 10.5f;
int expectedQty = 10;
float expectedPrice = 80.00f;

// (2)
SneakerService sneakerService = new SneakerService();
Sneaker testSneaker = sneakerService.create(expectedName, expectedBrand,
expectedSport, expectedSize, expectedQty, expectedPrice);

// (3)
int actualId = testSneaker.getId();
String actualName = testSneaker.getName();
String actualBrand = testSneaker.getBrand();
String actualSport = testSneaker.getSport();
float actualSize = testSneaker.getSize();
int actualQty = testSneaker.getQty();
float actualPrice = testSneaker.getPrice();

// (4)
Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName());
Assertions.assertEquals(expectedName, actualName);
Assertions.assertEquals(expectedBrand, actualBrand);
Assertions.assertEquals(expectedSport, actualSport);
Assertions.assertEquals(expectedSize, actualSize);
Assertions.assertEquals(expectedQty, actualQty);
Assertions.assertEquals(expectedPrice, actualPrice);

}
}
33 changes: 33 additions & 0 deletions src/test/java/services/WhiskeyServicesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package services;

import models.Whiskey;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class WhiskeyServicesTest {
@Test
public void createTest() {

// (1)
String expectedBrand = "Johnny";
int expectedQty = 10;
float expectedPrice = 80.00f;

// (2)
WhiskeyService whiskeyService = new WhiskeyService();
Whiskey testWhiskey = whiskeyService.create(expectedBrand, expectedQty, expectedPrice);

// (3)
int actualId = testWhiskey.getId();
String actualBrand = testWhiskey.getBrand();
int actualQty = testWhiskey.getQty();
float actualPrice = testWhiskey.getPrice();

// (4)
Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName());
Assertions.assertEquals(expectedBrand, actualBrand);
Assertions.assertEquals(expectedQty, actualQty);
Assertions.assertEquals(expectedPrice, actualPrice);

}
}