Skip to content

Commit

Permalink
runtime tests: throw dedicated TestException
Browse files Browse the repository at this point in the history
To make it easier to filter test output for unintended exceptions.
  • Loading branch information
jukzi committed Dec 20, 2024
1 parent ca5ed8a commit 470362a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public class LogSerializationTest {

static class TestException extends Exception {
private static final long serialVersionUID = 1L;

TestException() {
super();
}
}

private File logFile = null;
Expand Down Expand Up @@ -139,7 +135,16 @@ protected IStatus[] getInterestingMultiStatuses() {
interestingChildren[i] = subArray;
}
int childOff = 0;
return new IStatus[] {new MultiStatus("plugin-id", 1, interestingChildren[childOff++ % len], "message", null), new MultiStatus("org.foo.bar", 5, interestingChildren[childOff++ % len], "message", new NullPointerException()), new MultiStatus("plugin-id", 8, interestingChildren[childOff++ % len], "message", null), new MultiStatus("plugin-id", 0, interestingChildren[childOff++ % len], "message", new IllegalStateException()), new MultiStatus("plugin-id", 65756, interestingChildren[childOff++ % len], "message", null), new MultiStatus(".", 1, interestingChildren[childOff++ % len], "message", null), new MultiStatus("org.foo.blaz", 1, interestingChildren[childOff++ % len], "", null), new MultiStatus("plugin-id", 1, interestingChildren[childOff++ % len], "%$(% 98%(%(*^", null),
return new IStatus[] { new MultiStatus("plugin-id", 1, interestingChildren[childOff++ % len], "message", null),
new MultiStatus("org.foo.bar", 5, interestingChildren[childOff++ % len], "message",
new TestException()),
new MultiStatus("plugin-id", 8, interestingChildren[childOff++ % len], "message", null),
new MultiStatus("plugin-id", 0, interestingChildren[childOff++ % len], "message",
new TestException()),
new MultiStatus("plugin-id", 65756, interestingChildren[childOff++ % len], "message", null),
new MultiStatus(".", 1, interestingChildren[childOff++ % len], "message", null),
new MultiStatus("org.foo.blaz", 1, interestingChildren[childOff++ % len], "", null),
new MultiStatus("plugin-id", 1, interestingChildren[childOff++ % len], "%$(% 98%(%(*^", null),
new MultiStatus("plugin-id", 1, "message", null), new MultiStatus("..", 87326, "", null),};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public void testGetLogLocation() throws IOException {
assertEquals("4.0", initialLocation, Platform.getLogFileLocation());
}

static class TestException extends Exception {
private static final long serialVersionUID = 1L;
}
@Test
public void testRunnable() {
final List<Throwable> exceptions = new ArrayList<>();
Expand All @@ -152,7 +155,7 @@ public void testRunnable() {
ILogListener logListener = (status, plugin) -> collected.add(status);
Platform.addLogListener(logListener);

final Exception exception = new Exception("PlatformTest.testRunnable: this exception is thrown on purpose as part of the test.");
final Exception exception = new TestException();
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ public boolean shouldRun() {

}

static class TestException extends RuntimeException {
private static final long serialVersionUID = 1L;
}

/**
* Test of an ill-behaving {@link Job#shouldRun()}.
*/
Expand All @@ -463,7 +467,7 @@ protected IStatus run(IProgressMonitor monitor) {

@Override
public boolean shouldRun() {
throw new RuntimeException("Exception thrown on purpose as part of a test");
throw new TestException();
}
}
ShouldRunJob j = new ShouldRunJob();
Expand Down Expand Up @@ -1085,7 +1089,7 @@ public void testJoinFailingListener() throws InterruptedException {
shortJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
throw new RuntimeException("This exception thrown on purpose as part of a test");
throw new TestException();
}
});
final AtomicIntegerArray status = new AtomicIntegerArray(new int[1]);
Expand Down

0 comments on commit 470362a

Please sign in to comment.