001 package org.apache.commons.inject.util; 002 003 import static org.junit.Assert.*; 004 005 import java.lang.reflect.UndeclaredThrowableException; 006 007 import org.junit.Assert; 008 import org.junit.Test; 009 010 public class ExceptionsTest { 011 @Test 012 public void testShowRTE() { 013 final NullPointerException npe = new NullPointerException(); 014 Throwable th = null; 015 try { 016 throw Exceptions.show(npe); 017 } catch (Throwable t) { 018 th = t; 019 } 020 Assert.assertNotNull(th); 021 Assert.assertSame(npe, th); 022 } 023 024 @Test 025 public void testShowError() { 026 final OutOfMemoryError oome = new OutOfMemoryError(); 027 Throwable th = null; 028 try { 029 throw Exceptions.show(oome); 030 } catch (Throwable t) { 031 th = t; 032 } 033 Assert.assertNotNull(th); 034 Assert.assertSame(oome, th); 035 } 036 037 @Test 038 public void testShowThrowable() { 039 final Throwable t0 = new Throwable("Some throwable"){ 040 }; 041 Throwable th = null; 042 try { 043 throw Exceptions.show(t0); 044 } catch (UndeclaredThrowableException ute) { 045 th = ute.getCause(); 046 } 047 Assert.assertNotNull(th); 048 Assert.assertSame(t0, th); } 049 050 }