|
| 1 | +/** |
| 2 | + * Copyright (c) 2015 Digi International Inc., |
| 3 | + * All rights not expressly granted are reserved. |
| 4 | + * |
| 5 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 7 | + * You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | + * |
| 9 | + * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
| 10 | + * ======================================================================= |
| 11 | + */ |
| 12 | +package com.digi.xbee.api.exceptions; |
| 13 | + |
| 14 | +import static org.hamcrest.core.Is.is; |
| 15 | +import static org.hamcrest.core.IsEqual.equalTo; |
| 16 | +import static org.hamcrest.core.IsNull.nullValue; |
| 17 | +import static org.junit.Assert.assertThat; |
| 18 | + |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.AfterClass; |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.BeforeClass; |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +public class CommunicationExceptionTest { |
| 26 | + |
| 27 | + /** |
| 28 | + * @throws java.lang.Exception |
| 29 | + */ |
| 30 | + @BeforeClass |
| 31 | + public static void setUpBeforeClass() throws Exception { |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @throws java.lang.Exception |
| 36 | + */ |
| 37 | + @AfterClass |
| 38 | + public static void tearDownAfterClass() throws Exception { |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @throws java.lang.Exception |
| 43 | + */ |
| 44 | + @Before |
| 45 | + public void setUp() throws Exception { |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @throws java.lang.Exception |
| 50 | + */ |
| 51 | + @After |
| 52 | + public void tearDown() throws Exception { |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException()}. |
| 57 | + */ |
| 58 | + @Test |
| 59 | + public final void testCreateCommunicationExceptionDefault() { |
| 60 | + // Setup the resources for the test. |
| 61 | + |
| 62 | + // Call the method under test. |
| 63 | + CommunicationException e = new CommunicationException(); |
| 64 | + |
| 65 | + // Verify the result. |
| 66 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 67 | + e.getMessage(), is(nullValue(String.class))); |
| 68 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 69 | + e.getCause(), is(nullValue(Throwable.class))); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(Throwable))}. |
| 74 | + */ |
| 75 | + @Test |
| 76 | + public final void testCreateCommunicationExceptionCause() { |
| 77 | + // Setup the resources for the test. |
| 78 | + Throwable cause = new Exception(); |
| 79 | + |
| 80 | + // Call the method under test. |
| 81 | + CommunicationException e = new CommunicationException(cause); |
| 82 | + |
| 83 | + // Verify the result. |
| 84 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 85 | + e.getMessage(), is(equalTo(cause.toString()))); |
| 86 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 87 | + e.getCause(), is(equalTo(cause))); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(Throwable)}. |
| 92 | + */ |
| 93 | + @Test |
| 94 | + public final void testCreateCommunicationExceptionCauseNull() { |
| 95 | + // Setup the resources for the test. |
| 96 | + Throwable cause = null; |
| 97 | + |
| 98 | + // Call the method under test. |
| 99 | + CommunicationException e = new CommunicationException(cause); |
| 100 | + |
| 101 | + // Verify the result. |
| 102 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 103 | + e.getMessage(), is(nullValue(String.class))); |
| 104 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 105 | + e.getCause(), is(nullValue(Throwable.class))); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(String)}. |
| 110 | + */ |
| 111 | + @Test |
| 112 | + public final void testCreateCommunicationExceptionMessage() { |
| 113 | + // Setup the resources for the test. |
| 114 | + String message = "This is the message"; |
| 115 | + |
| 116 | + // Call the method under test. |
| 117 | + CommunicationException e = new CommunicationException(message); |
| 118 | + |
| 119 | + // Verify the result. |
| 120 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 121 | + e.getMessage(), is(equalTo(message))); |
| 122 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 123 | + e.getCause(), is(nullValue(Throwable.class))); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(String)}. |
| 128 | + */ |
| 129 | + @Test |
| 130 | + public final void testCreateCommunicationExceptionMessageNull() { |
| 131 | + // Setup the resources for the test. |
| 132 | + String message = null; |
| 133 | + |
| 134 | + // Call the method under test. |
| 135 | + CommunicationException e = new CommunicationException(message); |
| 136 | + |
| 137 | + // Verify the result. |
| 138 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 139 | + e.getMessage(), is(equalTo(message))); |
| 140 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 141 | + e.getCause(), is(nullValue(Throwable.class))); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(String, Throwable)}. |
| 146 | + */ |
| 147 | + @Test |
| 148 | + public final void testCreateCommunicationExceptionMessageAndCause() { |
| 149 | + // Setup the resources for the test. |
| 150 | + String message = "This is the message"; |
| 151 | + Throwable cause = new Exception(); |
| 152 | + |
| 153 | + // Call the method under test. |
| 154 | + CommunicationException e = new CommunicationException(message, cause); |
| 155 | + |
| 156 | + // Verify the result. |
| 157 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 158 | + e.getMessage(), is(equalTo(message))); |
| 159 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 160 | + e.getCause(), is(equalTo(cause))); |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(String, Throwable)}. |
| 165 | + */ |
| 166 | + @Test |
| 167 | + public final void testCommunicationExceptionMessageNullAndCause() { |
| 168 | + // Setup the resources for the test. |
| 169 | + String message = null; |
| 170 | + Throwable cause = new Exception(); |
| 171 | + |
| 172 | + // Call the method under test. |
| 173 | + CommunicationException e = new CommunicationException(message, cause); |
| 174 | + |
| 175 | + // Verify the result. |
| 176 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 177 | + e.getMessage(), is(equalTo(message))); |
| 178 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 179 | + e.getCause(), is(equalTo(cause))); |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(String, Throwable)}. |
| 184 | + */ |
| 185 | + @Test |
| 186 | + public final void testCreateCommunicationExceptionMessageAndCauseNull() { |
| 187 | + // Setup the resources for the test. |
| 188 | + String message = "This is the message"; |
| 189 | + Throwable cause = null; |
| 190 | + |
| 191 | + // Call the method under test. |
| 192 | + CommunicationException e = new CommunicationException(message, cause); |
| 193 | + |
| 194 | + // Verify the result. |
| 195 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 196 | + e.getMessage(), is(equalTo(message))); |
| 197 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 198 | + e.getCause(), is(equalTo(cause))); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#CommunicationException(String, Throwable)}. |
| 203 | + */ |
| 204 | + @Test |
| 205 | + public final void testCreateCommunicationExceptionMessageAndCauseBothNull() { |
| 206 | + // Setup the resources for the test. |
| 207 | + String message = null; |
| 208 | + Throwable cause = null; |
| 209 | + |
| 210 | + // Call the method under test. |
| 211 | + CommunicationException e = new CommunicationException(message, cause); |
| 212 | + |
| 213 | + // Verify the result. |
| 214 | + assertThat("Created 'CommunicationException' does not have the expected message", |
| 215 | + e.getMessage(), is(equalTo(message))); |
| 216 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 217 | + e.getCause(), is(equalTo(cause))); |
| 218 | + } |
| 219 | + |
| 220 | + /** |
| 221 | + * Test method for {@link com.digi.xbee.api.exceptions.CommunicationException#getCause()}. |
| 222 | + */ |
| 223 | + @Test |
| 224 | + public final void testGetCause() { |
| 225 | + // Setup the resources for the test. |
| 226 | + Throwable cause = new Exception(); |
| 227 | + CommunicationException e = new CommunicationException(); |
| 228 | + e.initCause(cause); |
| 229 | + |
| 230 | + // Call the method under test. |
| 231 | + Throwable result = e.getCause(); |
| 232 | + |
| 233 | + // Verify the result. |
| 234 | + assertThat("Created 'CommunicationException' does not have the expected cause", |
| 235 | + result, is(equalTo(cause))); |
| 236 | + } |
| 237 | +} |
0 commit comments