diff --git a/README.md b/README.md index dafea84a..f3e94a56 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Introduction to JUnit 5 with Maven -All source code examples in the repository are for my [Online Course - Testing Spring Beginner to Guru](https://springframework.guru) +All source code examples in the repository are for my [Online Course - Testing Spring Beginner to Guru](https://www.udemy.com/testing-spring-boot-beginner-to-guru/?couponCode=GITHUB_REPO) This source code repository contains JUnit 5 test examples with Maven. diff --git a/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java b/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java index 759f3e3c..8c0a8525 100644 --- a/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java +++ b/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java @@ -1,32 +1,40 @@ package guru.springframework.sfgpetclinic.controllers; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +/* + Author: jalnor + Date: 7/12/2021 5:08 AM + Project: guru.springframework.sfgpetclinic.controllers +*/ class IndexControllerTest { - IndexController controller; + IndexController indexController; @BeforeEach void setUp() { - controller = new IndexController(); + indexController = new IndexController(); } + @DisplayName("Test proper view name is returned for the index page") @Test void index() { - assertEquals("index", controller.index()); - assertEquals("index", controller.index(), "Wrong View Returned"); + assertEquals("index", indexController.index()); + assertEquals("index", indexController.index(), "Wrong view returned"); - assertEquals("index", controller.index(), () -> "Another Expensive Message " + - "Make me only if you have to"); + assertEquals("index", indexController.index(), () -> "Another expensive message, " + + "make only if necessary!!!!!"); } @Test + @DisplayName("Test exception") void oupsHandler() { - assertTrue("notimplemented".equals(controller.oupsHandler()), () -> "This is some expensive " + - "Message to build" + + assertTrue("notimplemented".equals(indexController.oupsHandler()), () -> "This is some expensive " + + "message to build " + "for my test"); } } \ No newline at end of file diff --git a/src/test/java/guru/springframework/sfgpetclinic/model/OwnerTest.java b/src/test/java/guru/springframework/sfgpetclinic/model/OwnerTest.java new file mode 100644 index 00000000..e48042c2 --- /dev/null +++ b/src/test/java/guru/springframework/sfgpetclinic/model/OwnerTest.java @@ -0,0 +1,107 @@ +package guru.springframework.sfgpetclinic.model; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/* + Author: jalnor + Date: 7/13/2021 7:32 AM + Project: guru.springframework.sfgpetclinic.model +*/ +class OwnerTest { + + Owner owner; + @BeforeEach + void setUp() { + owner = new Owner(1l, "Joe", "Schmoe"); + owner.setCity("Key West"); + owner.setTelephone("1231231234"); + } + // Can run multiple tests in same method + @Test + void dependentAssertions() { + assertAll("Properties Test", + () -> assertAll("Person Properties", + () -> assertEquals("Joe", owner.getFirstName()), + () -> assertEquals("Schmoe", owner.getLastName())), + () -> assertAll("Owner Properties", + () -> assertEquals("Key West", owner.getCity()), + () -> assertEquals("1231231234", owner.getTelephone()) + )); + } + + @AfterEach + void tearDown() { + } + + @Test + void getFirstName() { + } + + @Test + void setFirstName() { + } + + @Test + void getLastName() { + } + + @Test + void setLastName() { + } + + @Test + void isNew() { + } + + @Test + void getId() { + } + + @Test + void setId() { + } + + @Test + void getPet() { + } + + @Test + void testGetPet() { + } + + @Test + void getAddress() { + } + + @Test + void setAddress() { + } + + @Test + void getCity() { + } + + @Test + void setCity() { + } + + @Test + void getTelephone() { + } + + @Test + void setTelephone() { + } + + @Test + void getPets() { + } + + @Test + void setPets() { + } +} \ No newline at end of file diff --git a/src/test/java/guru/springframework/sfgpetclinic/model/PersonTest.java b/src/test/java/guru/springframework/sfgpetclinic/model/PersonTest.java new file mode 100644 index 00000000..3ff4a37e --- /dev/null +++ b/src/test/java/guru/springframework/sfgpetclinic/model/PersonTest.java @@ -0,0 +1,35 @@ +package guru.springframework.sfgpetclinic.model; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/* + Author: jalnor + Date: 7/12/2021 5:54 AM + Project: guru.springframework.sfgpetclinic.model +*/ +class PersonTest { + + @Test + void groupedAssertions() { + // given + Person person = new Person(1L, "Joe", "Shmoe"); + + // then + assertAll("Testing Properties are set...", + () -> assertEquals("Joe", person.getFirstName()), + () -> assertEquals("Shmoe", person.getLastName())); + } + + @Test + void groupedAssertionsMessages() { + // given + Person person = new Person(1L, "Joe", "Shmoe"); + + // then + assertAll("Testing Properties are set...", + () -> assertEquals( "Joe", person.getFirstName(), "First name failed..."), + () -> assertEquals( "Shmoe", person.getLastName(),"Last name failed...")); + } +} \ No newline at end of file