From ac2bfbccc45dc98d412947d8942ecd63988417fc Mon Sep 17 00:00:00 2001 From: John Thompson Date: Tue, 30 Oct 2018 18:52:36 -0400 Subject: [PATCH 1/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From c5b533aa3f9b3c6228c122903eacf3eb35138a13 Mon Sep 17 00:00:00 2001 From: hal90 Date: Mon, 12 Jul 2021 05:24:16 -0400 Subject: [PATCH 2/5] Added some assertEquals and an assertTrue test to indexController. Compiler warning of excessive lambda usage. --- .../controllers/IndexControllerTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java diff --git a/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java b/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java new file mode 100644 index 00000000..e4b44d77 --- /dev/null +++ b/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java @@ -0,0 +1,37 @@ +package guru.springframework.sfgpetclinic.controllers; + +import org.junit.jupiter.api.BeforeEach; +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 indexController; + + @BeforeEach + void setUp() { + indexController = new IndexController(); + } + + @Test + void index() { + assertEquals("index", indexController.index()); + assertEquals("index", indexController.index(), "Wrong view returned"); + + assertEquals("index", indexController.index(), () -> "Another expensive message, " + + "make only if necessary!!!!!"); + } + + @Test + void oupsHandler() { + assertTrue("notimplemented".equals(indexController.oupsHandler()), () -> "This is some expensive " + + "message to build " + + "for my test"); + } +} \ No newline at end of file From 204e7c799df73344549865710f5a767aad6d7fc0 Mon Sep 17 00:00:00 2001 From: hal90 Date: Mon, 12 Jul 2021 06:06:21 -0400 Subject: [PATCH 3/5] Added some groupAssertions to PersonTest. --- .../sfgpetclinic/model/PersonTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/java/guru/springframework/sfgpetclinic/model/PersonTest.java 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 From 3d66855346907dcfc789f05e69b4caa9fc292add Mon Sep 17 00:00:00 2001 From: hal90 Date: Tue, 13 Jul 2021 07:47:31 -0400 Subject: [PATCH 4/5] Added an Owner test and completed one method. --- .../sfgpetclinic/model/OwnerTest.java | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/test/java/guru/springframework/sfgpetclinic/model/OwnerTest.java 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 From f5b004d7616dbe0ae6eee3b73335611134adab4b Mon Sep 17 00:00:00 2001 From: hal90 Date: Tue, 13 Jul 2021 08:04:42 -0400 Subject: [PATCH 5/5] Added @DisplayName to the IndexControllerTest. --- .../sfgpetclinic/controllers/IndexControllerTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java b/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java index e4b44d77..8c0a8525 100644 --- a/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java +++ b/src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java @@ -1,6 +1,7 @@ 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.*; @@ -19,6 +20,7 @@ void setUp() { indexController = new IndexController(); } + @DisplayName("Test proper view name is returned for the index page") @Test void index() { assertEquals("index", indexController.index()); @@ -29,6 +31,7 @@ void index() { } @Test + @DisplayName("Test exception") void oupsHandler() { assertTrue("notimplemented".equals(indexController.oupsHandler()), () -> "This is some expensive " + "message to build " +