blob: 2a76d06561d41193d02f9db0e4968025758f26d2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.core.tests.runtime.jobs;
import java.io.*;
import junit.framework.TestCase;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
/**
* Common superclass for all tests of the org.eclipse.core.runtime.jobs API. Provides
* convenience methods useful for testing jobs.
*/
public class AbstractJobTest extends TestCase {
public AbstractJobTest() {
super("");
}
public AbstractJobTest(String name) {
super(name);
}
/**
* Fails the test due to the given exception.
* @param message
* @param e
*/
public void fail(String message, Throwable e) {
// If the exception is a CoreException with a multistatus
// then print out the multistatus so we can see all the info.
if (e instanceof CoreException) {
IStatus status = ((CoreException) e).getStatus();
if (status.getChildren().length > 0) {
write(status, 0);
}
}
fail(message + ": " + e);
}
protected void indent(OutputStream output, int indent) {
for (int i = 0; i < indent; i++)
try {
output.write("\t".getBytes());
} catch (IOException e) {
//ignore
}
}
protected void sleep(long duration) {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
//ignore
}
}
protected void write(IStatus status, int indent) {
PrintStream output = System.out;
indent(output, indent);
output.println("Severity: " + status.getSeverity());
indent(output, indent);
output.println("Plugin ID: " + status.getPlugin());
indent(output, indent);
output.println("Code: " + status.getCode());
indent(output, indent);
output.println("Message: " + status.getMessage());
if (status.isMultiStatus()) {
IStatus[] children = status.getChildren();
for (int i = 0; i < children.length; i++) {
write(children[i], indent + 1);
}
}
}
}