From edf064df04411405ee25a14b361a0350270af61f Mon Sep 17 00:00:00 2001 From: Ednara Oliveira Date: Tue, 23 Apr 2013 10:20:56 -0300 Subject: [PATCH] Testes de exceção --- impl/core/src/test/java/exception/ExceptionHandlerTwoParameter.java | 18 ++++++++++++++++++ impl/core/src/test/java/exception/MultiException.java | 2 -- impl/core/src/test/java/exception/MultiExceptionOneHandler.java | 18 ------------------ impl/core/src/test/java/exception/MultiExceptionTest.java | 18 +++++++----------- impl/core/src/test/java/exception/OneException.java | 14 ++++++++++++-- impl/core/src/test/java/exception/OneExceptionTest.java | 13 ++++++++++++- 6 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 impl/core/src/test/java/exception/ExceptionHandlerTwoParameter.java delete mode 100644 impl/core/src/test/java/exception/MultiExceptionOneHandler.java diff --git a/impl/core/src/test/java/exception/ExceptionHandlerTwoParameter.java b/impl/core/src/test/java/exception/ExceptionHandlerTwoParameter.java new file mode 100644 index 0000000..ae51937 --- /dev/null +++ b/impl/core/src/test/java/exception/ExceptionHandlerTwoParameter.java @@ -0,0 +1,18 @@ +package exception; + +import java.awt.geom.IllegalPathStateException; + +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; +import br.gov.frameworkdemoiselle.stereotype.Controller; + +@Controller +public class ExceptionHandlerTwoParameter { + + public void throwIllegalPathException() { + throw new IllegalPathStateException(); + } + + @ExceptionHandler + public void handler(IllegalPathStateException cause, IllegalStateException cause2) { + } +} diff --git a/impl/core/src/test/java/exception/MultiException.java b/impl/core/src/test/java/exception/MultiException.java index 2d54256..5876fb5 100644 --- a/impl/core/src/test/java/exception/MultiException.java +++ b/impl/core/src/test/java/exception/MultiException.java @@ -1,7 +1,5 @@ package exception; -import java.awt.geom.IllegalPathStateException; - import br.gov.frameworkdemoiselle.exception.ExceptionHandler; import br.gov.frameworkdemoiselle.stereotype.Controller; diff --git a/impl/core/src/test/java/exception/MultiExceptionOneHandler.java b/impl/core/src/test/java/exception/MultiExceptionOneHandler.java deleted file mode 100644 index af13f22..0000000 --- a/impl/core/src/test/java/exception/MultiExceptionOneHandler.java +++ /dev/null @@ -1,18 +0,0 @@ -package exception; - -import java.awt.geom.IllegalPathStateException; - -import br.gov.frameworkdemoiselle.exception.ExceptionHandler; -import br.gov.frameworkdemoiselle.stereotype.Controller; - -@Controller -public class MultiExceptionOneHandler { - - public void throwIllegalPathException() { - throw new IllegalPathStateException(); - } - - @ExceptionHandler - public void handler(IllegalPathStateException cause, IllegalStateException cause2) { - } -} diff --git a/impl/core/src/test/java/exception/MultiExceptionTest.java b/impl/core/src/test/java/exception/MultiExceptionTest.java index 727c2a1..7f801ce 100644 --- a/impl/core/src/test/java/exception/MultiExceptionTest.java +++ b/impl/core/src/test/java/exception/MultiExceptionTest.java @@ -22,7 +22,7 @@ public class MultiExceptionTest { private MultiException multiException; @Inject - private MultiExceptionOneHandler multiExceptionOneHandler; + private ExceptionHandlerTwoParameter exceptionTwoParameter; @Deployment public static JavaArchive createDeployment() { @@ -31,28 +31,24 @@ public class MultiExceptionTest { } @Test - public void testNullPointerExceptionHandler() { - multiException.throwNullPointerException(); - assertEquals(true, multiException.isNullPointerExceptionHandler()); - } - - @Test - public void testArithmeticExceptionHandler() { + public void testTwoExceptionTwoMethod() { multiException.throwArithmeticException(); + multiException.throwNullPointerException(); + assertEquals(true, multiException.isArithmeticExceptionHandler()); assertEquals(true, multiException.isArithmeticExceptionHandler()); } @Test - public void testMultiExceptionHandler() { + public void testTwoExceptionOneMethod() { multiException.throwTwoException(); assertEquals(true, multiException.isNullPointerExceptionHandler()); assertEquals(false, multiException.isArithmeticExceptionHandler()); } @Test - public void testExceptionHandlerWithTwoException() { + public void testExceptionHandlerWithTwoParameter() { try { - multiExceptionOneHandler.throwIllegalPathException(); + exceptionTwoParameter.throwIllegalPathException(); fail(); } catch (Exception e) { assertEquals(DemoiselleException.class, e.getClass()); diff --git a/impl/core/src/test/java/exception/OneException.java b/impl/core/src/test/java/exception/OneException.java index f784f14..8dd6f6b 100644 --- a/impl/core/src/test/java/exception/OneException.java +++ b/impl/core/src/test/java/exception/OneException.java @@ -1,5 +1,7 @@ package exception; +import java.util.NoSuchElementException; + import br.gov.frameworkdemoiselle.exception.ExceptionHandler; import br.gov.frameworkdemoiselle.stereotype.Controller; @@ -41,16 +43,19 @@ public class OneException { int result = 4/0; } - public void throwExceptionIllegalArgument() { + public void throwIllegalArgumentException() { throw new IllegalArgumentException(); } + + public void throwNoSuchElementException() { + throw new NoSuchElementException(); + } @ExceptionHandler public void handler(NullPointerException cause) { exceptionHandler = true; } - @ExceptionHandler public void handler1(IllegalArgumentException cause) { exceptionHandlerIllegalArgument1 = true; @@ -65,4 +70,9 @@ public class OneException { public void handler2(IllegalArgumentException cause) { exceptionHandlerIllegalArgument2 = true; } + + @ExceptionHandler + public void handlerWithError(NoSuchElementException cause) { + int a = 2/0; + } } diff --git a/impl/core/src/test/java/exception/OneExceptionTest.java b/impl/core/src/test/java/exception/OneExceptionTest.java index b44e7ec..47ced3b 100644 --- a/impl/core/src/test/java/exception/OneExceptionTest.java +++ b/impl/core/src/test/java/exception/OneExceptionTest.java @@ -43,9 +43,20 @@ public class OneExceptionTest { @Test public void testExceptionWithMultiHandler() { - oneException.throwExceptionIllegalArgument(); + oneException.throwIllegalArgumentException(); assertEquals(false, oneException.isExceptionHandlerIllegalArgument1()); assertEquals(true, oneException.isExceptionHandlerIllegalArgument2()); assertEquals(false, oneException.isExceptionHandlerIllegalArgument3()); } + + @Test + public void testExceptionHandlerWithException() { + try { + oneException.throwNoSuchElementException(); + } catch (Exception e) { + assertEquals(ArithmeticException.class, e.getClass()); + } + + + } } -- libgit2 0.21.2