tdd : inventoryHelper test
This commit is contained in:
@@ -13,8 +13,4 @@ public class Inventory {
|
||||
private InventoryTypeEnum type;
|
||||
private int capacity;
|
||||
private int current;
|
||||
|
||||
public int getUsableCapa() {
|
||||
return this.capacity - this.current;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.inventorytdd;
|
||||
|
||||
public class InventoryHelper {
|
||||
|
||||
public Inventory createInventory() {
|
||||
return new Inventory();
|
||||
}
|
||||
|
||||
public int getUsableCapa(Inventory inventory) {
|
||||
return inventory.getCapacity() - inventory.getCurrent();
|
||||
}
|
||||
|
||||
public boolean inbound(Inventory inventory, int count) {
|
||||
if (isInboundable(inventory, count)) {
|
||||
inventory.setCurrent(inventory.getCurrent() + count);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInboundable(Inventory inventory, int count) {
|
||||
return getUsableCapa(inventory) >= count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.example.inventorytdd;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class InventoryHelperTests {
|
||||
|
||||
@Test
|
||||
void inventoryHelper_getUsableCapa_test() {
|
||||
InventoryHelper inventoryHelper = new InventoryHelper();
|
||||
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.setCapacity(10);
|
||||
inventory.setCurrent(5);
|
||||
|
||||
int usableCapa = inventoryHelper.getUsableCapa(inventory);
|
||||
assertEquals(5, usableCapa);
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventoryHelper_inbound_true() {
|
||||
InventoryHelper inventoryHelper = new InventoryHelper();
|
||||
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.setCapacity(40);
|
||||
|
||||
assertTrue(inventoryHelper.inbound(inventory, 10));
|
||||
assertEquals(10, inventory.getCurrent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventoryHelper_inbound_false() {
|
||||
InventoryHelper inventoryHelper = new InventoryHelper();
|
||||
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.setCapacity(10);
|
||||
|
||||
assertFalse(inventoryHelper.inbound(inventory, 40));
|
||||
assertEquals(0, inventory.getCurrent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventoryHelper_isInboundable_true() {
|
||||
InventoryHelper inventoryHelper = new InventoryHelper();
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.setCapacity(10);
|
||||
inventory.setCurrent(5);
|
||||
|
||||
assertTrue(inventoryHelper.isInboundable(inventory, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventoryHelper_isInboundable_false() {
|
||||
InventoryHelper inventoryHelper = new InventoryHelper();
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.setCapacity(10);
|
||||
inventory.setCurrent(5);
|
||||
|
||||
assertFalse(inventoryHelper.isInboundable(inventory, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventoryHelper_createInventory() {
|
||||
InventoryHelper inventoryHelper = new InventoryHelper();
|
||||
Inventory inventory = inventoryHelper.createInventory();
|
||||
|
||||
assertNotNull(inventory);
|
||||
}
|
||||
}
|
||||
@@ -42,13 +42,4 @@ public class InventoryTests {
|
||||
|
||||
assertEquals(5, inventory.getCurrent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventory_usableCapa_test() {
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.setCapacity(10);
|
||||
inventory.setCurrent(5);
|
||||
|
||||
assertEquals(5, inventory.getUsableCapa());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,10 @@
|
||||
[v] 현재 저장된 수량을 알 수 있어야 한다.
|
||||
[v] Inventory 의 타입을 Enum 값으로 만든다.
|
||||
[v] 앞으로 저장 가능한 수량을 알 수 있어야 한다.
|
||||
[] InventoryHelper 클래스 생성
|
||||
[] Capacity 이상으로 입고 되는 것을 방지한다.
|
||||
[v] InventoryHelper 클래스 생성
|
||||
[v] InventoryHelper 클래스에서 사용 가능한 용량을 알아낸다.
|
||||
[v] InventoryHelper -> 입고 가능 여부를 확인한다.
|
||||
[v] InventoryHelper -> Capacity 이상으로 입고 되는 것을 방지한다.
|
||||
[v] InventoryHelper -> 입고를 시킨다.
|
||||
[v] InventoryHelper -> Inventory 를 생성한다.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user