Skip to content

Assertions #9

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

Open
wants to merge 6 commits into
base: assertions
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
107 changes: 107 additions & 0 deletions src/test/java/guru/springframework/sfgpetclinic/model/OwnerTest.java
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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..."));
}
}