Commit 636c56ff authored by Martin Parák's avatar Martin Parák

Added Tests. Closes #49

parent 3a85fd1d
......@@ -17,7 +17,6 @@ import lombok.Setter;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "owners")
public class Owner extends Person {
......
......@@ -69,6 +69,10 @@ public class OwnerMapService extends AbstractMapService<Owner, Long> implements
@Override
public Owner findByLastName(String lastName) {
return null;
return this.findAll()
.stream()
.filter(owner -> owner.getLastName().equalsIgnoreCase(lastName))
.findFirst()
.orElse(null);
}
}
package sk.jusska.sfgpetclinic.service.map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import sk.jusska.sfgpetclinic.model.Owner;
class OwnerMapServiceTest {
OwnerMapService ownerMapService;
final Long ownerId = 1L;
final String lastName = "Smith";
@BeforeEach
void setUp() {
ownerMapService = new OwnerMapService(new PetTypeMapService(), new PetMapService());
ownerMapService.save(Owner.builder().id(ownerId).lastName(lastName).build());
}
@Test
void findAll() {
Set<Owner> ownerSet = ownerMapService.findAll();
assertEquals(1, ownerSet.size());
}
@Test
void deleteById() {
ownerMapService.deleteById(ownerId);
assertEquals(0, ownerMapService.findAll().size());
}
@Test
void delete() {
ownerMapService.delete(ownerMapService.findById(ownerId));
assertEquals(0, ownerMapService.findAll().size());
}
@Test
void saveExistingId() {
long id = 2L;
Owner owner2 = Owner.builder().id(id).build();
Owner savedOwner = ownerMapService.save(owner2);
assertEquals(id, savedOwner.getId());
}
@Test
void saveNoId() {
Owner savedOwner = ownerMapService.save(Owner.builder().build());
assertNotNull(savedOwner);
assertNotNull(savedOwner.getId());
}
@Test
void findById() {
Owner owner = ownerMapService.findById(ownerId);
assertEquals(1, owner.getId());
}
@Test
void findByLastName() {
Owner smith = ownerMapService.findByLastName(lastName);
assertNotNull(smith);
assertEquals(ownerId, smith.getId());
}
@Test
void findByLastNameNotFound() {
Owner smith = ownerMapService.findByLastName("foo");
assertNull(smith);
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment