Commit c298b4fa63617e63d37d03010e9e9e9028fd1069
1 parent
c20d0c4b
Exists in
master
Testes de Exceção
Showing
8 changed files
with
191 additions
and
8 deletions
Show diff stats
| @@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
| 1 | +package exception; | ||
| 2 | + | ||
| 3 | +import br.gov.frameworkdemoiselle.exception.ApplicationException; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +@ApplicationException | ||
| 7 | +public class CustomException extends RuntimeException { | ||
| 8 | + | ||
| 9 | + private static final long serialVersionUID = 1L; | ||
| 10 | + | ||
| 11 | +} | ||
| 0 | \ No newline at end of file | 12 | \ No newline at end of file |
impl/core/src/test/java/exception/CustomExceptionHandler.java
0 → 100644
| @@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
| 1 | +package exception; | ||
| 2 | + | ||
| 3 | +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | ||
| 4 | +import br.gov.frameworkdemoiselle.stereotype.Controller; | ||
| 5 | + | ||
| 6 | +@Controller | ||
| 7 | +public class CustomExceptionHandler { | ||
| 8 | + | ||
| 9 | + private boolean exceptionHandler = false; | ||
| 10 | + | ||
| 11 | + public boolean isExceptionHandler() { | ||
| 12 | + return exceptionHandler; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public void setExceptionHandler(boolean exceptionHandler) { | ||
| 16 | + this.exceptionHandler = exceptionHandler; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void throwExceptionWithMessage() { | ||
| 20 | + throw new CustomException(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + @ExceptionHandler | ||
| 24 | + public void handler(CustomException exception) { | ||
| 25 | + setExceptionHandler(true); | ||
| 26 | + } | ||
| 27 | +} |
impl/core/src/test/java/exception/CustomExceptionTest.java
0 → 100644
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | +package exception; | ||
| 2 | + | ||
| 3 | +import static junit.framework.Assert.assertEquals; | ||
| 4 | + | ||
| 5 | +import javax.inject.Inject; | ||
| 6 | + | ||
| 7 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 8 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 9 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 10 | +import org.junit.Test; | ||
| 11 | +import org.junit.runner.RunWith; | ||
| 12 | + | ||
| 13 | +import test.Tests; | ||
| 14 | + | ||
| 15 | +@RunWith(Arquillian.class) | ||
| 16 | +public class CustomExceptionTest { | ||
| 17 | + | ||
| 18 | + @Inject | ||
| 19 | + private CustomExceptionHandler exception; | ||
| 20 | + | ||
| 21 | + @Deployment | ||
| 22 | + public static JavaArchive createDeployment() { | ||
| 23 | + JavaArchive deployment = Tests.createDeployment(CustomExceptionTest.class); | ||
| 24 | + return deployment; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + @Test | ||
| 28 | + public void testCustomExceptionHandler() { | ||
| 29 | + exception.throwExceptionWithMessage(); | ||
| 30 | + assertEquals(true, exception.isExceptionHandler()); | ||
| 31 | + } | ||
| 32 | +} |
impl/core/src/test/java/exception/ExceptionInheritance.java
0 → 100644
| @@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
| 1 | +package exception; | ||
| 2 | + | ||
| 3 | +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | ||
| 4 | +import br.gov.frameworkdemoiselle.stereotype.Controller; | ||
| 5 | + | ||
| 6 | +@Controller | ||
| 7 | +public class ExceptionInheritance { | ||
| 8 | + | ||
| 9 | + private boolean handlerSuperClass = false; | ||
| 10 | + | ||
| 11 | + private boolean handlerClass = false; | ||
| 12 | + | ||
| 13 | + public boolean isHandlerSuperClass() { | ||
| 14 | + return handlerSuperClass; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public boolean isHandlerClass() { | ||
| 18 | + return handlerClass; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void throwNullPointerException() { | ||
| 22 | + throw new NullPointerException(); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void throwArithmeticException() { | ||
| 26 | + throw new ArithmeticException(); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @ExceptionHandler | ||
| 30 | + public void handle(ArithmeticException e) { | ||
| 31 | + handlerClass = true; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @ExceptionHandler | ||
| 35 | + public void handle(RuntimeException e) { | ||
| 36 | + handlerSuperClass = true; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
impl/core/src/test/java/exception/ExceptionInheritanceTest.java
0 → 100644
| @@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
| 1 | +package exception; | ||
| 2 | + | ||
| 3 | +import static junit.framework.Assert.assertEquals; | ||
| 4 | + | ||
| 5 | +import javax.inject.Inject; | ||
| 6 | + | ||
| 7 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 8 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 9 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 10 | +import org.junit.Test; | ||
| 11 | +import org.junit.runner.RunWith; | ||
| 12 | + | ||
| 13 | +import test.Tests; | ||
| 14 | + | ||
| 15 | +@RunWith(Arquillian.class) | ||
| 16 | +public class ExceptionInheritanceTest { | ||
| 17 | + | ||
| 18 | + @Inject | ||
| 19 | + private ExceptionInheritance exceptionInheritance; | ||
| 20 | + | ||
| 21 | + @Deployment | ||
| 22 | + public static JavaArchive createDeployment() { | ||
| 23 | + JavaArchive deployment = Tests.createDeployment(ExceptionInheritanceTest.class); | ||
| 24 | + return deployment; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + @Test | ||
| 28 | + public void testExceptionInheritanceSuperClass() { | ||
| 29 | + exceptionInheritance.throwNullPointerException(); | ||
| 30 | + assertEquals(true, exceptionInheritance.isHandlerSuperClass()); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Test | ||
| 34 | + public void testExceptionInheritanceClass() { | ||
| 35 | + exceptionInheritance.throwArithmeticException(); | ||
| 36 | + assertEquals(false, exceptionInheritance.isHandlerSuperClass()); | ||
| 37 | + assertEquals(true, exceptionInheritance.isHandlerClass()); | ||
| 38 | + } | ||
| 39 | +} |
impl/core/src/test/java/exception/MultiException.java
| 1 | package exception; | 1 | package exception; |
| 2 | 2 | ||
| 3 | +import java.awt.geom.IllegalPathStateException; | ||
| 4 | + | ||
| 3 | import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | 5 | import br.gov.frameworkdemoiselle.exception.ExceptionHandler; |
| 4 | import br.gov.frameworkdemoiselle.stereotype.Controller; | 6 | import br.gov.frameworkdemoiselle.stereotype.Controller; |
| 5 | 7 | ||
| @@ -9,7 +11,7 @@ public class MultiException { | @@ -9,7 +11,7 @@ public class MultiException { | ||
| 9 | private boolean nullPointerExceptionHandler = false; | 11 | private boolean nullPointerExceptionHandler = false; |
| 10 | 12 | ||
| 11 | private boolean arithmeticExceptionHandler = false; | 13 | private boolean arithmeticExceptionHandler = false; |
| 12 | - | 14 | + |
| 13 | public boolean isNullPointerExceptionHandler() { | 15 | public boolean isNullPointerExceptionHandler() { |
| 14 | return nullPointerExceptionHandler; | 16 | return nullPointerExceptionHandler; |
| 15 | } | 17 | } |
| @@ -17,15 +19,15 @@ public class MultiException { | @@ -17,15 +19,15 @@ public class MultiException { | ||
| 17 | public boolean isArithmeticExceptionHandler() { | 19 | public boolean isArithmeticExceptionHandler() { |
| 18 | return arithmeticExceptionHandler; | 20 | return arithmeticExceptionHandler; |
| 19 | } | 21 | } |
| 20 | - | ||
| 21 | - public void throwExceptionNullPointer() { | 22 | + |
| 23 | + public void throwNullPointerException() { | ||
| 22 | throw new NullPointerException(); | 24 | throw new NullPointerException(); |
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | - public void throwExceptionArithmetic() { | 27 | + public void throwArithmeticException() { |
| 26 | throw new ArithmeticException(); | 28 | throw new ArithmeticException(); |
| 27 | } | 29 | } |
| 28 | - | 30 | + |
| 29 | @SuppressWarnings({ "null", "unused" }) | 31 | @SuppressWarnings({ "null", "unused" }) |
| 30 | public void throwTwoException() { | 32 | public void throwTwoException() { |
| 31 | String txt = null; | 33 | String txt = null; |
| @@ -41,5 +43,5 @@ public class MultiException { | @@ -41,5 +43,5 @@ public class MultiException { | ||
| 41 | @ExceptionHandler | 43 | @ExceptionHandler |
| 42 | public void handler(ArithmeticException cause) { | 44 | public void handler(ArithmeticException cause) { |
| 43 | arithmeticExceptionHandler = true; | 45 | arithmeticExceptionHandler = true; |
| 44 | - } | 46 | + } |
| 45 | } | 47 | } |
impl/core/src/test/java/exception/MultiExceptionOneHandler.java
0 → 100644
| @@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
| 1 | +package exception; | ||
| 2 | + | ||
| 3 | +import java.awt.geom.IllegalPathStateException; | ||
| 4 | + | ||
| 5 | +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | ||
| 6 | +import br.gov.frameworkdemoiselle.stereotype.Controller; | ||
| 7 | + | ||
| 8 | +@Controller | ||
| 9 | +public class MultiExceptionOneHandler { | ||
| 10 | + | ||
| 11 | + public void throwIllegalPathException() { | ||
| 12 | + throw new IllegalPathStateException(); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + @ExceptionHandler | ||
| 16 | + public void handler(IllegalPathStateException cause, IllegalStateException cause2) { | ||
| 17 | + } | ||
| 18 | +} |
impl/core/src/test/java/exception/MultiExceptionTest.java
| @@ -11,6 +11,8 @@ import org.jboss.shrinkwrap.api.spec.JavaArchive; | @@ -11,6 +11,8 @@ import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 11 | import org.junit.Test; | 11 | import org.junit.Test; |
| 12 | import org.junit.runner.RunWith; | 12 | import org.junit.runner.RunWith; |
| 13 | 13 | ||
| 14 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 15 | + | ||
| 14 | import test.Tests; | 16 | import test.Tests; |
| 15 | 17 | ||
| 16 | @RunWith(Arquillian.class) | 18 | @RunWith(Arquillian.class) |
| @@ -18,6 +20,9 @@ public class MultiExceptionTest { | @@ -18,6 +20,9 @@ public class MultiExceptionTest { | ||
| 18 | 20 | ||
| 19 | @Inject | 21 | @Inject |
| 20 | private MultiException multiException; | 22 | private MultiException multiException; |
| 23 | + | ||
| 24 | + @Inject | ||
| 25 | + private MultiExceptionOneHandler multiExceptionOneHandler; | ||
| 21 | 26 | ||
| 22 | @Deployment | 27 | @Deployment |
| 23 | public static JavaArchive createDeployment() { | 28 | public static JavaArchive createDeployment() { |
| @@ -27,13 +32,13 @@ public class MultiExceptionTest { | @@ -27,13 +32,13 @@ public class MultiExceptionTest { | ||
| 27 | 32 | ||
| 28 | @Test | 33 | @Test |
| 29 | public void testNullPointerExceptionHandler() { | 34 | public void testNullPointerExceptionHandler() { |
| 30 | - multiException.throwExceptionNullPointer(); | 35 | + multiException.throwNullPointerException(); |
| 31 | assertEquals(true, multiException.isNullPointerExceptionHandler()); | 36 | assertEquals(true, multiException.isNullPointerExceptionHandler()); |
| 32 | } | 37 | } |
| 33 | 38 | ||
| 34 | @Test | 39 | @Test |
| 35 | public void testArithmeticExceptionHandler() { | 40 | public void testArithmeticExceptionHandler() { |
| 36 | - multiException.throwExceptionArithmetic(); | 41 | + multiException.throwArithmeticException(); |
| 37 | assertEquals(true, multiException.isArithmeticExceptionHandler()); | 42 | assertEquals(true, multiException.isArithmeticExceptionHandler()); |
| 38 | } | 43 | } |
| 39 | 44 | ||
| @@ -43,4 +48,14 @@ public class MultiExceptionTest { | @@ -43,4 +48,14 @@ public class MultiExceptionTest { | ||
| 43 | assertEquals(true, multiException.isNullPointerExceptionHandler()); | 48 | assertEquals(true, multiException.isNullPointerExceptionHandler()); |
| 44 | assertEquals(true, multiException.isArithmeticExceptionHandler()); | 49 | assertEquals(true, multiException.isArithmeticExceptionHandler()); |
| 45 | } | 50 | } |
| 51 | + | ||
| 52 | + @Test | ||
| 53 | + public void testExceptionHandlerWithTwoException() { | ||
| 54 | + try { | ||
| 55 | + multiExceptionOneHandler.throwIllegalPathException(); | ||
| 56 | + fail(); | ||
| 57 | + } catch (Exception e) { | ||
| 58 | + assertEquals(DemoiselleException.class, e.getClass()); | ||
| 59 | + } | ||
| 60 | + } | ||
| 46 | } | 61 | } |