Commit edf064df04411405ee25a14b361a0350270af61f

Authored by Ednara Oliveira
1 parent 2c550250
Exists in master

Testes de exceção

impl/core/src/test/java/exception/ExceptionHandlerTwoParameter.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 ExceptionHandlerTwoParameter {
  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/MultiException.java
1 package exception; 1 package exception;
2 2
3 -import java.awt.geom.IllegalPathStateException;  
4 -  
5 import br.gov.frameworkdemoiselle.exception.ExceptionHandler; 3 import br.gov.frameworkdemoiselle.exception.ExceptionHandler;
6 import br.gov.frameworkdemoiselle.stereotype.Controller; 4 import br.gov.frameworkdemoiselle.stereotype.Controller;
7 5
impl/core/src/test/java/exception/MultiExceptionOneHandler.java
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
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
@@ -22,7 +22,7 @@ public class MultiExceptionTest { @@ -22,7 +22,7 @@ public class MultiExceptionTest {
22 private MultiException multiException; 22 private MultiException multiException;
23 23
24 @Inject 24 @Inject
25 - private MultiExceptionOneHandler multiExceptionOneHandler; 25 + private ExceptionHandlerTwoParameter exceptionTwoParameter;
26 26
27 @Deployment 27 @Deployment
28 public static JavaArchive createDeployment() { 28 public static JavaArchive createDeployment() {
@@ -31,28 +31,24 @@ public class MultiExceptionTest { @@ -31,28 +31,24 @@ public class MultiExceptionTest {
31 } 31 }
32 32
33 @Test 33 @Test
34 - public void testNullPointerExceptionHandler() {  
35 - multiException.throwNullPointerException();  
36 - assertEquals(true, multiException.isNullPointerExceptionHandler());  
37 - }  
38 -  
39 - @Test  
40 - public void testArithmeticExceptionHandler() { 34 + public void testTwoExceptionTwoMethod() {
41 multiException.throwArithmeticException(); 35 multiException.throwArithmeticException();
  36 + multiException.throwNullPointerException();
  37 + assertEquals(true, multiException.isArithmeticExceptionHandler());
42 assertEquals(true, multiException.isArithmeticExceptionHandler()); 38 assertEquals(true, multiException.isArithmeticExceptionHandler());
43 } 39 }
44 40
45 @Test 41 @Test
46 - public void testMultiExceptionHandler() { 42 + public void testTwoExceptionOneMethod() {
47 multiException.throwTwoException(); 43 multiException.throwTwoException();
48 assertEquals(true, multiException.isNullPointerExceptionHandler()); 44 assertEquals(true, multiException.isNullPointerExceptionHandler());
49 assertEquals(false, multiException.isArithmeticExceptionHandler()); 45 assertEquals(false, multiException.isArithmeticExceptionHandler());
50 } 46 }
51 47
52 @Test 48 @Test
53 - public void testExceptionHandlerWithTwoException() { 49 + public void testExceptionHandlerWithTwoParameter() {
54 try { 50 try {
55 - multiExceptionOneHandler.throwIllegalPathException(); 51 + exceptionTwoParameter.throwIllegalPathException();
56 fail(); 52 fail();
57 } catch (Exception e) { 53 } catch (Exception e) {
58 assertEquals(DemoiselleException.class, e.getClass()); 54 assertEquals(DemoiselleException.class, e.getClass());
impl/core/src/test/java/exception/OneException.java
1 package exception; 1 package exception;
2 2
  3 +import java.util.NoSuchElementException;
  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
@@ -41,16 +43,19 @@ public class OneException { @@ -41,16 +43,19 @@ public class OneException {
41 int result = 4/0; 43 int result = 4/0;
42 } 44 }
43 45
44 - public void throwExceptionIllegalArgument() { 46 + public void throwIllegalArgumentException() {
45 throw new IllegalArgumentException(); 47 throw new IllegalArgumentException();
46 } 48 }
  49 +
  50 + public void throwNoSuchElementException() {
  51 + throw new NoSuchElementException();
  52 + }
47 53
48 @ExceptionHandler 54 @ExceptionHandler
49 public void handler(NullPointerException cause) { 55 public void handler(NullPointerException cause) {
50 exceptionHandler = true; 56 exceptionHandler = true;
51 } 57 }
52 58
53 -  
54 @ExceptionHandler 59 @ExceptionHandler
55 public void handler1(IllegalArgumentException cause) { 60 public void handler1(IllegalArgumentException cause) {
56 exceptionHandlerIllegalArgument1 = true; 61 exceptionHandlerIllegalArgument1 = true;
@@ -65,4 +70,9 @@ public class OneException { @@ -65,4 +70,9 @@ public class OneException {
65 public void handler2(IllegalArgumentException cause) { 70 public void handler2(IllegalArgumentException cause) {
66 exceptionHandlerIllegalArgument2 = true; 71 exceptionHandlerIllegalArgument2 = true;
67 } 72 }
  73 +
  74 + @ExceptionHandler
  75 + public void handlerWithError(NoSuchElementException cause) {
  76 + int a = 2/0;
  77 + }
68 } 78 }
impl/core/src/test/java/exception/OneExceptionTest.java
@@ -43,9 +43,20 @@ public class OneExceptionTest { @@ -43,9 +43,20 @@ public class OneExceptionTest {
43 43
44 @Test 44 @Test
45 public void testExceptionWithMultiHandler() { 45 public void testExceptionWithMultiHandler() {
46 - oneException.throwExceptionIllegalArgument(); 46 + oneException.throwIllegalArgumentException();
47 assertEquals(false, oneException.isExceptionHandlerIllegalArgument1()); 47 assertEquals(false, oneException.isExceptionHandlerIllegalArgument1());
48 assertEquals(true, oneException.isExceptionHandlerIllegalArgument2()); 48 assertEquals(true, oneException.isExceptionHandlerIllegalArgument2());
49 assertEquals(false, oneException.isExceptionHandlerIllegalArgument3()); 49 assertEquals(false, oneException.isExceptionHandlerIllegalArgument3());
50 } 50 }
  51 +
  52 + @Test
  53 + public void testExceptionHandlerWithException() {
  54 + try {
  55 + oneException.throwNoSuchElementException();
  56 + } catch (Exception e) {
  57 + assertEquals(ArithmeticException.class, e.getClass());
  58 + }
  59 +
  60 +
  61 + }
51 } 62 }