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 @@ | @@ -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,6 +41,8 @@ import static junit.framework.Assert.fail; | ||
| 41 | 41 | ||
| 42 | import javax.inject.Inject; | 42 | import javax.inject.Inject; |
| 43 | 43 | ||
| 44 | +import junit.framework.Assert; | ||
| 45 | + | ||
| 44 | import org.jboss.arquillian.container.test.api.Deployment; | 46 | import org.jboss.arquillian.container.test.api.Deployment; |
| 45 | import org.jboss.arquillian.junit.Arquillian; | 47 | import org.jboss.arquillian.junit.Arquillian; |
| 46 | import org.jboss.shrinkwrap.api.spec.JavaArchive; | 48 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| @@ -55,13 +57,19 @@ public class ExceptionHandlerTest { | @@ -55,13 +57,19 @@ public class ExceptionHandlerTest { | ||
| 55 | 57 | ||
| 56 | @Inject | 58 | @Inject |
| 57 | private SimpleExceptionHandler exceptionHandler; | 59 | private SimpleExceptionHandler exceptionHandler; |
| 58 | - | 60 | + |
| 59 | @Inject | 61 | @Inject |
| 60 | private MultiExceptionHandler multiExceptionHandler; | 62 | private MultiExceptionHandler multiExceptionHandler; |
| 61 | 63 | ||
| 62 | @Inject | 64 | @Inject |
| 63 | private ExceptionHandlerTwoParameter exceptionTwoParameter; | 65 | private ExceptionHandlerTwoParameter exceptionTwoParameter; |
| 64 | 66 | ||
| 67 | + @Inject | ||
| 68 | + private ExceptionNested nested; | ||
| 69 | + | ||
| 70 | + @Inject | ||
| 71 | + private ExceptionClassNotAnnotated classNotAnnotated; | ||
| 72 | + | ||
| 65 | @Deployment | 73 | @Deployment |
| 66 | public static JavaArchive createDeployment() { | 74 | public static JavaArchive createDeployment() { |
| 67 | JavaArchive deployment = Tests.createDeployment(ExceptionHandlerTest.class); | 75 | JavaArchive deployment = Tests.createDeployment(ExceptionHandlerTest.class); |
| @@ -75,7 +83,7 @@ public class ExceptionHandlerTest { | @@ -75,7 +83,7 @@ public class ExceptionHandlerTest { | ||
| 75 | assertEquals(true, exceptionHandler.isArithmeticExceptionHandler()); | 83 | assertEquals(true, exceptionHandler.isArithmeticExceptionHandler()); |
| 76 | assertEquals(true, exceptionHandler.isArithmeticExceptionHandler()); | 84 | assertEquals(true, exceptionHandler.isArithmeticExceptionHandler()); |
| 77 | } | 85 | } |
| 78 | - | 86 | + |
| 79 | @Test | 87 | @Test |
| 80 | public void exceptionWithoutHandler() { | 88 | public void exceptionWithoutHandler() { |
| 81 | try { | 89 | try { |
| @@ -84,7 +92,7 @@ public class ExceptionHandlerTest { | @@ -84,7 +92,7 @@ public class ExceptionHandlerTest { | ||
| 84 | } catch (Exception cause) { | 92 | } catch (Exception cause) { |
| 85 | assertEquals(IllegalArgumentException.class, cause.getClass()); | 93 | assertEquals(IllegalArgumentException.class, cause.getClass()); |
| 86 | } | 94 | } |
| 87 | - } | 95 | + } |
| 88 | 96 | ||
| 89 | @Test | 97 | @Test |
| 90 | public void twoExceptionOneMethod() { | 98 | public void twoExceptionOneMethod() { |
| @@ -102,21 +110,33 @@ public class ExceptionHandlerTest { | @@ -102,21 +110,33 @@ public class ExceptionHandlerTest { | ||
| 102 | } | 110 | } |
| 103 | 111 | ||
| 104 | @Test | 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 | public void exceptionHandlerWithException() { | 123 | public void exceptionHandlerWithException() { |
| 106 | try { | 124 | try { |
| 107 | - multiExceptionHandler.throwNoSuchElementException(); | 125 | + nested.throwNoSuchElementException(); |
| 126 | + fail(); | ||
| 108 | } catch (Exception e) { | 127 | } catch (Exception e) { |
| 109 | assertEquals(ArithmeticException.class, e.getClass()); | 128 | assertEquals(ArithmeticException.class, e.getClass()); |
| 129 | + assertEquals(false, nested.isExceptionHandler()); | ||
| 110 | } | 130 | } |
| 111 | } | 131 | } |
| 112 | 132 | ||
| 113 | @Test | 133 | @Test |
| 114 | - public void exceptionHandlerWithTwoParameter() { | 134 | + public void exceptionClassNotAnnotatedController() { |
| 115 | try { | 135 | try { |
| 116 | - exceptionTwoParameter.throwIllegalPathException(); | 136 | + classNotAnnotated.throwNullPointerException(); |
| 117 | fail(); | 137 | fail(); |
| 118 | } catch (Exception e) { | 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 @@ | @@ -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,8 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package exception.basic; | 37 | package exception.basic; |
| 38 | 38 | ||
| 39 | -import java.util.NoSuchElementException; | ||
| 40 | - | ||
| 41 | import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | 39 | import br.gov.frameworkdemoiselle.exception.ExceptionHandler; |
| 42 | import br.gov.frameworkdemoiselle.stereotype.Controller; | 40 | import br.gov.frameworkdemoiselle.stereotype.Controller; |
| 43 | 41 | ||
| @@ -62,22 +60,10 @@ public class MultiExceptionHandler { | @@ -62,22 +60,10 @@ public class MultiExceptionHandler { | ||
| 62 | return exceptionHandlerIllegalArgument3; | 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 | public void throwIllegalArgumentException() { | 63 | public void throwIllegalArgumentException() { |
| 74 | throw new IllegalArgumentException(); | 64 | throw new IllegalArgumentException(); |
| 75 | } | 65 | } |
| 76 | 66 | ||
| 77 | - public void throwNoSuchElementException() { | ||
| 78 | - throw new NoSuchElementException(); | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | @ExceptionHandler | 67 | @ExceptionHandler |
| 82 | public void handler1(IllegalArgumentException cause) { | 68 | public void handler1(IllegalArgumentException cause) { |
| 83 | exceptionHandlerIllegalArgument1 = true; | 69 | exceptionHandlerIllegalArgument1 = true; |
| @@ -93,9 +79,4 @@ public class MultiExceptionHandler { | @@ -93,9 +79,4 @@ public class MultiExceptionHandler { | ||
| 93 | exceptionHandlerIllegalArgument2 = true; | 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 | } |