--- a/langtools/test/jdk/jshell/ReplaceTest.java Tue Aug 09 13:22:57 2016 -0700
+++ b/langtools/test/jdk/jshell/ReplaceTest.java Tue Aug 09 23:00:49 2016 -0700
@@ -28,9 +28,9 @@
* @run testng ReplaceTest
*/
-import java.util.Collection;
-
+import java.util.Iterator;
import java.util.List;
+import java.util.stream.Stream;
import jdk.jshell.Snippet;
import jdk.jshell.MethodSnippet;
import jdk.jshell.PersistentSnippet;
@@ -42,6 +42,7 @@
import jdk.jshell.SnippetEvent;
import jdk.jshell.UnresolvedReferenceException;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static jdk.jshell.Snippet.Status.*;
import static jdk.jshell.Snippet.SubKind.*;
import static org.testng.Assert.assertTrue;
@@ -90,17 +91,22 @@
assertActiveKeys();
}
+ private <T extends Snippet> void identityMatch(Stream<T> got, T expected) {
+ Iterator<T> it = got.iterator();
+ assertTrue(it.hasNext(), "expected exactly one");
+ assertTrue(expected == it.next(), "Identity must not change");
+ assertFalse(it.hasNext(), "expected exactly one");
+ }
+
public void testReplaceVarToMethod() {
Snippet x = varKey(assertEval("int x;"));
- Snippet musn = methodKey(assertEval("double mu() { return x * 4; }"));
+ MethodSnippet musn = methodKey(assertEval("double mu() { return x * 4; }"));
assertEval("x == 0;", "true");
assertEval("mu() == 0.0;", "true");
assertEval("double x = 2.5;",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
- Collection<MethodSnippet> meths = getState().methods();
- assertEquals(meths.size(), 1);
- assertTrue(musn == meths.iterator().next(), "Identity must not change");
+ identityMatch(getState().methods(), musn);
assertEval("x == 2.5;", "true");
assertEval("mu() == 10.0;", "true"); // Auto redefine
assertActiveKeys();
@@ -132,15 +138,13 @@
public void testReplaceVarToClass() {
Snippet x = varKey(assertEval("int x;"));
- Snippet c = classKey(assertEval("class A { double a = 4 * x; }"));
+ TypeDeclSnippet c = classKey(assertEval("class A { double a = 4 * x; }"));
assertEval("x == 0;", "true");
assertEval("new A().a == 0.0;", "true");
assertEval("double x = 2.5;",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
- Collection<TypeDeclSnippet> classes = getState().types();
- assertEquals(classes.size(), 1);
- assertTrue(c == classes.iterator().next(), "Identity must not change");
+ identityMatch(getState().types(), c);
assertEval("x == 2.5;", "true");
assertEval("new A().a == 10.0;", "true");
assertActiveKeys();
@@ -148,16 +152,14 @@
public void testReplaceMethodToClass() {
Snippet x = methodKey(assertEval("int x() { return 0; }"));
- Snippet c = classKey(assertEval("class A { double a = 4 * x(); }"));
+ TypeDeclSnippet c = classKey(assertEval("class A { double a = 4 * x(); }"));
assertEval("x() == 0;", "true");
assertEval("new A().a == 0.0;", "true");
assertEval("double x() { return 2.5; }",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertEval("x();", "2.5");
- Collection<TypeDeclSnippet> classes = getState().types();
- assertEquals(classes.size(), 1);
- assertTrue(c == classes.iterator().next(), "Identity must not change");
+ identityMatch(getState().types(), c);
assertEval("x() == 2.5;", "true");
assertEval("new A().a == 10.0;", "true");
assertActiveKeys();
@@ -313,8 +315,8 @@
Snippet assn = ste.snippet();
DeclarationSnippet unsn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
assertEquals(unsn.name(), "A", "Wrong with unresolved");
- assertEquals(getState().unresolvedDependencies(unsn).size(), 1, "Wrong size unresolved");
- assertEquals(getState().diagnostics(unsn).size(), 0, "Expected no diagnostics");
+ assertEquals(getState().unresolvedDependencies(unsn).count(), 1, "Wrong size unresolved");
+ assertEquals(getState().diagnostics(unsn).count(), 0L, "Expected no diagnostics");
Snippet g = varKey(assertEval("int g = 10;", "10",
added(VALID),