Bug 572600: re-add old interface methods, yet deprecated

Change-Id: I34b70cfd5d2149aef51d9cdb14d836e6066c6c1f
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/ScriptResult.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/ScriptResult.java
index 21ff342..a7558b8 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/ScriptResult.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/ScriptResult.java
@@ -71,17 +71,6 @@
 		}
 	}
 
-	/**
-	 * Get the exception stored within this result.
-	 *
-	 * @return stored exception or null
-	 */
-	public final ScriptExecutionException getException() {
-		synchronized (this) {
-			return fException;
-		}
-	}
-
 	@Override
 	public final String toString() {
 		try {
@@ -93,17 +82,6 @@
 		}
 	}
 
-	/**
-	 * Checks whether this result contains an exception.
-	 *
-	 * @return true when this result contains an exception
-	 */
-	public final boolean hasException() {
-		synchronized (this) {
-			return (fException != null);
-		}
-	}
-
 	@Override
 	public boolean cancel(boolean mayInterruptIfRunning) {
 		return false;
@@ -125,30 +103,37 @@
 	public Object get() throws ExecutionException {
 		waitForResult();
 
-		return getResult();
+		return getResultOrThrow();
 	}
 
 	@Override
 	public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
 		waitForResult(unit.toMillis(timeout));
 
-		return getResult();
-	}
-
-	private Object getResult() throws ScriptExecutionException {
-		if (hasException())
-			throw getException();
-
-		synchronized (this) {
-			return fResult;
-		}
+		return getResultOrThrow();
 	}
 
 	public Object get(long milliSeconds) throws InterruptedException, ExecutionException, TimeoutException {
 		return get(milliSeconds, TimeUnit.MILLISECONDS);
 	}
 
-	private void waitForResult() throws ExecutionException {
+	private Object getResultOrThrow() throws ScriptExecutionException {
+		synchronized (this) {
+			if (fException != null)
+				throw fException;
+
+			return fResult;
+		}
+	}
+
+	/**
+	 * Blocks execution until the execution result is ready.
+	 *
+	 * @deprecated use {@link #get()}
+	 */
+	@Deprecated
+	public void waitForResult() throws ExecutionException {
+		// instead of removing this method should be marked 'private'
 		synchronized (this) {
 			while (!isDone()) {
 				try {
@@ -160,7 +145,17 @@
 		}
 	}
 
-	private void waitForResult(long milliseconds) throws InterruptedException, TimeoutException {
+	/**
+	 * Blocks execution until the execution result is ready or the timeout is reached. Once this method returns you still need to query {@link #isReady()} as
+	 * the timeout might have depleted.
+	 *
+	 * @param milliseconds
+	 *            the maximum time to wait in milliseconds.
+	 * @deprecated use {@link #get(long, TimeUnit)}
+	 */
+	@Deprecated
+	public void waitForResult(long milliseconds) throws InterruptedException, TimeoutException {
+		// instead of removing this method should be marked 'private'
 		final long waitUntil = System.currentTimeMillis() + milliseconds;
 		synchronized (this) {
 			while (!isDone() && (System.currentTimeMillis() < waitUntil))
@@ -170,4 +165,64 @@
 				throw new TimeoutException(String.format("Result not ready after %d milliseconds", milliseconds));
 		}
 	}
+
+	/**
+	 * Verify that this ScriptResult is processed. If the result is ready, execution of the underlying script is done.
+	 *
+	 * @return true when processing is done
+	 * @deprecated use {@link #isDone()}
+	 */
+	@Deprecated
+	public final boolean isReady() {
+		return isDone();
+	}
+
+	/**
+	 * Get the result value stored.
+	 *
+	 * @return result value
+	 * @deprecated use {@link #get()}
+	 */
+	@Deprecated
+	public final Object getResult() {
+		try {
+			return get();
+		} catch (final ExecutionException e) {
+			throw new RuntimeException("Execution failed", e);
+		}
+	}
+
+	/**
+	 * Get the exception stored within this result.
+	 *
+	 * @return stored exception or null
+	 * @deprecated use {@link #get()}
+	 */
+	@Deprecated
+	public final Throwable getException() {
+		try {
+			get();
+			throw new RuntimeException("Execution did not throw an exception");
+
+		} catch (final ExecutionException e) {
+			return e;
+		}
+	}
+
+	/**
+	 * Checks whether this result contains an exception.
+	 *
+	 * @return true when this result contains an exception
+	 * @deprecated use {@link #get()}
+	 */
+	@Deprecated
+	public final boolean hasException() {
+		try {
+			get();
+			return false;
+
+		} catch (final ExecutionException e) {
+			return true;
+		}
+	}
 }
diff --git a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ModeTestBase.java b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ModeTestBase.java
index f7a76c3..6663c76 100644
--- a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ModeTestBase.java
+++ b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ModeTestBase.java
@@ -13,7 +13,6 @@
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Arrays;
@@ -93,7 +92,6 @@
 	public void createPythonObject() throws Exception {
 		final ScriptResult result = executeCode("object()", false);
 		assertNotNull(result);
-		assertNull(result.getException());
 		assertNotNull(result.get());
 		assertTrue(result.get() instanceof String);
 		assertTrue(result.get().toString().startsWith("<object object at "));
@@ -112,7 +110,6 @@
 		executeCode(sb.toString(), false);
 		final ScriptResult result = executeCode("Foo()");
 		assertNotNull(result);
-		assertNull(result.getException());
 		assertNotNull(result.get());
 		assertTrue(result.get() instanceof IScriptable);
 	}
@@ -166,7 +163,6 @@
 	public void javaLongArray() throws Exception {
 		final ScriptResult result = executeCode("longArray([1, 2])", false);
 		assertNotNull(result);
-		assertNull(result.getException());
 		assertNotNull(result.get());
 
 		// FIXME: Different behavior between Python 2 and 3
diff --git a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTest.java b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTest.java
index 766e785..7684de1 100644
--- a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTest.java
+++ b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTest.java
@@ -11,7 +11,6 @@
 package org.eclipse.ease.lang.python.py4j;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
 
 import org.eclipse.ease.ScriptResult;
 import org.junit.jupiter.api.Disabled;
@@ -32,17 +31,13 @@
 
 		// try to use each function from the other mode
 		final ScriptResult resultScript_a = executeCode("a(20)", false);
-		assertNull(resultScript_a.getException());
 		assertEquals(21, resultScript_a.get());
 		final ScriptResult resultScript_b = executeCode("b(10)", false);
-		assertNull(resultScript_b.getException());
 		assertEquals(12, resultScript_b.get());
 
 		final ScriptResult result21 = executeCode("a(20)", true);
-		assertNull(result21.getException());
 		assertEquals(21, result21.get());
 		final ScriptResult result22 = executeCode("b(20)", true);
-		assertNull(result22.getException());
 		assertEquals(22, result22.get());
 	}
 
diff --git a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTestBase.java b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTestBase.java
index c7ae872..0b11e87 100644
--- a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTestBase.java
+++ b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/Py4JEngineTestBase.java
@@ -10,7 +10,6 @@
  *******************************************************************************/
 package org.eclipse.ease.lang.python.py4j;
 
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.eclipse.ease.IReplEngine;
@@ -44,7 +43,6 @@
 	protected ScriptResult push(String line, boolean expectMore) throws Exception {
 		final ScriptResult result = executeCode(line, true);
 		if (expectMore) {
-			assertNull(result.getException());
 			assertTrue(result.get() instanceof String);
 			assertTrue(result.get().toString().startsWith("..."));
 		}
diff --git a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ScriptModeEngineTest.java b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ScriptModeEngineTest.java
index 3be818b..94509c0 100644
--- a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ScriptModeEngineTest.java
+++ b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ScriptModeEngineTest.java
@@ -14,8 +14,10 @@
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import org.eclipse.ease.ScriptExecutionException;
 import org.eclipse.ease.ScriptResult;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
@@ -31,7 +33,6 @@
 	protected void executeCode(String code, Object target) throws Exception {
 		final ScriptResult result = super.executeCode(code, false);
 		assertNotNull(result);
-		assertNull(result.getException());
 		assertNotNull(result.get());
 		assertEquals(target, result.get());
 	}
@@ -52,7 +53,7 @@
 	@Test
 	public void incompleteStatement() throws Exception {
 		final ScriptResult result = executeCode("def a():");
-		assertNotNull(result.getException());
+		assertThrows(ScriptExecutionException.class, () -> result.get());
 		assertTrue(fErrorStream.getAndClearOutput().contains("SyntaxError"));
 		assertNull(result.get());
 	}
diff --git a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ShellModeEngineTest.java b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ShellModeEngineTest.java
index 4e19a74..8ae111a 100644
--- a/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ShellModeEngineTest.java
+++ b/tests/org.eclipse.ease.lang.python.py4j.test/src/org/eclipse/ease/lang/python/py4j/ShellModeEngineTest.java
@@ -15,8 +15,10 @@
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import org.eclipse.ease.ScriptExecutionException;
 import org.eclipse.ease.ScriptResult;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
@@ -32,7 +34,6 @@
 	protected void executeCode(String code, Object target) throws Exception {
 		final ScriptResult result = super.executeCode(code, true);
 		assertNotNull(result);
-		assertNull(result.getException());
 		assertNotNull(result.get());
 		assertEquals(target, result.get());
 	}
@@ -40,7 +41,6 @@
 	@Test
 	public void callModuleCode() throws Exception {
 		final ScriptResult result = executeCode("exit(\"done\")");
-		assertNull(result.getException());
 		assertEquals("done", result.get());
 	}
 
@@ -52,7 +52,6 @@
 	@Test
 	public void getScriptEngine() throws Exception {
 		final ScriptResult result = executeCode("getScriptEngine()");
-		assertNull(result.getException());
 		assertSame(fEngine, result.get());
 	}
 
@@ -96,14 +95,13 @@
 		push("", false);
 		// assertResultIsNone(push("", false));final
 		final ScriptResult result = push("a()", false);
-		assertNull(result.getException());
 		assertEquals(42, result.get());
 	}
 
 	@Test
 	public void invalidSyntax() throws Exception {
 		final ScriptResult result = executeCode("1++");
-		assertNotNull(result.getException());
+		assertThrows(ScriptExecutionException.class, () -> result.get());
 		assertTrue(fErrorStream.getAndClearOutput().contains("SyntaxError"));
 		assertNull(result.get());
 	}
@@ -111,7 +109,7 @@
 	@Test
 	public void runtimeError() throws Exception {
 		final ScriptResult result = executeCode("x");
-		assertNotNull(result.getException());
+		assertThrows(ScriptExecutionException.class, () -> result.get());
 		assertTrue(fErrorStream.getAndClearOutput().contains("NameError"));
 		assertNull(result.get());
 	}
diff --git a/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptResultTest.java b/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptResultTest.java
index f5145f4..f17283a 100644
--- a/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptResultTest.java
+++ b/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptResultTest.java
@@ -210,47 +210,4 @@
 		result.setException(EXCEPTION);
 		assertThrows(IllegalArgumentException.class, () -> result.setException(EXCEPTION));
 	}
-
-	@Test
-	public void isReady() {
-		ScriptResult result = new ScriptResult();
-		result.setResult(RESULT);
-		assertTrue(result.isDone());
-
-		result = new ScriptResult();
-		assertFalse(result.isDone());
-
-		result.setResult(RESULT);
-		assertTrue(result.isDone());
-
-		result = new ScriptResult();
-		result.setException(new ScriptExecutionException());
-		assertTrue(result.isDone());
-	}
-
-	@Test
-	public void getException() {
-		final ScriptResult result = new ScriptResult();
-		result.setException(EXCEPTION);
-
-		assertEquals(EXCEPTION, result.getException());
-	}
-
-	@Test
-	@DisplayName("hasException() == true when exception is present")
-	public void hasException_true_when_exception_is_present() {
-		final ScriptResult result = new ScriptResult();
-
-		result.setException(EXCEPTION);
-		assertTrue(result.hasException());
-	}
-
-	@Test
-	@DisplayName("hasException() == false when result is present")
-	public void hasException_false_when_result_is_present() {
-		final ScriptResult result = new ScriptResult();
-
-		result.setResult(RESULT);
-		assertFalse(result.hasException());
-	}
 }
diff --git a/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java b/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java
index 311bbc6..f466963 100644
--- a/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java
+++ b/tests/org.eclipse.ease.test/src/org/eclipse/ease/ScriptTest.java
@@ -3,7 +3,7 @@
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -131,6 +131,6 @@
 		final Script script = new Script(fFile);
 
 		script.setException(new ScriptExecutionException());
-		assertTrue(script.getResult().hasException());
+		assertThrows(ScriptExecutionException.class, () -> script.getResult().get());
 	}
 }