Skip to content

Commit

Permalink
Add example of exception management with assertThrows
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Sep 9, 2022
1 parent 410f7da commit f52db0b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/java/giis/demo/tkrun/ut/TestInscripcion.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package giis.demo.tkrun.ut;
import org.junit.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import org.junit.rules.ExpectedException;

Expand Down Expand Up @@ -159,7 +160,9 @@ public void testCarrerasActivasException1() {
}
/**
* Utilizacion de reglas, para comprobar tambien los mensajes de las excepciones
* (esta deprecated en las ultimas versiones)
*/
@SuppressWarnings("deprecation")
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
Expand All @@ -169,6 +172,17 @@ public void testCarrerasActivasException2() {
thrown.expectMessage("La fecha de inscripcion no puede ser nula");
inscr.getListaCarreras(null);
}
/**
* Manejo de excepciones recomendado en junit 4 sin especificar una regla
*/
@Test
public void testCarrerasActivasException3() {
CarrerasModel inscr=new CarrerasModel();
ApplicationException exception=assertThrows(ApplicationException.class, () -> {
inscr.getListaCarreras(null);
});
assertEquals("La fecha de inscripcion no puede ser nula", exception.getMessage());
}

/**
* Determinacion del descuento o recargo porcentual segun la fecha de inscripcion
Expand Down

0 comments on commit f52db0b

Please sign in to comment.