Skip to content

Instantly share code, notes, and snippets.

@nkpart
Created August 4, 2008 23:19
Show Gist options
  • Save nkpart/3993 to your computer and use it in GitHub Desktop.
Save nkpart/3993 to your computer and use it in GitHub Desktop.
package com.vlc.common.test.util;
import au.net.netstorm.boost.nursery.reflect.checker.AssertThrows;
import au.net.netstorm.boost.nursery.reflect.checker.DefaultAssertThrows;
public final class ExceptionTestChecker {
private static final AssertThrows ASSERT_THROWS = new DefaultAssertThrows();
private ExceptionTestChecker() {
throw new UnsupportedOperationException();
}
public static <T extends Throwable> Throwable expectException(final Class<T> expectedException, final String message, final Runnable block) {
return ASSERT_THROWS.assertThrows(expectedException, message, block);
}
public static <T extends Throwable> Throwable expectException(final Class<T> expectedException, final Runnable block) {
return ASSERT_THROWS.assertThrows(expectedException, block);
}
public static void expectMessageContains(final Throwable t, final String fragment) {
ASSERT_THROWS.assertMessageContains(t, fragment);
}
}
@Specification
public void shouldThrowOnInvalidLines() {
expectException(VlcRuntimeException.class, "Invalid dimension definition, expected 3 tokens: 200-12", new Runnable() {
public void run() {
dimensionCreator.apply(invalidLine1);
}
});
expectException(VlcRuntimeException.class, "Invalid dimension definition, types incorrect: 200-12-A", new Runnable() {
public void run() {
dimensionCreator.apply(invalidLine2);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment