Commit d132a1f626b8209ceeb6b8c414a973b59dab7fdd
1 parent
79d89477
Exists in
master
Testes de Exception
Showing
4 changed files
with
116 additions
and
27 deletions
Show diff stats
impl/core/src/test/java/exception/basic/ExceptionClassNotAnnotated.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package exception.basic; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | |
40 | + | |
41 | +public class ExceptionClassNotAnnotated { | |
42 | + | |
43 | + private boolean nullPointerExceptionHandler = false; | |
44 | + | |
45 | + public boolean isNullPointerExceptionHandler() { | |
46 | + return nullPointerExceptionHandler; | |
47 | + } | |
48 | + | |
49 | + public void throwNullPointerException() { | |
50 | + throw new NullPointerException(); | |
51 | + } | |
52 | + | |
53 | + @ExceptionHandler | |
54 | + public void handler(NullPointerException cause) { | |
55 | + nullPointerExceptionHandler = true; | |
56 | + } | |
57 | +} | ... | ... |
impl/core/src/test/java/exception/basic/ExceptionHandlerTest.java
... | ... | @@ -41,6 +41,8 @@ import static junit.framework.Assert.fail; |
41 | 41 | |
42 | 42 | import javax.inject.Inject; |
43 | 43 | |
44 | +import junit.framework.Assert; | |
45 | + | |
44 | 46 | import org.jboss.arquillian.container.test.api.Deployment; |
45 | 47 | import org.jboss.arquillian.junit.Arquillian; |
46 | 48 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
... | ... | @@ -55,13 +57,19 @@ public class ExceptionHandlerTest { |
55 | 57 | |
56 | 58 | @Inject |
57 | 59 | private SimpleExceptionHandler exceptionHandler; |
58 | - | |
60 | + | |
59 | 61 | @Inject |
60 | 62 | private MultiExceptionHandler multiExceptionHandler; |
61 | 63 | |
62 | 64 | @Inject |
63 | 65 | private ExceptionHandlerTwoParameter exceptionTwoParameter; |
64 | 66 | |
67 | + @Inject | |
68 | + private ExceptionNested nested; | |
69 | + | |
70 | + @Inject | |
71 | + private ExceptionClassNotAnnotated classNotAnnotated; | |
72 | + | |
65 | 73 | @Deployment |
66 | 74 | public static JavaArchive createDeployment() { |
67 | 75 | JavaArchive deployment = Tests.createDeployment(ExceptionHandlerTest.class); |
... | ... | @@ -75,7 +83,7 @@ public class ExceptionHandlerTest { |
75 | 83 | assertEquals(true, exceptionHandler.isArithmeticExceptionHandler()); |
76 | 84 | assertEquals(true, exceptionHandler.isArithmeticExceptionHandler()); |
77 | 85 | } |
78 | - | |
86 | + | |
79 | 87 | @Test |
80 | 88 | public void exceptionWithoutHandler() { |
81 | 89 | try { |
... | ... | @@ -84,7 +92,7 @@ public class ExceptionHandlerTest { |
84 | 92 | } catch (Exception cause) { |
85 | 93 | assertEquals(IllegalArgumentException.class, cause.getClass()); |
86 | 94 | } |
87 | - } | |
95 | + } | |
88 | 96 | |
89 | 97 | @Test |
90 | 98 | public void twoExceptionOneMethod() { |
... | ... | @@ -102,21 +110,33 @@ public class ExceptionHandlerTest { |
102 | 110 | } |
103 | 111 | |
104 | 112 | @Test |
113 | + public void exceptionHandlerWithTwoParameter() { | |
114 | + try { | |
115 | + exceptionTwoParameter.throwIllegalPathException(); | |
116 | + fail(); | |
117 | + } catch (Exception e) { | |
118 | + assertEquals(DemoiselleException.class, e.getClass()); | |
119 | + } | |
120 | + } | |
121 | + | |
122 | + @Test | |
105 | 123 | public void exceptionHandlerWithException() { |
106 | 124 | try { |
107 | - multiExceptionHandler.throwNoSuchElementException(); | |
125 | + nested.throwNoSuchElementException(); | |
126 | + fail(); | |
108 | 127 | } catch (Exception e) { |
109 | 128 | assertEquals(ArithmeticException.class, e.getClass()); |
129 | + assertEquals(false, nested.isExceptionHandler()); | |
110 | 130 | } |
111 | 131 | } |
112 | 132 | |
113 | 133 | @Test |
114 | - public void exceptionHandlerWithTwoParameter() { | |
134 | + public void exceptionClassNotAnnotatedController() { | |
115 | 135 | try { |
116 | - exceptionTwoParameter.throwIllegalPathException(); | |
136 | + classNotAnnotated.throwNullPointerException(); | |
117 | 137 | fail(); |
118 | 138 | } catch (Exception e) { |
119 | - assertEquals(DemoiselleException.class, e.getClass()); | |
139 | + assertEquals(NullPointerException.class, e.getClass()); | |
120 | 140 | } |
121 | - } | |
141 | + } | |
122 | 142 | } | ... | ... |
impl/core/src/test/java/exception/basic/ExceptionNested.java
0 → 100644
... | ... | @@ -0,0 +1,31 @@ |
1 | +package exception.basic; | |
2 | + | |
3 | +import java.util.NoSuchElementException; | |
4 | + | |
5 | +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | |
6 | +import br.gov.frameworkdemoiselle.stereotype.Controller; | |
7 | + | |
8 | +@Controller | |
9 | +public class ExceptionNested { | |
10 | + | |
11 | + private boolean exceptionHandler = false; | |
12 | + | |
13 | + public boolean isExceptionHandler() { | |
14 | + return exceptionHandler; | |
15 | + } | |
16 | + | |
17 | + public void throwNoSuchElementException() { | |
18 | + throw new NoSuchElementException(); | |
19 | + } | |
20 | + | |
21 | + @ExceptionHandler | |
22 | + @SuppressWarnings("unused") | |
23 | + public void handlerWithError(NoSuchElementException cause) { | |
24 | + int a = 2 / 0; | |
25 | + } | |
26 | + | |
27 | + @ExceptionHandler | |
28 | + public void handler(ArithmeticException cause) { | |
29 | + exceptionHandler = true; | |
30 | + } | |
31 | +} | ... | ... |
impl/core/src/test/java/exception/basic/MultiExceptionHandler.java
... | ... | @@ -36,8 +36,6 @@ |
36 | 36 | */ |
37 | 37 | package exception.basic; |
38 | 38 | |
39 | -import java.util.NoSuchElementException; | |
40 | - | |
41 | 39 | import br.gov.frameworkdemoiselle.exception.ExceptionHandler; |
42 | 40 | import br.gov.frameworkdemoiselle.stereotype.Controller; |
43 | 41 | |
... | ... | @@ -62,22 +60,10 @@ public class MultiExceptionHandler { |
62 | 60 | return exceptionHandlerIllegalArgument3; |
63 | 61 | } |
64 | 62 | |
65 | - @SuppressWarnings("null") | |
66 | - public void throwExceptionWithHandler() { | |
67 | - String txt = null; | |
68 | - txt.toString(); | |
69 | - } | |
70 | - | |
71 | - | |
72 | - | |
73 | 63 | public void throwIllegalArgumentException() { |
74 | 64 | throw new IllegalArgumentException(); |
75 | 65 | } |
76 | 66 | |
77 | - public void throwNoSuchElementException() { | |
78 | - throw new NoSuchElementException(); | |
79 | - } | |
80 | - | |
81 | 67 | @ExceptionHandler |
82 | 68 | public void handler1(IllegalArgumentException cause) { |
83 | 69 | exceptionHandlerIllegalArgument1 = true; |
... | ... | @@ -93,9 +79,4 @@ public class MultiExceptionHandler { |
93 | 79 | exceptionHandlerIllegalArgument2 = true; |
94 | 80 | } |
95 | 81 | |
96 | - @ExceptionHandler | |
97 | - @SuppressWarnings("unused") | |
98 | - public void handlerWithError(NoSuchElementException cause) { | |
99 | - int a = 2 / 0; | |
100 | - } | |
101 | 82 | } | ... | ... |