TDD: check for exceptions
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 5 Nov 2015 18:54:20 +0000 (19:54 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 5 Nov 2015 18:54:20 +0000 (19:54 +0100)
TDD/src/main/java/de/example/services/impl/UsersServiceImpl.java
TDD/src/test/java/de/example/services/UsersServiceTest.java

index 7743cd2..d0a3a39 100644 (file)
@@ -1,5 +1,7 @@
 package de.example.services.impl;
 
+import java.util.Objects;
+
 import de.example.model.mapper.UsersMapper;
 import de.example.model.resource.UserResource;
 import de.example.services.UsersService;
@@ -20,6 +22,8 @@ public class UsersServiceImpl implements UsersService {
 
        @Override
     public void create(final UserResource user) {
+               Objects.requireNonNull(user, "user");
+
                this.spiedMethod(user);
                
                usersMapper.create(user); 
index ad8e697..57ee670 100644 (file)
@@ -58,6 +58,12 @@ public class UsersServiceTest {
                assertEquals(expectedUser, newUser);            
        }
        
+       @Test(expected=NullPointerException.class)
+       public void givenNoUserDataWhenCreateNewUserThenThrowNullPointerException() {
+               // Act
+               usersService.create(null);
+       }
+
        @Test
        public void givenNewUserDataWhenCreateNewUserThenCreateUserWithArgumentCaptor() {
                // Arrange