1 17 18 package org.sablecc.sablecc.exception; 19 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.fail; 22 23 import org.junit.Before; 24 import org.junit.Test; 25 26 public class InvalidArgumentRuntimeExceptionTest { 27 28 InvalidArgumentRuntimeException exception; 29 30 String message; 31 32 Throwable cause; 33 34 @Before 35 public void setUp() { 36 37 this.message = "valid message"; 38 this.cause = new Throwable (); 39 } 40 41 @Test 42 public void testInvalidArgumentRuntimeExceptionString() { 43 44 String nullMessage = null; 46 try { 47 this.exception = new InvalidArgumentRuntimeException(nullMessage); 48 fail("message may not be null"); 49 } 50 catch (InternalException e) { 51 } 53 54 this.exception = new InvalidArgumentRuntimeException(this.message); 56 assertEquals("Invalid exception message", this.message, this.exception 57 .getMessage()); 58 } 59 60 @Test 61 public void testInvalidArgumentRuntimeExceptionStringThrowable() { 62 63 String nullMessage = null; 65 66 try { 67 this.exception = new InvalidArgumentRuntimeException(nullMessage, 68 this.cause); 69 fail("message may not be null"); 70 } 71 catch (InternalException e) { 72 } 74 75 Throwable nullCause = null; 77 try { 78 this.exception = new InvalidArgumentRuntimeException(this.message, 79 nullCause); 80 fail("a cause may not be null"); 81 } 82 catch (InternalException e) { 83 } 85 86 this.exception = new InvalidArgumentRuntimeException(this.message, 88 this.cause); 89 assertEquals("Invalid exception message", this.message, this.exception 90 .getMessage()); 91 assertEquals("Invalid exception cause", this.cause, this.exception 92 .getCause()); 93 } 94 95 } 96 | Popular Tags |