*/
package org.opendaylight.controller.netconf.persist.impl.osgi;
-import org.junit.matchers.JUnitMatchers;
-
+import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
final class TestingExceptionHandler implements Thread.UncaughtExceptionHandler {
+ private static final Logger LOG = LoggerFactory.getLogger(TestingExceptionHandler.class);
+
private Throwable t;
@Override
public void uncaughtException(Thread t, Throwable e) {
+ LOG.debug("Uncaught exception in thread {}", t, e);
this.t = e;
}
+ public void assertException(Class<? extends Exception> exType, String exMessageToContain) {
+ assertException(exMessageToContain, exType, exMessageToContain);
+ }
+
public void assertException(String failMessageSuffix, Class<? extends Exception> exType, String exMessageToContain) {
if(t == null) {
fail("Should fail to " + failMessageSuffix);
private void assertException(Throwable t, Class<? extends Exception> exType, String exMessageToContain) {
assertEquals("Expected exception of type " + exType + " but was " + t, exType, t.getClass());
if(exMessageToContain!=null) {
- assertThat(t.getMessage(), JUnitMatchers.containsString(exMessageToContain));
+ assertThat(t.getMessage(), containsString(exMessageToContain));
}
}