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