From 8dc331d93181ffa985e2cd133f3d8b417f51bc62 Mon Sep 17 00:00:00 2001 From: anuradha Date: Sun, 15 Aug 2021 11:08:39 +0530 Subject: [PATCH] Added a unit test --- .../hexagon/HexagonApplicationTests.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/hexagon/src/test/java/com/baeldung/hexagon/HexagonApplicationTests.java b/hexagon/src/test/java/com/baeldung/hexagon/HexagonApplicationTests.java index e626cb4bad..ddce6a5b71 100644 --- a/hexagon/src/test/java/com/baeldung/hexagon/HexagonApplicationTests.java +++ b/hexagon/src/test/java/com/baeldung/hexagon/HexagonApplicationTests.java @@ -1,13 +1,55 @@ package com.baeldung.hexagon; +import com.baeldung.hexagon.core.domain.Burger; +import com.baeldung.hexagon.port.inbound.BurgerService; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + @SpringBootTest class HexagonApplicationTests { + @Autowired + private BurgerService burgerService; + @Test - void contextLoads() { + void testCreate() { + Burger burger = new Burger(); + burger.setName("Chicken Burger"); + burger.setAddons(new String[]{"tomato", "cheese"}); + burgerService.createBurger(burger); + assertNotNull(burgerService.findByName("Chicken Burger")); + } + + @Test + void testFindByName() { + Burger burger = new Burger(); + burger.setName("Chicken Burger"); + burger.setAddons(new String[]{"tomato", "cheese"}); + burgerService.createBurger(burger); + Burger burger1 = burgerService.findByName("Chicken Burger"); + Assertions.assertEquals("Chicken Burger", burger1.getName()); + } + + @Test + void testFindAll() { + Burger burger1 = new Burger(); + burger1.setName("Chicken Burger"); + burger1.setAddons(new String[]{"tomato", "cheese"}); + burgerService.createBurger(burger1); + + Burger burger2 = new Burger(); + burger2.setName("Veggie Burger"); + burger2.setAddons(new String[]{"onion", "cheese"}); + burgerService.createBurger(burger2); + List burgers = burgerService.findAll(); + + Assertions.assertEquals(2, burgers.size()); } }