提交 56d3f322 编写于 作者: S snazarki

8037866: Replace the Fun class in tests with lambdas

Reviewed-by: andrew, aph
上级 a3f3ff42
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -943,18 +943,13 @@ public class Basic { ...@@ -943,18 +943,13 @@ public class Basic {
equal(pb.redirectError(), Redirect.to(efile)); equal(pb.redirectError(), Redirect.to(efile));
THROWS(IllegalArgumentException.class, THROWS(IllegalArgumentException.class,
new Fun(){void f() { () -> pb.redirectInput(Redirect.to(ofile)),
pb.redirectInput(Redirect.to(ofile)); }}, () -> pb.redirectOutput(Redirect.from(ifile)),
new Fun(){void f() { () -> pb.redirectError(Redirect.from(ifile)));
pb.redirectInput(Redirect.appendTo(ofile)); }},
new Fun(){void f() {
pb.redirectOutput(Redirect.from(ifile)); }},
new Fun(){void f() {
pb.redirectError(Redirect.from(ifile)); }});
THROWS(IOException.class, THROWS(IOException.class,
// Input file does not exist // Input file does not exist
new Fun(){void f() throws Throwable { pb.start(); }}); () -> pb.start());
setFileContents(ifile, "standard input"); setFileContents(ifile, "standard input");
//---------------------------------------------------------------- //----------------------------------------------------------------
...@@ -1090,18 +1085,15 @@ public class Basic { ...@@ -1090,18 +1085,15 @@ public class Basic {
= new FilePermission("<<ALL FILES>>", "read,write,execute"); = new FilePermission("<<ALL FILES>>", "read,write,execute");
THROWS(SecurityException.class, THROWS(SecurityException.class,
new Fun() { void f() throws IOException { () -> { policy.setPermissions(xPermission);
policy.setPermissions(xPermission); redirectIO(pb, from(tmpFile), PIPE, PIPE);
redirectIO(pb, from(tmpFile), PIPE, PIPE); pb.start();},
pb.start();}}, () -> { policy.setPermissions(rxPermission);
new Fun() { void f() throws IOException { redirectIO(pb, PIPE, to(ofile), PIPE);
policy.setPermissions(rxPermission); pb.start();},
redirectIO(pb, PIPE, to(ofile), PIPE); () -> { policy.setPermissions(rxPermission);
pb.start();}}, redirectIO(pb, PIPE, PIPE, to(efile));
new Fun() { void f() throws IOException { pb.start();});
policy.setPermissions(rxPermission);
redirectIO(pb, PIPE, PIPE, to(efile));
pb.start();}});
{ {
policy.setPermissions(rxPermission); policy.setPermissions(rxPermission);
...@@ -1212,10 +1204,10 @@ public class Basic { ...@@ -1212,10 +1204,10 @@ public class Basic {
// System.getenv() is read-only. // System.getenv() is read-only.
//---------------------------------------------------------------- //----------------------------------------------------------------
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ getenv().put("FOO","BAR");}}, () -> getenv().put("FOO","BAR"),
new Fun(){void f(){ getenv().remove("PATH");}}, () -> getenv().remove("PATH"),
new Fun(){void f(){ getenv().keySet().remove("PATH");}}, () -> getenv().keySet().remove("PATH"),
new Fun(){void f(){ getenv().values().remove("someValue");}}); () -> getenv().values().remove("someValue"));
try { try {
Collection<Map.Entry<String,String>> c = getenv().entrySet(); Collection<Map.Entry<String,String>> c = getenv().entrySet();
...@@ -1240,19 +1232,17 @@ public class Basic { ...@@ -1240,19 +1232,17 @@ public class Basic {
{ {
final Map<String,String> m = new ProcessBuilder().environment(); final Map<String,String> m = new ProcessBuilder().environment();
THROWS(IllegalArgumentException.class, THROWS(IllegalArgumentException.class,
new Fun(){void f(){ m.put("FOO=","BAR");}}, () -> m.put("FOO=","BAR"),
new Fun(){void f(){ m.put("FOO\u0000","BAR");}}, () -> m.put("FOO\u0000","BAR"),
new Fun(){void f(){ m.put("FOO","BAR\u0000");}}); () -> m.put("FOO","BAR\u0000"));
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
// Commands must never be null. // Commands must never be null.
//---------------------------------------------------------------- //----------------------------------------------------------------
THROWS(NullPointerException.class, THROWS(NullPointerException.class,
new Fun(){void f(){ () -> new ProcessBuilder((List<String>)null),
new ProcessBuilder((List<String>)null);}}, () -> new ProcessBuilder().command((List<String>)null));
new Fun(){void f(){
new ProcessBuilder().command((List<String>)null);}});
//---------------------------------------------------------------- //----------------------------------------------------------------
// Put in a command; get the same one back out. // Put in a command; get the same one back out.
...@@ -1277,25 +1267,18 @@ public class Basic { ...@@ -1277,25 +1267,18 @@ public class Basic {
// Commands must contain at least one element. // Commands must contain at least one element.
//---------------------------------------------------------------- //----------------------------------------------------------------
THROWS(IndexOutOfBoundsException.class, THROWS(IndexOutOfBoundsException.class,
new Fun() { void f() throws IOException { () -> new ProcessBuilder().start(),
new ProcessBuilder().start();}}, () -> new ProcessBuilder(new ArrayList<String>()).start(),
new Fun() { void f() throws IOException { () -> Runtime.getRuntime().exec(new String[]{}));
new ProcessBuilder(new ArrayList<String>()).start();}},
new Fun() { void f() throws IOException {
Runtime.getRuntime().exec(new String[]{});}});
//---------------------------------------------------------------- //----------------------------------------------------------------
// Commands must not contain null elements at start() time. // Commands must not contain null elements at start() time.
//---------------------------------------------------------------- //----------------------------------------------------------------
THROWS(NullPointerException.class, THROWS(NullPointerException.class,
new Fun() { void f() throws IOException { () -> new ProcessBuilder("foo",null,"bar").start(),
new ProcessBuilder("foo",null,"bar").start();}}, () -> new ProcessBuilder((String)null).start(),
new Fun() { void f() throws IOException { () -> new ProcessBuilder(new String[]{null}).start(),
new ProcessBuilder((String)null).start();}}, () -> new ProcessBuilder(new String[]{"foo",null,"bar"}).start());
new Fun() { void f() throws IOException {
new ProcessBuilder(new String[]{null}).start();}},
new Fun() { void f() throws IOException {
new ProcessBuilder(new String[]{"foo",null,"bar"}).start();}});
//---------------------------------------------------------------- //----------------------------------------------------------------
// Command lists are growable. // Command lists are growable.
...@@ -1312,15 +1295,13 @@ public class Basic { ...@@ -1312,15 +1295,13 @@ public class Basic {
try { try {
final Map<String,String> env = new ProcessBuilder().environment(); final Map<String,String> env = new ProcessBuilder().environment();
THROWS(NullPointerException.class, THROWS(NullPointerException.class,
new Fun(){void f(){ env.put("foo",null);}}, () -> env.put("foo",null),
new Fun(){void f(){ env.put(null,"foo");}}, () -> env.put(null,"foo"),
new Fun(){void f(){ env.remove(null);}}, () -> env.remove(null),
new Fun(){void f(){ () -> { for (Map.Entry<String,String> e : env.entrySet())
for (Map.Entry<String,String> e : env.entrySet()) e.setValue(null);},
e.setValue(null);}}, () -> Runtime.getRuntime().exec(new String[]{"foo"},
new Fun() { void f() throws IOException { new String[]{null}));
Runtime.getRuntime().exec(new String[]{"foo"},
new String[]{null});}});
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
//---------------------------------------------------------------- //----------------------------------------------------------------
...@@ -1329,10 +1310,10 @@ public class Basic { ...@@ -1329,10 +1310,10 @@ public class Basic {
try { try {
final Map<String,String> env = new ProcessBuilder().environment(); final Map<String,String> env = new ProcessBuilder().environment();
THROWS(ClassCastException.class, THROWS(ClassCastException.class,
new Fun(){void f(){ env.remove(TRUE);}}, () -> env.remove(TRUE),
new Fun(){void f(){ env.keySet().remove(TRUE);}}, () -> env.keySet().remove(TRUE),
new Fun(){void f(){ env.values().remove(TRUE);}}, () -> env.values().remove(TRUE),
new Fun(){void f(){ env.entrySet().remove(TRUE);}}); () -> env.entrySet().remove(TRUE));
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
//---------------------------------------------------------------- //----------------------------------------------------------------
...@@ -1348,22 +1329,22 @@ public class Basic { ...@@ -1348,22 +1329,22 @@ public class Basic {
// Nulls in environment queries are forbidden. // Nulls in environment queries are forbidden.
//---------------------------------------------------------------- //----------------------------------------------------------------
THROWS(NullPointerException.class, THROWS(NullPointerException.class,
new Fun(){void f(){ getenv(null);}}, () -> getenv(null),
new Fun(){void f(){ env.get(null);}}, () -> env.get(null),
new Fun(){void f(){ env.containsKey(null);}}, () -> env.containsKey(null),
new Fun(){void f(){ env.containsValue(null);}}, () -> env.containsValue(null),
new Fun(){void f(){ env.keySet().contains(null);}}, () -> env.keySet().contains(null),
new Fun(){void f(){ env.values().contains(null);}}); () -> env.values().contains(null));
//---------------------------------------------------------------- //----------------------------------------------------------------
// Non-String types in environment queries are forbidden. // Non-String types in environment queries are forbidden.
//---------------------------------------------------------------- //----------------------------------------------------------------
THROWS(ClassCastException.class, THROWS(ClassCastException.class,
new Fun(){void f(){ env.get(TRUE);}}, () -> env.get(TRUE),
new Fun(){void f(){ env.containsKey(TRUE);}}, () -> env.containsKey(TRUE),
new Fun(){void f(){ env.containsValue(TRUE);}}, () -> env.containsValue(TRUE),
new Fun(){void f(){ env.keySet().contains(TRUE);}}, () -> env.keySet().contains(TRUE),
new Fun(){void f(){ env.values().contains(TRUE);}}); () -> env.values().contains(TRUE));
//---------------------------------------------------------------- //----------------------------------------------------------------
// Illegal String values in environment queries are (grumble) OK // Illegal String values in environment queries are (grumble) OK
...@@ -1381,12 +1362,11 @@ public class Basic { ...@@ -1381,12 +1362,11 @@ public class Basic {
final Set<Map.Entry<String,String>> entrySet = final Set<Map.Entry<String,String>> entrySet =
new ProcessBuilder().environment().entrySet(); new ProcessBuilder().environment().entrySet();
THROWS(NullPointerException.class, THROWS(NullPointerException.class,
new Fun(){void f(){ entrySet.contains(null);}}); () -> entrySet.contains(null));
THROWS(ClassCastException.class, THROWS(ClassCastException.class,
new Fun(){void f(){ entrySet.contains(TRUE);}}, () -> entrySet.contains(TRUE),
new Fun(){void f(){ () -> entrySet.contains(
entrySet.contains( new SimpleImmutableEntry<Boolean,String>(TRUE,"")));
new SimpleImmutableEntry<Boolean,String>(TRUE,""));}});
check(! entrySet.contains check(! entrySet.contains
(new SimpleImmutableEntry<String,String>("", ""))); (new SimpleImmutableEntry<String,String>("", "")));
...@@ -1856,8 +1836,7 @@ public class Basic { ...@@ -1856,8 +1836,7 @@ public class Basic {
final ProcessBuilder pb = final ProcessBuilder pb =
new ProcessBuilder(new String[]{"unliKely"}); new ProcessBuilder(new String[]{"unliKely"});
pb.environment().put("PATH", "suBdiR"); pb.environment().put("PATH", "suBdiR");
THROWS(IOException.class, THROWS(IOException.class, () -> pb.start());
new Fun() {void f() throws Throwable {pb.start();}});
} catch (Throwable t) { unexpected(t); } catch (Throwable t) { unexpected(t);
} finally { } finally {
new File("suBdiR/unliKely").delete(); new File("suBdiR/unliKely").delete();
...@@ -1930,10 +1909,8 @@ public class Basic { ...@@ -1930,10 +1909,8 @@ public class Basic {
equal(SIZE, p.getInputStream().available()); equal(SIZE, p.getInputStream().available());
equal(SIZE, p.getErrorStream().available()); equal(SIZE, p.getErrorStream().available());
THROWS(IOException.class, THROWS(IOException.class,
new Fun(){void f() throws IOException { () -> { p.getOutputStream().write((byte) '!');
p.getOutputStream().write((byte) '!'); p.getOutputStream().flush();});
p.getOutputStream().flush();
}});
final byte[] bytes = new byte[SIZE + 1]; final byte[] bytes = new byte[SIZE + 1];
equal(SIZE, p.getInputStream().read(bytes)); equal(SIZE, p.getInputStream().read(bytes));
...@@ -1960,12 +1937,9 @@ public class Basic { ...@@ -1960,12 +1937,9 @@ public class Basic {
InputStream[] streams = { p.getInputStream(), p.getErrorStream() }; InputStream[] streams = { p.getInputStream(), p.getErrorStream() };
for (final InputStream in : streams) { for (final InputStream in : streams) {
Fun[] ops = { Fun[] ops = {
new Fun(){void f() throws IOException { () -> in.read(),
in.read(); }}, () -> in.read(bytes),
new Fun(){void f() throws IOException { () -> in.available()
in.read(bytes); }},
new Fun(){void f() throws IOException {
in.available(); }}
}; };
for (Fun op : ops) { for (Fun op : ops) {
try { try {
...@@ -2169,21 +2143,17 @@ public class Basic { ...@@ -2169,21 +2143,17 @@ public class Basic {
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
THROWS(SecurityException.class, THROWS(SecurityException.class,
new Fun() { void f() throws IOException { () -> { policy.setPermissions(/* Nothing */);
policy.setPermissions(/* Nothing */); System.getenv("foo");},
System.getenv("foo");}}, () -> { policy.setPermissions(/* Nothing */);
new Fun() { void f() throws IOException { System.getenv();},
policy.setPermissions(/* Nothing */); () -> { policy.setPermissions(/* Nothing */);
System.getenv();}}, new ProcessBuilder("echo").start();},
new Fun() { void f() throws IOException { () -> { policy.setPermissions(/* Nothing */);
policy.setPermissions(/* Nothing */); Runtime.getRuntime().exec("echo");},
new ProcessBuilder("echo").start();}}, () -> { policy.setPermissions(
new Fun() { void f() throws IOException { new RuntimePermission("getenv.bar"));
policy.setPermissions(/* Nothing */); System.getenv("foo");});
Runtime.getRuntime().exec("echo");}},
new Fun() { void f() throws IOException {
policy.setPermissions(new RuntimePermission("getenv.bar"));
System.getenv("foo");}});
try { try {
policy.setPermissions(new RuntimePermission("getenv.foo")); policy.setPermissions(new RuntimePermission("getenv.foo"));
...@@ -2200,18 +2170,16 @@ public class Basic { ...@@ -2200,18 +2170,16 @@ public class Basic {
= new FilePermission("<<ALL FILES>>", "execute"); = new FilePermission("<<ALL FILES>>", "execute");
THROWS(SecurityException.class, THROWS(SecurityException.class,
new Fun() { void f() throws IOException { () -> { // environment permission by itself insufficient
// environment permission by itself insufficient policy.setPermissions(new RuntimePermission("getenv.*"));
policy.setPermissions(new RuntimePermission("getenv.*")); ProcessBuilder pb = new ProcessBuilder("env");
ProcessBuilder pb = new ProcessBuilder("env"); pb.environment().put("foo","bar");
pb.environment().put("foo","bar"); pb.start();},
pb.start();}}, () -> { // exec permission by itself insufficient
new Fun() { void f() throws IOException { policy.setPermissions(execPermission);
// exec permission by itself insufficient ProcessBuilder pb = new ProcessBuilder("env");
policy.setPermissions(execPermission); pb.environment().put("foo","bar");
ProcessBuilder pb = new ProcessBuilder("env"); pb.start();});
pb.environment().put("foo","bar");
pb.start();}});
try { try {
// Both permissions? OK. // Both permissions? OK.
...@@ -2576,7 +2544,7 @@ public class Basic { ...@@ -2576,7 +2544,7 @@ public class Basic {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -99,13 +99,6 @@ public class Standard { ...@@ -99,13 +99,6 @@ public class Standard {
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new Exception("Some tests failed"); if (failed > 0) throw new Exception("Some tests failed");
} }
private static abstract class Fun {abstract void f() throws Throwable;}
private static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}}
static byte[] serializedForm(Object obj) { static byte[] serializedForm(Object obj) {
try { try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
......
/* /*
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -236,13 +236,6 @@ public class BiggernYours { ...@@ -236,13 +236,6 @@ public class BiggernYours {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}}
private static abstract class CheckedThread extends Thread { private static abstract class CheckedThread extends Thread {
abstract void realRun() throws Throwable; abstract void realRun() throws Throwable;
public void run() { public void run() {
......
/* /*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -84,9 +84,9 @@ public class IteratorAtEnd { ...@@ -84,9 +84,9 @@ public class IteratorAtEnd {
try { try {
final Iterator it = c.iterator(); final Iterator it = c.iterator();
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun() {void f() { while (true) it.next(); }}); () -> { while (true) it.next(); });
try { it.remove(); } try { it.remove(); }
catch (UnsupportedOperationException _) { return; } catch (UnsupportedOperationException exc) { return; }
pass(); pass();
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
...@@ -96,10 +96,9 @@ public class IteratorAtEnd { ...@@ -96,10 +96,9 @@ public class IteratorAtEnd {
final ListIterator it = list.listIterator(0); final ListIterator it = list.listIterator(0);
it.next(); it.next();
final Object x = it.previous(); final Object x = it.previous();
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.previous());
new Fun() {void f() { it.previous(); }});
try { it.remove(); } try { it.remove(); }
catch (UnsupportedOperationException _) { return; } catch (UnsupportedOperationException exc) { return; }
pass(); pass();
check(! list.get(0).equals(x)); check(! list.get(0).equals(x));
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
...@@ -108,10 +107,9 @@ public class IteratorAtEnd { ...@@ -108,10 +107,9 @@ public class IteratorAtEnd {
final ListIterator it = list.listIterator(list.size()); final ListIterator it = list.listIterator(list.size());
it.previous(); it.previous();
final Object x = it.next(); final Object x = it.next();
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.next());
new Fun() {void f() { it.next(); }});
try { it.remove(); } try { it.remove(); }
catch (UnsupportedOperationException _) { return; } catch (UnsupportedOperationException exc) { return; }
pass(); pass();
check(! list.get(list.size()-1).equals(x)); check(! list.get(list.size()-1).equals(x));
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
...@@ -132,7 +130,7 @@ public class IteratorAtEnd { ...@@ -132,7 +130,7 @@ public class IteratorAtEnd {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -116,10 +116,8 @@ public class MOAT { ...@@ -116,10 +116,8 @@ public class MOAT {
final List<Integer> emptyArray = Arrays.asList(new Integer[]{}); final List<Integer> emptyArray = Arrays.asList(new Integer[]{});
testCollection(emptyArray); testCollection(emptyArray);
testEmptyList(emptyArray); testEmptyList(emptyArray);
THROWS(IndexOutOfBoundsException.class, THROWS(IndexOutOfBoundsException.class, () -> emptyArray.set(0,1));
new Fun(){void f(){ emptyArray.set(0,1); }}); THROWS(UnsupportedOperationException.class, () -> emptyArray.add(0,1));
THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ emptyArray.add(0,1); }});
List<Integer> noOne = nCopies(0,1); List<Integer> noOne = nCopies(0,1);
testCollection(noOne); testCollection(noOne);
...@@ -203,8 +201,7 @@ public class MOAT { ...@@ -203,8 +201,7 @@ public class MOAT {
if (rnd.nextBoolean()) if (rnd.nextBoolean())
check(! it.hasNext()); check(! it.hasNext());
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.next());
new Fun(){void f(){ it.next(); }});
try { it.remove(); } try { it.remove(); }
catch (IllegalStateException ignored) { pass(); } catch (IllegalStateException ignored) { pass(); }
...@@ -231,16 +228,15 @@ public class MOAT { ...@@ -231,16 +228,15 @@ public class MOAT {
private static void testImmutableCollection(final Collection<Integer> c) { private static void testImmutableCollection(final Collection<Integer> c) {
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ c.add(99); }}, () -> c.add(99),
new Fun(){void f(){ c.addAll(singleton(99)); }}); () -> c.addAll(singleton(99)));
if (! c.isEmpty()) { if (! c.isEmpty()) {
final Integer first = c.iterator().next(); final Integer first = c.iterator().next();
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ c.clear(); }}, () -> c.clear(),
new Fun(){void f(){ c.remove(first); }}, () -> c.remove(first),
new Fun(){void f(){ c.removeAll(singleton(first)); }}, () -> c.removeAll(singleton(first)),
new Fun(){void f(){ c.retainAll(emptyList()); }} () -> c.retainAll(emptyList()));
);
} }
} }
...@@ -252,17 +248,17 @@ public class MOAT { ...@@ -252,17 +248,17 @@ public class MOAT {
testList(c); testList(c);
testImmutableCollection(c); testImmutableCollection(c);
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ c.set(0,42); }}, () -> c.set(0,42),
new Fun(){void f(){ c.add(0,42); }}, () -> c.add(0,42),
new Fun(){void f(){ c.addAll(0,singleton(86)); }}); () -> c.addAll(0,singleton(86)));
if (! c.isEmpty()) if (! c.isEmpty())
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ () -> { Iterator<Integer> it = c.iterator();
Iterator<Integer> it = c.iterator(); it.next();
it.next(); it.remove();}}, it.remove(); },
new Fun(){void f(){ () -> { ListIterator<Integer> it = c.listIterator();
ListIterator<Integer> it = c.listIterator(); it.next();
it.next(); it.remove();}}); it.remove(); });
} }
private static void clear(Collection<Integer> c) { private static void clear(Collection<Integer> c) {
...@@ -289,19 +285,19 @@ public class MOAT { ...@@ -289,19 +285,19 @@ public class MOAT {
private static void testImmutableMap(final Map<Integer,Integer> m) { private static void testImmutableMap(final Map<Integer,Integer> m) {
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ m.put(1,1); }}, () -> m.put(1,1),
new Fun(){void f(){ m.putAll(singletonMap(1,1)); }}); () -> m.putAll(singletonMap(1,1)));
if (! m.isEmpty()) { if (! m.isEmpty()) {
final Integer first = m.keySet().iterator().next(); final Integer first = m.keySet().iterator().next();
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ m.remove(first); }}, () -> m.remove(first),
new Fun(){void f(){ m.clear(); }}); () -> m.clear());
final Map.Entry<Integer,Integer> me final Map.Entry<Integer,Integer> me
= m.entrySet().iterator().next(); = m.entrySet().iterator().next();
Integer key = me.getKey(); Integer key = me.getKey();
Integer val = me.getValue(); Integer val = me.getValue();
THROWS(UnsupportedOperationException.class, THROWS(UnsupportedOperationException.class,
new Fun(){void f(){ me.setValue(3); }}); () -> me.setValue(3));
equal(key, me.getKey()); equal(key, me.getKey());
equal(val, me.getValue()); equal(val, me.getValue());
} }
...@@ -491,9 +487,9 @@ public class MOAT { ...@@ -491,9 +487,9 @@ public class MOAT {
// insert, query, remove element at head // insert, query, remove element at head
if (isEmpty) { if (isEmpty) {
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun(){void f(){ deq.getFirst(); }}, () -> deq.getFirst(),
new Fun(){void f(){ deq.element(); }}, () -> deq.element(),
new Fun(){void f(){ deq.iterator().next(); }}); () -> deq.iterator().next());
check(deq.peekFirst() == null); check(deq.peekFirst() == null);
check(deq.peek() == null); check(deq.peek() == null);
} else { } else {
...@@ -545,9 +541,9 @@ public class MOAT { ...@@ -545,9 +541,9 @@ public class MOAT {
} }
if (isEmpty) { if (isEmpty) {
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun(){void f(){ deq.getFirst(); }}, () -> deq.getFirst(),
new Fun(){void f(){ deq.element(); }}, () -> deq.element(),
new Fun(){void f(){ deq.iterator().next(); }}); () -> deq.iterator().next());
check(deq.peekFirst() == null); check(deq.peekFirst() == null);
check(deq.peek() == null); check(deq.peek() == null);
} else { } else {
...@@ -570,8 +566,7 @@ public class MOAT { ...@@ -570,8 +566,7 @@ public class MOAT {
// insert, query, remove element at tail // insert, query, remove element at tail
if (isEmpty) { if (isEmpty) {
check(deq.peekLast() == null); check(deq.peekLast() == null);
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> deq.getLast());
new Fun(){void f(){ deq.getLast(); }});
} else { } else {
check(deq.peekLast() != e); check(deq.peekLast() != e);
check(deq.getLast() != e); check(deq.getLast() != e);
...@@ -614,8 +609,7 @@ public class MOAT { ...@@ -614,8 +609,7 @@ public class MOAT {
} }
if (isEmpty) { if (isEmpty) {
check(deq.peekLast() == null); check(deq.peekLast() == null);
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> deq.getLast());
new Fun(){void f(){ deq.getLast(); }});
} else { } else {
check(deq.peekLast() != e); check(deq.peekLast() != e);
check(deq.getLast() != e); check(deq.getLast() != e);
...@@ -648,17 +642,17 @@ public class MOAT { ...@@ -648,17 +642,17 @@ public class MOAT {
if (isList) { if (isList) {
check(!asList.listIterator().hasPrevious()); check(!asList.listIterator().hasPrevious());
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun(){void f(){ asList.listIterator().previous(); }}); () -> asList.listIterator().previous());
} }
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun(){void f(){ deq.iterator().next(); }}, () -> deq.iterator().next(),
new Fun(){void f(){ deq.element(); }}, () -> deq.element(),
new Fun(){void f(){ deq.getFirst(); }}, () -> deq.getFirst(),
new Fun(){void f(){ deq.getLast(); }}, () -> deq.getLast(),
new Fun(){void f(){ deq.pop(); }}, () -> deq.pop(),
new Fun(){void f(){ deq.remove(); }}, () -> deq.remove(),
new Fun(){void f(){ deq.removeFirst(); }}, () -> deq.removeFirst(),
new Fun(){void f(){ deq.removeLast(); }}); () -> deq.removeLast());
check(deq.poll() == null); check(deq.poll() == null);
check(deq.pollFirst() == null); check(deq.pollFirst() == null);
...@@ -981,22 +975,22 @@ public class MOAT { ...@@ -981,22 +975,22 @@ public class MOAT {
? (ConcurrentMap<T,Integer>) m ? (ConcurrentMap<T,Integer>) m
: null; : null;
List<Fun> fs = new ArrayList<Fun>(); List<Fun> fs = new ArrayList<Fun>();
fs.add(new Fun(){void f(){ check(! m.containsKey(null));}}); fs.add(() -> check(! m.containsKey(null)));
fs.add(new Fun(){void f(){ equal(m.remove(null), null);}}); fs.add(() -> equal(m.remove(null), null));
fs.add(new Fun(){void f(){ equal(m.get(null), null);}}); fs.add(() -> equal(m.get(null), null));
if (cm != null) { if (cm != null)
fs.add(new Fun(){void f(){ check(! cm.remove(null,null));}});} fs.add(() -> check(! cm.remove(null,null)));
throwsConsistently(NullPointerException.class, fs); throwsConsistently(NullPointerException.class, fs);
fs.clear(); fs.clear();
final Map<T,Integer> sm = singletonMap(null,1); final Map<T,Integer> sm = singletonMap(null,1);
fs.add(new Fun(){void f(){ equal(m.put(null,1), null); m.clear();}}); fs.add(() -> { equal(m.put(null,1), null); m.clear();});
fs.add(new Fun(){void f(){ m.putAll(sm); m.clear();}}); fs.add(() -> { m.putAll(sm); m.clear();});
if (cm != null) { if (cm != null) {
fs.add(new Fun(){void f(){ check(! cm.remove(null,null));}}); fs.add(() -> check(! cm.remove(null,null)));
fs.add(new Fun(){void f(){ equal(cm.putIfAbsent(null,1), 1);}}); fs.add(() -> equal(cm.putIfAbsent(null,1), 1));
fs.add(new Fun(){void f(){ equal(cm.replace(null,1), null);}}); fs.add(() -> equal(cm.replace(null,1), null));
fs.add(new Fun(){void f(){ equal(cm.replace(null,1, 1), 1);}}); fs.add(() -> equal(cm.replace(null,1, 1), 1));
} }
throwsConsistently(NullPointerException.class, fs); throwsConsistently(NullPointerException.class, fs);
} }
...@@ -1157,8 +1151,7 @@ public class MOAT { ...@@ -1157,8 +1151,7 @@ public class MOAT {
equalNext(it, 3); equalNext(it, 3);
equalNext(it, 1); equalNext(it, 1);
check(! it.hasNext()); check(! it.hasNext());
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.next());
new Fun(){void f(){it.next();}});
} }
{ {
...@@ -1168,8 +1161,7 @@ public class MOAT { ...@@ -1168,8 +1161,7 @@ public class MOAT {
check(it.hasNext()); equal(it.next().getKey(), 3); check(it.hasNext()); equal(it.next().getKey(), 3);
check(it.hasNext()); equal(it.next().getKey(), 1); check(it.hasNext()); equal(it.next().getKey(), 1);
check(! it.hasNext()); check(! it.hasNext());
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.next());
new Fun(){void f(){it.next();}});
} }
prepMapForDescItrTests(m); prepMapForDescItrTests(m);
...@@ -1239,8 +1231,7 @@ public class MOAT { ...@@ -1239,8 +1231,7 @@ public class MOAT {
equalNext(it, 3); equalNext(it, 3);
equalNext(it, 1); equalNext(it, 1);
check(! it.hasNext()); check(! it.hasNext());
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.next());
new Fun(){void f(){it.next();}});
} }
prepSetForDescItrTests(s); prepSetForDescItrTests(s);
...@@ -1342,7 +1333,7 @@ public class MOAT { ...@@ -1342,7 +1333,7 @@ public class MOAT {
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new Exception("Some tests failed"); if (failed > 0) throw new Exception("Some tests failed");
} }
private static abstract class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
private static void THROWS(Class<? extends Throwable> k, Fun... fs) { private static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -56,8 +56,7 @@ public class AsLifoQueue { ...@@ -56,8 +56,7 @@ public class AsLifoQueue {
equal(q.size(), 3); equal(q.size(), 3);
check(! q.offer("d")); check(! q.offer("d"));
equal(q.size(), 3); equal(q.size(), 3);
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class, () -> q.add("d"));
new Fun(){void f(){ q.add("d"); }});
equal(q.size(), 3); equal(q.size(), 3);
equal(q.toString(), "[c, b, a]"); equal(q.toString(), "[c, b, a]");
equal(q.peek(), "c"); equal(q.peek(), "c");
...@@ -66,8 +65,7 @@ public class AsLifoQueue { ...@@ -66,8 +65,7 @@ public class AsLifoQueue {
equal(q.poll(), "b"); equal(q.poll(), "b");
equal(q.peek(), "a"); equal(q.peek(), "a");
equal(q.remove(), "a"); equal(q.remove(), "a");
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> q.remove());
new Fun(){void f(){ q.remove(); }});
equal(q.poll(), null); equal(q.poll(), null);
check(q.isEmpty()); check(q.isEmpty());
equal(q.size(), 0); equal(q.size(), 0);
...@@ -88,7 +86,7 @@ public class AsLifoQueue { ...@@ -88,7 +86,7 @@ public class AsLifoQueue {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
static abstract class Fun { abstract void f() throws Throwable; } interface Fun {void f() throws Throwable;}
private static void THROWS(Class<? extends Throwable> k, Fun... fs) { private static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -236,8 +236,8 @@ public class LockStep { ...@@ -236,8 +236,8 @@ public class LockStep {
Comparator cmp = comparator(s); Comparator cmp = comparator(s);
if (s.isEmpty()) { if (s.isEmpty()) {
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun(){void f(){ s.first(); }}, () -> s.first(),
new Fun(){void f(){ s.last(); }}); () -> s.last());
equal(null, s.lower(1)); equal(null, s.lower(1));
equal(null, s.floor(1)); equal(null, s.floor(1));
equal(null, s.ceiling(1)); equal(null, s.ceiling(1));
...@@ -265,8 +265,7 @@ public class LockStep { ...@@ -265,8 +265,7 @@ public class LockStep {
}; };
for (final Iterator it : its) for (final Iterator it : its)
if (maybe(4)) if (maybe(4))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class, () -> it.remove());
new Fun(){void f(){ it.remove(); }});
Object prev = null; Object prev = null;
for (Object e : s) { for (Object e : s) {
check(s.contains(e)); check(s.contains(e));
...@@ -284,7 +283,7 @@ public class LockStep { ...@@ -284,7 +283,7 @@ public class LockStep {
for (final Iterator it : its) { for (final Iterator it : its) {
if (maybe(2)) if (maybe(2))
check(! it.hasNext()); check(! it.hasNext());
Fun fun = new Fun(){void f(){ it.next(); }}; Fun fun = () -> it.next();
THROWS(NoSuchElementException.class, fun, fun, fun); THROWS(NoSuchElementException.class, fun, fun, fun);
} }
} }
...@@ -380,8 +379,8 @@ public class LockStep { ...@@ -380,8 +379,8 @@ public class LockStep {
Comparator cmp = comparator(m); Comparator cmp = comparator(m);
if (m.isEmpty()) { if (m.isEmpty()) {
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class,
new Fun(){void f(){ m.firstKey(); }}, () -> m.firstKey(),
new Fun(){void f(){ m.lastKey(); }}); () -> m.lastKey());
equal(null, m.firstEntry()); equal(null, m.firstEntry());
equal(null, m.lastEntry()); equal(null, m.lastEntry());
equal(null, m.pollFirstEntry()); equal(null, m.pollFirstEntry());
...@@ -430,8 +429,7 @@ public class LockStep { ...@@ -430,8 +429,7 @@ public class LockStep {
Iterator[] its = concat(kits, vits, eits); Iterator[] its = concat(kits, vits, eits);
for (final Iterator it : its) for (final Iterator it : its)
if (maybe(4)) if (maybe(4))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class, () -> it.remove());
new Fun(){void f(){ it.remove(); }});
Map.Entry prev = null; Map.Entry prev = null;
for (Map.Entry e : (Set<Map.Entry>) m.entrySet()) { for (Map.Entry e : (Set<Map.Entry>) m.entrySet()) {
Object k = e.getKey(); Object k = e.getKey();
...@@ -459,7 +457,7 @@ public class LockStep { ...@@ -459,7 +457,7 @@ public class LockStep {
for (final Iterator it : its) { for (final Iterator it : its) {
if (maybe(2)) if (maybe(2))
check(! it.hasNext()); check(! it.hasNext());
Fun fun = new Fun(){void f(){ it.next(); }}; Fun fun = () -> it.next();
THROWS(NoSuchElementException.class, fun, fun, fun); THROWS(NoSuchElementException.class, fun, fun, fun);
} }
} }
...@@ -633,7 +631,7 @@ public class LockStep { ...@@ -633,7 +631,7 @@ public class LockStep {
} }
static Fun remover(final Iterator it) { static Fun remover(final Iterator it) {
return new Fun(){void f(){ it.remove(); }}; return () -> it.remove();
} }
static MapFrobber randomRemover(NavigableMap m) { static MapFrobber randomRemover(NavigableMap m) {
...@@ -663,7 +661,7 @@ public class LockStep { ...@@ -663,7 +661,7 @@ public class LockStep {
it.remove(); it.remove();
if (maybe(2)) if (maybe(2))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class,
new Fun(){void f(){ it.remove(); }}); () -> it.remove());
} }
checkUnusedKey(m, k);}}, checkUnusedKey(m, k);}},
new MapFrobber() {void frob(NavigableMap m) { new MapFrobber() {void frob(NavigableMap m) {
...@@ -673,7 +671,7 @@ public class LockStep { ...@@ -673,7 +671,7 @@ public class LockStep {
it.remove(); it.remove();
if (maybe(2)) if (maybe(2))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class,
new Fun(){void f(){ it.remove(); }}); () -> it.remove());
} }
checkUnusedKey(m, k);}}, checkUnusedKey(m, k);}},
new MapFrobber() {void frob(NavigableMap m) { new MapFrobber() {void frob(NavigableMap m) {
...@@ -718,7 +716,7 @@ public class LockStep { ...@@ -718,7 +716,7 @@ public class LockStep {
it.remove(); it.remove();
if (maybe(2)) if (maybe(2))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class,
new Fun(){void f(){ it.remove(); }}); () -> it.remove());
} }
checkUnusedElt(s, e);}}, checkUnusedElt(s, e);}},
new SetFrobber() {void frob(NavigableSet s) { new SetFrobber() {void frob(NavigableSet s) {
...@@ -728,7 +726,7 @@ public class LockStep { ...@@ -728,7 +726,7 @@ public class LockStep {
it.remove(); it.remove();
if (maybe(2)) if (maybe(2))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class,
new Fun(){void f(){ it.remove(); }}); () -> it.remove());
} }
checkUnusedElt(s, e);}}, checkUnusedElt(s, e);}},
new SetFrobber() {void frob(NavigableSet s) { new SetFrobber() {void frob(NavigableSet s) {
...@@ -738,7 +736,7 @@ public class LockStep { ...@@ -738,7 +736,7 @@ public class LockStep {
it.remove(); it.remove();
if (maybe(2)) if (maybe(2))
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class,
new Fun(){void f(){ it.remove(); }}); () -> it.remove());
} }
checkUnusedElt(s, e);}} checkUnusedElt(s, e);}}
}; };
...@@ -769,12 +767,12 @@ public class LockStep { ...@@ -769,12 +767,12 @@ public class LockStep {
for (final NavigableMap m : maps) { for (final NavigableMap m : maps) {
final Object e = usedKey(m); final Object e = usedKey(m);
THROWS(IllegalArgumentException.class, THROWS(IllegalArgumentException.class,
new Fun(){void f(){m.subMap(e,true,e,false) () -> {m.subMap(e,true,e,false)
.subMap(e,true,e,true);}}, .subMap(e,true,e,true);},
new Fun(){void f(){m.subMap(e,false,e,true) () -> {m.subMap(e,false,e,true)
.subMap(e,true,e,true);}}, .subMap(e,true,e,true);},
new Fun(){void f(){m.tailMap(e,false).tailMap(e,true);}}, () -> m.tailMap(e,false).tailMap(e,true),
new Fun(){void f(){m.headMap(e,false).headMap(e,true);}}); () -> m.headMap(e,false).headMap(e,true));
} }
//System.out.printf("%s%n", m1); //System.out.printf("%s%n", m1);
for (int i = size; i > 0; i--) { for (int i = size; i > 0; i--) {
...@@ -811,12 +809,12 @@ public class LockStep { ...@@ -811,12 +809,12 @@ public class LockStep {
for (final NavigableSet s : sets) { for (final NavigableSet s : sets) {
final Object e = usedElt(s); final Object e = usedElt(s);
THROWS(IllegalArgumentException.class, THROWS(IllegalArgumentException.class,
new Fun(){void f(){s.subSet(e,true,e,false) () -> {s.subSet(e,true,e,false)
.subSet(e,true,e,true);}}, .subSet(e,true,e,true);},
new Fun(){void f(){s.subSet(e,false,e,true) () -> {s.subSet(e,false,e,true)
.subSet(e,true,e,true);}}, .subSet(e,true,e,true);},
new Fun(){void f(){s.tailSet(e,false).tailSet(e,true);}}, () -> s.tailSet(e,false).tailSet(e,true),
new Fun(){void f(){s.headSet(e,false).headSet(e,true);}}); () -> s.headSet(e,false).headSet(e,true));
} }
//System.out.printf("%s%n", s1); //System.out.printf("%s%n", s1);
for (int i = size; i > 0; i--) { for (int i = size; i > 0; i--) {
...@@ -847,7 +845,7 @@ public class LockStep { ...@@ -847,7 +845,7 @@ public class LockStep {
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new Exception("Some tests failed"); if (failed > 0) throw new Exception("Some tests failed");
} }
static abstract class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,16 +37,14 @@ public class ForgetMeNot { ...@@ -37,16 +37,14 @@ public class ForgetMeNot {
private static void noMoreElements(final Iterator<Integer> it) { private static void noMoreElements(final Iterator<Integer> it) {
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
THROWS(NoSuchElementException.class, THROWS(NoSuchElementException.class, () -> it.next());
new Fun() { void f() { it.next(); }});
check(! it.hasNext()); check(! it.hasNext());
} }
} }
private static void removeIsCurrentlyIllegal(final Iterator<Integer> it) { private static void removeIsCurrentlyIllegal(final Iterator<Integer> it) {
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
THROWS(IllegalStateException.class, THROWS(IllegalStateException.class, () -> it.remove());
new Fun() { void f() { it.remove(); }});
} }
} }
...@@ -146,7 +144,7 @@ public class ForgetMeNot { ...@@ -146,7 +144,7 @@ public class ForgetMeNot {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -70,19 +70,13 @@ public class Interrupt { ...@@ -70,19 +70,13 @@ public class Interrupt {
(BlockingDeque<Object>) q : null; (BlockingDeque<Object>) q : null;
q.clear(); q.clear();
List<Fun> fs = new ArrayList<Fun>(); List<Fun> fs = new ArrayList<Fun>();
fs.add(new Fun() { void f() throws Throwable fs.add(() -> q.take());
{ q.take(); }}); fs.add(() -> q.poll(60, SECONDS));
fs.add(new Fun() { void f() throws Throwable
{ q.poll(60, SECONDS); }});
if (deq != null) { if (deq != null) {
fs.add(new Fun() { void f() throws Throwable fs.add(() -> deq.takeFirst());
{ deq.takeFirst(); }}); fs.add(() -> deq.takeLast());
fs.add(new Fun() { void f() throws Throwable fs.add(() -> deq.pollFirst(7, SECONDS));
{ deq.takeLast(); }}); fs.add(() -> deq.pollLast(7, SECONDS));
fs.add(new Fun() { void f() throws Throwable
{ deq.pollFirst(7, SECONDS); }});
fs.add(new Fun() { void f() throws Throwable
{ deq.pollLast(7, SECONDS); }});
} }
checkInterrupted(fs); checkInterrupted(fs);
...@@ -93,19 +87,13 @@ public class Interrupt { ...@@ -93,19 +87,13 @@ public class Interrupt {
catch (Throwable t) { unexpected(t); } catch (Throwable t) { unexpected(t); }
fs.clear(); fs.clear();
fs.add(new Fun() { void f() throws Throwable fs.add(() -> q.put(1));
{ q.put(1); }}); fs.add(() -> q.offer(1, 7, SECONDS));
fs.add(new Fun() { void f() throws Throwable
{ q.offer(1, 7, SECONDS); }});
if (deq != null) { if (deq != null) {
fs.add(new Fun() { void f() throws Throwable fs.add(() -> deq.putFirst(1));
{ deq.putFirst(1); }}); fs.add(() -> deq.putLast(1));
fs.add(new Fun() { void f() throws Throwable fs.add(() -> deq.offerFirst(1, 7, SECONDS));
{ deq.putLast(1); }}); fs.add(() -> deq.offerLast(1, 7, SECONDS));
fs.add(new Fun() { void f() throws Throwable
{ deq.offerFirst(1, 7, SECONDS); }});
fs.add(new Fun() { void f() throws Throwable
{ deq.offerLast(1, 7, SECONDS); }});
} }
checkInterrupted(fs); checkInterrupted(fs);
} catch (Throwable t) { } catch (Throwable t) {
...@@ -136,5 +124,5 @@ public class Interrupt { ...@@ -136,5 +124,5 @@ public class Interrupt {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private abstract static class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
} }
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -40,10 +40,8 @@ public class Basic { ...@@ -40,10 +40,8 @@ public class Basic {
equal(barrier.getNumberWaiting(), 0); equal(barrier.getNumberWaiting(), 0);
THROWS(BrokenBarrierException.class, THROWS(BrokenBarrierException.class,
new Fun() { public void f() throws Throwable { () -> barrier.await(),
barrier.await(); }}, () -> barrier.await(100, MILLISECONDS));
new Fun() { public void f() throws Throwable {
barrier.await(100, MILLISECONDS); }});
} }
private static void reset(CyclicBarrier barrier) { private static void reset(CyclicBarrier barrier) {
...@@ -417,7 +415,7 @@ public class Basic { ...@@ -417,7 +415,7 @@ public class Basic {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
abstract static class Fun { abstract void f() throws Throwable; } interface Fun {void f() throws Throwable;}
private static void THROWS(Class<? extends Throwable> k, Fun... fs) { private static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -45,33 +45,31 @@ public class Throws { ...@@ -45,33 +45,31 @@ public class Throws {
ThreadPoolExecutor executor) {}}; ThreadPoolExecutor executor) {}};
final RejectedExecutionHandler nullHandler = null; final RejectedExecutionHandler nullHandler = null;
THROWS( THROWS(NullPointerException.class,
NullPointerException.class, () -> newFixedThreadPool(3, null),
new Fun(){void f(){ newFixedThreadPool(3, null); }}, () -> newCachedThreadPool(null),
new Fun(){void f(){ newCachedThreadPool(null); }}, () -> newSingleThreadScheduledExecutor(null),
new Fun(){void f(){ newSingleThreadScheduledExecutor(null); }}, () -> newScheduledThreadPool(0, null),
new Fun(){void f(){ newScheduledThreadPool(0, null); }}, () -> unconfigurableExecutorService(null),
new Fun(){void f(){ unconfigurableExecutorService(null); }}, () -> unconfigurableScheduledExecutorService(null),
new Fun(){void f(){ unconfigurableScheduledExecutorService(null); }}, () -> callable(null, "foo"),
new Fun(){void f(){ callable(null, "foo"); }}, () -> callable((Runnable) null),
new Fun(){void f(){ callable((Runnable) null); }}, () -> callable((PrivilegedAction<?>) null),
new Fun(){void f(){ callable((PrivilegedAction<?>) null); }}, () -> callable((PrivilegedExceptionAction<?>) null),
new Fun(){void f(){ callable((PrivilegedExceptionAction<?>) null); }}, () -> privilegedCallable((Callable<?>) null),
new Fun(){void f(){ privilegedCallable((Callable<?>) null); }}, () -> new ScheduledThreadPoolExecutor(0, nullFactory),
new Fun(){void f(){ new ScheduledThreadPoolExecutor(0, nullFactory); }}, () -> new ScheduledThreadPoolExecutor(0, nullFactory, reh),
new Fun(){void f(){ new ScheduledThreadPoolExecutor(0, nullFactory, reh); }}, () -> new ScheduledThreadPoolExecutor(0, fac, nullHandler));
new Fun(){void f(){ new ScheduledThreadPoolExecutor(0, fac, nullHandler); }});
THROWS(IllegalArgumentException.class,
THROWS( () -> newFixedThreadPool(-42),
IllegalArgumentException.class, () -> newFixedThreadPool(0),
new Fun(){void f(){ newFixedThreadPool(-42); }}, () -> newFixedThreadPool(-42, fac),
new Fun(){void f(){ newFixedThreadPool(0) ; }}, () -> newFixedThreadPool(0, fac),
new Fun(){void f(){ newFixedThreadPool(-42, fac); }}, () -> newScheduledThreadPool(-42),
new Fun(){void f(){ newFixedThreadPool(0, fac); }}, () -> new ScheduledThreadPoolExecutor(-42),
new Fun(){void f(){ newScheduledThreadPool(-42); }}, () -> new ScheduledThreadPoolExecutor(-42, reh),
new Fun(){void f(){ new ScheduledThreadPoolExecutor(-42); }}, () -> new ScheduledThreadPoolExecutor(-42, fac, reh));
new Fun(){void f(){ new ScheduledThreadPoolExecutor(-42, reh); }},
new Fun(){void f(){ new ScheduledThreadPoolExecutor(-42, fac, reh); }});
try { newFixedThreadPool(1).shutdownNow(); pass(); } try { newFixedThreadPool(1).shutdownNow(); pass(); }
catch (Throwable t) { unexpected(t); } catch (Throwable t) { unexpected(t); }
...@@ -122,7 +120,7 @@ public class Throws { ...@@ -122,7 +120,7 @@ public class Throws {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private abstract static class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -70,8 +70,7 @@ public class Customized { ...@@ -70,8 +70,7 @@ public class Customized {
check(! task.isDone()); check(! task.isDone());
check(! task.isCancelled()); check(! task.isCancelled());
THROWS(TimeoutException.class, THROWS(TimeoutException.class,
new Fun(){void f() throws Throwable { () -> task.get(0L, TimeUnit.SECONDS));
task.get(0L, TimeUnit.SECONDS); }});
} }
static <V> void checkDone(final FutureTask<V> task) { static <V> void checkDone(final FutureTask<V> task) {
...@@ -86,20 +85,16 @@ public class Customized { ...@@ -86,20 +85,16 @@ public class Customized {
check(task.isDone()); check(task.isDone());
check(task.isCancelled()); check(task.isCancelled());
THROWS(CancellationException.class, THROWS(CancellationException.class,
new Fun(){void f() throws Throwable { () -> task.get(0L, TimeUnit.SECONDS),
task.get(0L, TimeUnit.SECONDS); }}, () -> task.get());
new Fun(){void f() throws Throwable {
task.get(); }});
} }
static <V> void checkThrew(final FutureTask<V> task) { static <V> void checkThrew(final FutureTask<V> task) {
check(task.isDone()); check(task.isDone());
check(! task.isCancelled()); check(! task.isCancelled());
THROWS(ExecutionException.class, THROWS(ExecutionException.class,
new Fun(){void f() throws Throwable { () -> task.get(0L, TimeUnit.SECONDS),
task.get(0L, TimeUnit.SECONDS); }}, () -> task.get());
new Fun(){void f() throws Throwable {
task.get(); }});
} }
static <V> void cancel(FutureTask<V> task, boolean mayInterruptIfRunning) { static <V> void cancel(FutureTask<V> task, boolean mayInterruptIfRunning) {
...@@ -203,7 +198,7 @@ public class Customized { ...@@ -203,7 +198,7 @@ public class Customized {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private abstract static class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -72,7 +72,7 @@ public class ConfigChanges { ...@@ -72,7 +72,7 @@ public class ConfigChanges {
check(((ThreadPoolExecutor) es).isTerminating() check(((ThreadPoolExecutor) es).isTerminating()
|| es.isTerminated()); || es.isTerminated());
THROWS(RejectedExecutionException.class, THROWS(RejectedExecutionException.class,
new Fun() {void f() {es.execute(nop);}}); () -> es.execute(nop));
} }
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
} }
...@@ -241,7 +241,7 @@ public class ConfigChanges { ...@@ -241,7 +241,7 @@ public class ConfigChanges {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private abstract static class Fun {abstract void f() throws Throwable;} interface Fun {void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
/* /*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -81,13 +81,6 @@ public class ShutdownNowExecuteRace { ...@@ -81,13 +81,6 @@ public class ShutdownNowExecuteRace {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private abstract static class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}}
private abstract static class CheckedThread extends Thread { private abstract static class CheckedThread extends Thread {
abstract void realRun() throws Throwable; abstract void realRun() throws Throwable;
public void run() { public void run() {
......
/* /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -155,13 +155,6 @@ public class FindOneCharEncoderBugs { ...@@ -155,13 +155,6 @@ public class FindOneCharEncoderBugs {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}}
private static abstract class CheckedThread extends Thread { private static abstract class CheckedThread extends Thread {
abstract void realRun() throws Throwable; abstract void realRun() throws Throwable;
public void run() { public void run() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册