Skip to content

Commit

Permalink
Cycle 4: RED, Service: update employee throws exception when id not e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
gungor committed Apr 18, 2021
1 parent b979397 commit d7c4833
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
@@ -0,0 +1,4 @@
package tddexample.exception;

public class EmployeeNotFoundException extends RuntimeException{
}
7 changes: 7 additions & 0 deletions src/test/java/tddexample/service/EmployeeServiceTest.java
Expand Up @@ -8,6 +8,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.support.TransactionTemplate;
import tddexample.exception.EmployeeNotFoundException;
import tddexample.model.entity.Employee;
import tddexample.model.rest.EmployeeSaveRequest;
import tddexample.model.rest.EmployeeUpdateRequest;
Expand Down Expand Up @@ -53,6 +54,12 @@ public void shouldUpdateEmployee(){
Assertions.assertEquals( "Frodo Baggins", updatedEmployee.getFullName() );
}

@Test
public void shouldThrowEmployeeNotFoundExceptionFromUpdateWhenIdNotExists(){
EmployeeUpdateRequest request = new EmployeeUpdateRequest(1,"Frodo Baggins");
Assertions.assertThrows(EmployeeNotFoundException.class, () -> employeeService.updateEmployee(request));
}

@AfterEach
public void cleanUp(){
transactionTemplate.execute(transactionStatus -> {
Expand Down

0 comments on commit d7c4833

Please sign in to comment.