Skip to content
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
36 changes: 25 additions & 11 deletions pom.xml
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<java.version>8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<junit-platform.version>5.3.1</junit-platform.version>
Expand DownExpand Up@@ -65,6 +65,20 @@
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All@@ -78,21 +92,21 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
<!-- <configuration>-->
<!-- <argLine>-->
<!--&#45;&#45;illegal-access=permit-->
<!-- </argLine>-->
<!-- </configuration>-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
<!-- <configuration>-->
<!-- <argLine>-->
<!--&#45;&#45;illegal-access=permit-->
<!-- </argLine>-->
<!-- </configuration>-->
</plugin>
</plugins>
</build>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,10 @@
public class IndexController {

public String index(){

return "index";
}

public String oupsHandler(){
return "notimplemented";
public String oopsHandler() {
throw new ValueNotFoundException();
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
package guru.springframework.sfgpetclinic.controllers;

import guru.springframework.sfgpetclinic.fauxspring.Model;

import java.util.HashMap;

public class ModelImpl implements Model {

private HashMap<String, Object> map;

ModelImpl() {
map = new HashMap<>();
}

@Override
public void addAttribute(String key, Object o) {
map.put(key,o);
}

@Override
public void addAttribute(Object o) {
map.put(o.toString(), o);
}

public HashMap<String, Object> getMap() {
return map;
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
package guru.springframework.sfgpetclinic.controllers;

/**
* Created by jt on 2018-10-22.
*/
public class ValueNotFoundException extends RuntimeException {
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ public Vet findById(Long id) {
@Override
public Vet save(Vet object) {

if (object.getSpecialities().size() > 0){
if (object.getSpecialities() != null && object.getSpecialities().size() > 0){
object.getSpecialities().forEach(speciality -> {
if(speciality.getId() == null){
Speciality savedSpecialty = specialtyService.save(speciality);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
package guru.springframework.sfgpetclinic.controllers;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.*;

import java.time.Duration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

class IndexControllerTest {

IndexController controller;

@BeforeEach
void setUp() {
controller = new IndexController();
}

@DisplayName("Test Proper View name is returned for index page")
@Test
void index() {
assertEquals("index", controller.index());
assertEquals("index", controller.index(), "Wrong View Returned");

assertEquals("index", controller.index(), () -> "Another Expensive Message " +
"Make me only if you have to");

assertThat(controller.index()).isEqualTo("index");
}

@Test
@DisplayName("Test exception")
void oupsHandler() {
assertThrows(ValueNotFoundException.class, () -> {
controller.oopsHandler();
});
}

@Disabled("Demo of timeout")
@Test
void testTimeOut() {

assertTimeout(Duration.ofMillis(100), () -> {
Thread.sleep(5000);

System.out.println("I got here");
});
}

@Disabled("Demo of timeout")
@Test
void testTimeOutPrempt() {

assertTimeoutPreemptively(Duration.ofMillis(100), () -> {
Thread.sleep(5000);

System.out.println("I got here 2342342342342");
});
}

@Test
void testAssumptionTrue() {

assumeTrue("GURU".equalsIgnoreCase(System.getenv("GURU_RUNTIME")));
}

@Test
void testAssumptionTrueAssumptionIsTrue() {

assumeTrue("GURU".equalsIgnoreCase("GURU"));
}

@EnabledOnOs(OS.MAC)
@Test
void testMeOnMacOS() {
}

@EnabledOnOs(OS.WINDOWS)
@Test
void testMeOnWindows() {
}

@EnabledOnJre(JRE.JAVA_8)
@Test
void testMeOnJava8() {
}

@EnabledOnJre(JRE.JAVA_11)
@Test
void testMeOnJava11() {
}

@EnabledIfEnvironmentVariable(named = "USER", matches = "jt")
@Test
void testIfUserJT() {
}

@EnabledIfEnvironmentVariable(named = "USER", matches = "fred")
@Test
void testIfUserFred() {
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
package guru.springframework.sfgpetclinic.controllers;

import static org.junit.jupiter.api.Assertions.*;

import guru.springframework.sfgpetclinic.fauxspring.Model;
import guru.springframework.sfgpetclinic.model.Vet;
import guru.springframework.sfgpetclinic.services.SpecialtyService;
import guru.springframework.sfgpetclinic.services.VetService;
import guru.springframework.sfgpetclinic.services.map.SpecialityMapService;
import guru.springframework.sfgpetclinic.services.map.VetMapService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;

class VetControllerTest {

VetController controller;
Model model;
VetService service;
SpecialtyService specialtyService;

@BeforeEach
void setUp() {
specialtyService = new SpecialityMapService();
service = new VetMapService(specialtyService);
controller = new VetController(service);
model = new ModelImpl();

Vet vet1 = new Vet(10l, "Mac", "Kem", null);
Vet vet2 = new Vet(11l, "Radzio", "Bluszcz", null);

service.save(vet1);
service.save(vet2);
}

@Test
void listVets() {
String str = controller.listVets(model);

assertEquals("vets/index", str);

Set vets = (Set)((ModelImpl)model).getMap().get("vets");

assertEquals(vets.size(),2);
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
package guru.springframework.sfgpetclinic.model;

import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.*;

class OwnerTest {

@Test
void dependentAssertions() {

Owner owner = new Owner(1l, "Joe", "Buck");
owner.setCity("Key West");
owner.setTelephone("1231231234");

assertAll("Properties Test",
() -> assertAll("Person Properties",
() -> assertEquals("Joe", owner.getFirstName(), "First Name Did not Match"),
() -> assertEquals("Buck", owner.getLastName())),
() -> assertAll("Owner Properties",
() -> assertEquals("Key West", owner.getCity(), "City Did Not Match"),
() -> assertEquals("1231231234", owner.getTelephone())
));

assertThat(owner.getCity(), is("Key West"));
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
package guru.springframework.sfgpetclinic.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class PersonTest {

@Test
void groupedAssertions() {
//given
Person person = new Person(1l, "Joe", "Buck");

//then
assertAll("Test Props Set",
() -> assertEquals(person.getFirstName(), "Joe"),
() -> assertEquals(person.getLastName(), "Buck"));
}

@Test
void groupedAssertionMsgs() {
//given
Person person = new Person(1l, "Joe", "Buck");

//then
assertAll("Test Props Set",
() -> assertEquals(person.getFirstName(), "Joe", "First Name Failed"),
() -> assertEquals(person.getLastName(), "Buck", "Last Name Failed"));
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
package guru.springframework.sfgpetclinic.services.springdatajpa;

import guru.springframework.sfgpetclinic.model.Owner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

@Disabled(value = "Disabled until we learn Mocking")
class OwnerSDJpaServiceTest {

OwnerSDJpaService service;

@BeforeEach
void setUp() {
service = new OwnerSDJpaService(null, null, null);

}

@Disabled
@Test
void findByLastName() {
Owner foundOwner = service.findByLastName("Buck");
}

@Test
void findAllByLastNameLike() {
}

@Test
void findAll() {
}

@Test
void findById() {
}

@Test
void save() {
}

@Test
void delete() {
}

@Test
void deleteById() {
}
}