From 56d3f322e21ebd8344b9de8536d0a6811401f3c8 Mon Sep 17 00:00:00 2001 From: snazarki Date: Fri, 15 May 2020 12:22:15 +0300 Subject: [PATCH] 8037866: Replace the Fun class in tests with lambdas Reviewed-by: andrew, aph --- test/java/lang/ProcessBuilder/Basic.java | 200 ++++++++---------- .../charset/StandardCharsets/Standard.java | 9 +- test/java/util/Collection/BiggernYours.java | 9 +- test/java/util/Collection/IteratorAtEnd.java | 18 +- test/java/util/Collection/MOAT.java | 121 +++++------ test/java/util/Collections/AsLifoQueue.java | 10 +- test/java/util/NavigableMap/LockStep.java | 58 +++-- test/java/util/PriorityQueue/ForgetMeNot.java | 10 +- .../concurrent/BlockingQueue/Interrupt.java | 40 ++-- .../util/concurrent/CyclicBarrier/Basic.java | 10 +- .../util/concurrent/Executors/Throws.java | 56 +++-- .../concurrent/FutureTask/Customized.java | 19 +- .../ThreadPoolExecutor/ConfigChanges.java | 6 +- .../ShutdownNowExecuteRace.java | 9 +- test/sun/nio/cs/FindOneCharEncoderBugs.java | 9 +- 15 files changed, 243 insertions(+), 341 deletions(-) diff --git a/test/java/lang/ProcessBuilder/Basic.java b/test/java/lang/ProcessBuilder/Basic.java index 7a9260acb..138199196 100644 --- a/test/java/lang/ProcessBuilder/Basic.java +++ b/test/java/lang/ProcessBuilder/Basic.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -943,18 +943,13 @@ public class Basic { equal(pb.redirectError(), Redirect.to(efile)); THROWS(IllegalArgumentException.class, - new Fun(){void f() { - pb.redirectInput(Redirect.to(ofile)); }}, - new Fun(){void f() { - pb.redirectInput(Redirect.appendTo(ofile)); }}, - new Fun(){void f() { - pb.redirectOutput(Redirect.from(ifile)); }}, - new Fun(){void f() { - pb.redirectError(Redirect.from(ifile)); }}); + () -> pb.redirectInput(Redirect.to(ofile)), + () -> pb.redirectOutput(Redirect.from(ifile)), + () -> pb.redirectError(Redirect.from(ifile))); THROWS(IOException.class, // Input file does not exist - new Fun(){void f() throws Throwable { pb.start(); }}); + () -> pb.start()); setFileContents(ifile, "standard input"); //---------------------------------------------------------------- @@ -1090,18 +1085,15 @@ public class Basic { = new FilePermission("<>", "read,write,execute"); THROWS(SecurityException.class, - new Fun() { void f() throws IOException { - policy.setPermissions(xPermission); - redirectIO(pb, from(tmpFile), PIPE, PIPE); - pb.start();}}, - new Fun() { void f() throws IOException { - policy.setPermissions(rxPermission); - redirectIO(pb, PIPE, to(ofile), PIPE); - pb.start();}}, - new Fun() { void f() throws IOException { - policy.setPermissions(rxPermission); - redirectIO(pb, PIPE, PIPE, to(efile)); - pb.start();}}); + () -> { policy.setPermissions(xPermission); + redirectIO(pb, from(tmpFile), PIPE, PIPE); + pb.start();}, + () -> { policy.setPermissions(rxPermission); + redirectIO(pb, PIPE, to(ofile), PIPE); + pb.start();}, + () -> { policy.setPermissions(rxPermission); + redirectIO(pb, PIPE, PIPE, to(efile)); + pb.start();}); { policy.setPermissions(rxPermission); @@ -1212,10 +1204,10 @@ public class Basic { // System.getenv() is read-only. //---------------------------------------------------------------- THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ getenv().put("FOO","BAR");}}, - new Fun(){void f(){ getenv().remove("PATH");}}, - new Fun(){void f(){ getenv().keySet().remove("PATH");}}, - new Fun(){void f(){ getenv().values().remove("someValue");}}); + () -> getenv().put("FOO","BAR"), + () -> getenv().remove("PATH"), + () -> getenv().keySet().remove("PATH"), + () -> getenv().values().remove("someValue")); try { Collection> c = getenv().entrySet(); @@ -1240,19 +1232,17 @@ public class Basic { { final Map m = new ProcessBuilder().environment(); THROWS(IllegalArgumentException.class, - new Fun(){void f(){ m.put("FOO=","BAR");}}, - new Fun(){void f(){ m.put("FOO\u0000","BAR");}}, - new Fun(){void f(){ m.put("FOO","BAR\u0000");}}); + () -> m.put("FOO=","BAR"), + () -> m.put("FOO\u0000","BAR"), + () -> m.put("FOO","BAR\u0000")); } //---------------------------------------------------------------- // Commands must never be null. //---------------------------------------------------------------- THROWS(NullPointerException.class, - new Fun(){void f(){ - new ProcessBuilder((List)null);}}, - new Fun(){void f(){ - new ProcessBuilder().command((List)null);}}); + () -> new ProcessBuilder((List)null), + () -> new ProcessBuilder().command((List)null)); //---------------------------------------------------------------- // Put in a command; get the same one back out. @@ -1277,25 +1267,18 @@ public class Basic { // Commands must contain at least one element. //---------------------------------------------------------------- THROWS(IndexOutOfBoundsException.class, - new Fun() { void f() throws IOException { - new ProcessBuilder().start();}}, - new Fun() { void f() throws IOException { - new ProcessBuilder(new ArrayList()).start();}}, - new Fun() { void f() throws IOException { - Runtime.getRuntime().exec(new String[]{});}}); + () -> new ProcessBuilder().start(), + () -> new ProcessBuilder(new ArrayList()).start(), + () -> Runtime.getRuntime().exec(new String[]{})); //---------------------------------------------------------------- // Commands must not contain null elements at start() time. //---------------------------------------------------------------- THROWS(NullPointerException.class, - new Fun() { void f() throws IOException { - new ProcessBuilder("foo",null,"bar").start();}}, - new Fun() { void f() throws IOException { - new ProcessBuilder((String)null).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();}}); + () -> new ProcessBuilder("foo",null,"bar").start(), + () -> new ProcessBuilder((String)null).start(), + () -> new ProcessBuilder(new String[]{null}).start(), + () -> new ProcessBuilder(new String[]{"foo",null,"bar"}).start()); //---------------------------------------------------------------- // Command lists are growable. @@ -1312,15 +1295,13 @@ public class Basic { try { final Map env = new ProcessBuilder().environment(); THROWS(NullPointerException.class, - new Fun(){void f(){ env.put("foo",null);}}, - new Fun(){void f(){ env.put(null,"foo");}}, - new Fun(){void f(){ env.remove(null);}}, - new Fun(){void f(){ - for (Map.Entry e : env.entrySet()) - e.setValue(null);}}, - new Fun() { void f() throws IOException { - Runtime.getRuntime().exec(new String[]{"foo"}, - new String[]{null});}}); + () -> env.put("foo",null), + () -> env.put(null,"foo"), + () -> env.remove(null), + () -> { for (Map.Entry e : env.entrySet()) + e.setValue(null);}, + () -> Runtime.getRuntime().exec(new String[]{"foo"}, + new String[]{null})); } catch (Throwable t) { unexpected(t); } //---------------------------------------------------------------- @@ -1329,10 +1310,10 @@ public class Basic { try { final Map env = new ProcessBuilder().environment(); THROWS(ClassCastException.class, - new Fun(){void f(){ env.remove(TRUE);}}, - new Fun(){void f(){ env.keySet().remove(TRUE);}}, - new Fun(){void f(){ env.values().remove(TRUE);}}, - new Fun(){void f(){ env.entrySet().remove(TRUE);}}); + () -> env.remove(TRUE), + () -> env.keySet().remove(TRUE), + () -> env.values().remove(TRUE), + () -> env.entrySet().remove(TRUE)); } catch (Throwable t) { unexpected(t); } //---------------------------------------------------------------- @@ -1348,22 +1329,22 @@ public class Basic { // Nulls in environment queries are forbidden. //---------------------------------------------------------------- THROWS(NullPointerException.class, - new Fun(){void f(){ getenv(null);}}, - new Fun(){void f(){ env.get(null);}}, - new Fun(){void f(){ env.containsKey(null);}}, - new Fun(){void f(){ env.containsValue(null);}}, - new Fun(){void f(){ env.keySet().contains(null);}}, - new Fun(){void f(){ env.values().contains(null);}}); + () -> getenv(null), + () -> env.get(null), + () -> env.containsKey(null), + () -> env.containsValue(null), + () -> env.keySet().contains(null), + () -> env.values().contains(null)); //---------------------------------------------------------------- // Non-String types in environment queries are forbidden. //---------------------------------------------------------------- THROWS(ClassCastException.class, - new Fun(){void f(){ env.get(TRUE);}}, - new Fun(){void f(){ env.containsKey(TRUE);}}, - new Fun(){void f(){ env.containsValue(TRUE);}}, - new Fun(){void f(){ env.keySet().contains(TRUE);}}, - new Fun(){void f(){ env.values().contains(TRUE);}}); + () -> env.get(TRUE), + () -> env.containsKey(TRUE), + () -> env.containsValue(TRUE), + () -> env.keySet().contains(TRUE), + () -> env.values().contains(TRUE)); //---------------------------------------------------------------- // Illegal String values in environment queries are (grumble) OK @@ -1381,12 +1362,11 @@ public class Basic { final Set> entrySet = new ProcessBuilder().environment().entrySet(); THROWS(NullPointerException.class, - new Fun(){void f(){ entrySet.contains(null);}}); + () -> entrySet.contains(null)); THROWS(ClassCastException.class, - new Fun(){void f(){ entrySet.contains(TRUE);}}, - new Fun(){void f(){ - entrySet.contains( - new SimpleImmutableEntry(TRUE,""));}}); + () -> entrySet.contains(TRUE), + () -> entrySet.contains( + new SimpleImmutableEntry(TRUE,""))); check(! entrySet.contains (new SimpleImmutableEntry("", ""))); @@ -1856,8 +1836,7 @@ public class Basic { final ProcessBuilder pb = new ProcessBuilder(new String[]{"unliKely"}); pb.environment().put("PATH", "suBdiR"); - THROWS(IOException.class, - new Fun() {void f() throws Throwable {pb.start();}}); + THROWS(IOException.class, () -> pb.start()); } catch (Throwable t) { unexpected(t); } finally { new File("suBdiR/unliKely").delete(); @@ -1930,10 +1909,8 @@ public class Basic { equal(SIZE, p.getInputStream().available()); equal(SIZE, p.getErrorStream().available()); THROWS(IOException.class, - new Fun(){void f() throws IOException { - p.getOutputStream().write((byte) '!'); - p.getOutputStream().flush(); - }}); + () -> { p.getOutputStream().write((byte) '!'); + p.getOutputStream().flush();}); final byte[] bytes = new byte[SIZE + 1]; equal(SIZE, p.getInputStream().read(bytes)); @@ -1960,12 +1937,9 @@ public class Basic { InputStream[] streams = { p.getInputStream(), p.getErrorStream() }; for (final InputStream in : streams) { Fun[] ops = { - new Fun(){void f() throws IOException { - in.read(); }}, - new Fun(){void f() throws IOException { - in.read(bytes); }}, - new Fun(){void f() throws IOException { - in.available(); }} + () -> in.read(), + () -> in.read(bytes), + () -> in.available() }; for (Fun op : ops) { try { @@ -2169,21 +2143,17 @@ public class Basic { } catch (Throwable t) { unexpected(t); } THROWS(SecurityException.class, - new Fun() { void f() throws IOException { - policy.setPermissions(/* Nothing */); - System.getenv("foo");}}, - new Fun() { void f() throws IOException { - policy.setPermissions(/* Nothing */); - System.getenv();}}, - new Fun() { void f() throws IOException { - policy.setPermissions(/* Nothing */); - new ProcessBuilder("echo").start();}}, - new Fun() { void f() throws IOException { - policy.setPermissions(/* Nothing */); - Runtime.getRuntime().exec("echo");}}, - new Fun() { void f() throws IOException { - policy.setPermissions(new RuntimePermission("getenv.bar")); - System.getenv("foo");}}); + () -> { policy.setPermissions(/* Nothing */); + System.getenv("foo");}, + () -> { policy.setPermissions(/* Nothing */); + System.getenv();}, + () -> { policy.setPermissions(/* Nothing */); + new ProcessBuilder("echo").start();}, + () -> { policy.setPermissions(/* Nothing */); + Runtime.getRuntime().exec("echo");}, + () -> { policy.setPermissions( + new RuntimePermission("getenv.bar")); + System.getenv("foo");}); try { policy.setPermissions(new RuntimePermission("getenv.foo")); @@ -2200,18 +2170,16 @@ public class Basic { = new FilePermission("<>", "execute"); THROWS(SecurityException.class, - new Fun() { void f() throws IOException { - // environment permission by itself insufficient - policy.setPermissions(new RuntimePermission("getenv.*")); - ProcessBuilder pb = new ProcessBuilder("env"); - pb.environment().put("foo","bar"); - pb.start();}}, - new Fun() { void f() throws IOException { - // exec permission by itself insufficient - policy.setPermissions(execPermission); - ProcessBuilder pb = new ProcessBuilder("env"); - pb.environment().put("foo","bar"); - pb.start();}}); + () -> { // environment permission by itself insufficient + policy.setPermissions(new RuntimePermission("getenv.*")); + ProcessBuilder pb = new ProcessBuilder("env"); + pb.environment().put("foo","bar"); + pb.start();}, + () -> { // exec permission by itself insufficient + policy.setPermissions(execPermission); + ProcessBuilder pb = new ProcessBuilder("env"); + pb.environment().put("foo","bar"); + pb.start();}); try { // Both permissions? OK. @@ -2576,7 +2544,7 @@ public class Basic { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/nio/charset/StandardCharsets/Standard.java b/test/java/nio/charset/StandardCharsets/Standard.java index 66d1b112a..c570a9558 100644 --- a/test/java/nio/charset/StandardCharsets/Standard.java +++ b/test/java/nio/charset/StandardCharsets/Standard.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -99,13 +99,6 @@ public class Standard { System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 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) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/test/java/util/Collection/BiggernYours.java b/test/java/util/Collection/BiggernYours.java index 24ce930e7..37bbe072c 100644 --- a/test/java/util/Collection/BiggernYours.java +++ b/test/java/util/Collection/BiggernYours.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -236,13 +236,6 @@ public class BiggernYours { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} - private static abstract class Fun {abstract void f() throws Throwable;} - static void THROWS(Class 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 { abstract void realRun() throws Throwable; public void run() { diff --git a/test/java/util/Collection/IteratorAtEnd.java b/test/java/util/Collection/IteratorAtEnd.java index fffc7f70f..be3a7e116 100644 --- a/test/java/util/Collection/IteratorAtEnd.java +++ b/test/java/util/Collection/IteratorAtEnd.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -84,9 +84,9 @@ public class IteratorAtEnd { try { final Iterator it = c.iterator(); THROWS(NoSuchElementException.class, - new Fun() {void f() { while (true) it.next(); }}); + () -> { while (true) it.next(); }); try { it.remove(); } - catch (UnsupportedOperationException _) { return; } + catch (UnsupportedOperationException exc) { return; } pass(); } catch (Throwable t) { unexpected(t); } @@ -96,10 +96,9 @@ public class IteratorAtEnd { final ListIterator it = list.listIterator(0); it.next(); final Object x = it.previous(); - THROWS(NoSuchElementException.class, - new Fun() {void f() { it.previous(); }}); + THROWS(NoSuchElementException.class, () -> it.previous()); try { it.remove(); } - catch (UnsupportedOperationException _) { return; } + catch (UnsupportedOperationException exc) { return; } pass(); check(! list.get(0).equals(x)); } catch (Throwable t) { unexpected(t); } @@ -108,10 +107,9 @@ public class IteratorAtEnd { final ListIterator it = list.listIterator(list.size()); it.previous(); final Object x = it.next(); - THROWS(NoSuchElementException.class, - new Fun() {void f() { it.next(); }}); + THROWS(NoSuchElementException.class, () -> it.next()); try { it.remove(); } - catch (UnsupportedOperationException _) { return; } + catch (UnsupportedOperationException exc) { return; } pass(); check(! list.get(list.size()-1).equals(x)); } catch (Throwable t) { unexpected(t); } @@ -132,7 +130,7 @@ public class IteratorAtEnd { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/Collection/MOAT.java b/test/java/util/Collection/MOAT.java index 889149527..2cd16e2b4 100644 --- a/test/java/util/Collection/MOAT.java +++ b/test/java/util/Collection/MOAT.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -116,10 +116,8 @@ public class MOAT { final List emptyArray = Arrays.asList(new Integer[]{}); testCollection(emptyArray); testEmptyList(emptyArray); - THROWS(IndexOutOfBoundsException.class, - new Fun(){void f(){ emptyArray.set(0,1); }}); - THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ emptyArray.add(0,1); }}); + THROWS(IndexOutOfBoundsException.class, () -> emptyArray.set(0,1)); + THROWS(UnsupportedOperationException.class, () -> emptyArray.add(0,1)); List noOne = nCopies(0,1); testCollection(noOne); @@ -203,8 +201,7 @@ public class MOAT { if (rnd.nextBoolean()) check(! it.hasNext()); - THROWS(NoSuchElementException.class, - new Fun(){void f(){ it.next(); }}); + THROWS(NoSuchElementException.class, () -> it.next()); try { it.remove(); } catch (IllegalStateException ignored) { pass(); } @@ -231,16 +228,15 @@ public class MOAT { private static void testImmutableCollection(final Collection c) { THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ c.add(99); }}, - new Fun(){void f(){ c.addAll(singleton(99)); }}); + () -> c.add(99), + () -> c.addAll(singleton(99))); if (! c.isEmpty()) { final Integer first = c.iterator().next(); THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ c.clear(); }}, - new Fun(){void f(){ c.remove(first); }}, - new Fun(){void f(){ c.removeAll(singleton(first)); }}, - new Fun(){void f(){ c.retainAll(emptyList()); }} - ); + () -> c.clear(), + () -> c.remove(first), + () -> c.removeAll(singleton(first)), + () -> c.retainAll(emptyList())); } } @@ -252,17 +248,17 @@ public class MOAT { testList(c); testImmutableCollection(c); THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ c.set(0,42); }}, - new Fun(){void f(){ c.add(0,42); }}, - new Fun(){void f(){ c.addAll(0,singleton(86)); }}); + () -> c.set(0,42), + () -> c.add(0,42), + () -> c.addAll(0,singleton(86))); if (! c.isEmpty()) THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ - Iterator it = c.iterator(); - it.next(); it.remove();}}, - new Fun(){void f(){ - ListIterator it = c.listIterator(); - it.next(); it.remove();}}); + () -> { Iterator it = c.iterator(); + it.next(); + it.remove(); }, + () -> { ListIterator it = c.listIterator(); + it.next(); + it.remove(); }); } private static void clear(Collection c) { @@ -289,19 +285,19 @@ public class MOAT { private static void testImmutableMap(final Map m) { THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ m.put(1,1); }}, - new Fun(){void f(){ m.putAll(singletonMap(1,1)); }}); + () -> m.put(1,1), + () -> m.putAll(singletonMap(1,1))); if (! m.isEmpty()) { final Integer first = m.keySet().iterator().next(); THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ m.remove(first); }}, - new Fun(){void f(){ m.clear(); }}); + () -> m.remove(first), + () -> m.clear()); final Map.Entry me = m.entrySet().iterator().next(); Integer key = me.getKey(); Integer val = me.getValue(); THROWS(UnsupportedOperationException.class, - new Fun(){void f(){ me.setValue(3); }}); + () -> me.setValue(3)); equal(key, me.getKey()); equal(val, me.getValue()); } @@ -491,9 +487,9 @@ public class MOAT { // insert, query, remove element at head if (isEmpty) { THROWS(NoSuchElementException.class, - new Fun(){void f(){ deq.getFirst(); }}, - new Fun(){void f(){ deq.element(); }}, - new Fun(){void f(){ deq.iterator().next(); }}); + () -> deq.getFirst(), + () -> deq.element(), + () -> deq.iterator().next()); check(deq.peekFirst() == null); check(deq.peek() == null); } else { @@ -545,9 +541,9 @@ public class MOAT { } if (isEmpty) { THROWS(NoSuchElementException.class, - new Fun(){void f(){ deq.getFirst(); }}, - new Fun(){void f(){ deq.element(); }}, - new Fun(){void f(){ deq.iterator().next(); }}); + () -> deq.getFirst(), + () -> deq.element(), + () -> deq.iterator().next()); check(deq.peekFirst() == null); check(deq.peek() == null); } else { @@ -570,8 +566,7 @@ public class MOAT { // insert, query, remove element at tail if (isEmpty) { check(deq.peekLast() == null); - THROWS(NoSuchElementException.class, - new Fun(){void f(){ deq.getLast(); }}); + THROWS(NoSuchElementException.class, () -> deq.getLast()); } else { check(deq.peekLast() != e); check(deq.getLast() != e); @@ -614,8 +609,7 @@ public class MOAT { } if (isEmpty) { check(deq.peekLast() == null); - THROWS(NoSuchElementException.class, - new Fun(){void f(){ deq.getLast(); }}); + THROWS(NoSuchElementException.class, () -> deq.getLast()); } else { check(deq.peekLast() != e); check(deq.getLast() != e); @@ -648,17 +642,17 @@ public class MOAT { if (isList) { check(!asList.listIterator().hasPrevious()); THROWS(NoSuchElementException.class, - new Fun(){void f(){ asList.listIterator().previous(); }}); + () -> asList.listIterator().previous()); } THROWS(NoSuchElementException.class, - new Fun(){void f(){ deq.iterator().next(); }}, - new Fun(){void f(){ deq.element(); }}, - new Fun(){void f(){ deq.getFirst(); }}, - new Fun(){void f(){ deq.getLast(); }}, - new Fun(){void f(){ deq.pop(); }}, - new Fun(){void f(){ deq.remove(); }}, - new Fun(){void f(){ deq.removeFirst(); }}, - new Fun(){void f(){ deq.removeLast(); }}); + () -> deq.iterator().next(), + () -> deq.element(), + () -> deq.getFirst(), + () -> deq.getLast(), + () -> deq.pop(), + () -> deq.remove(), + () -> deq.removeFirst(), + () -> deq.removeLast()); check(deq.poll() == null); check(deq.pollFirst() == null); @@ -981,22 +975,22 @@ public class MOAT { ? (ConcurrentMap) m : null; List fs = new ArrayList(); - fs.add(new Fun(){void f(){ check(! m.containsKey(null));}}); - fs.add(new Fun(){void f(){ equal(m.remove(null), null);}}); - fs.add(new Fun(){void f(){ equal(m.get(null), null);}}); - if (cm != null) { - fs.add(new Fun(){void f(){ check(! cm.remove(null,null));}});} + fs.add(() -> check(! m.containsKey(null))); + fs.add(() -> equal(m.remove(null), null)); + fs.add(() -> equal(m.get(null), null)); + if (cm != null) + fs.add(() -> check(! cm.remove(null,null))); throwsConsistently(NullPointerException.class, fs); fs.clear(); final Map sm = singletonMap(null,1); - fs.add(new Fun(){void f(){ equal(m.put(null,1), null); m.clear();}}); - fs.add(new Fun(){void f(){ m.putAll(sm); m.clear();}}); + fs.add(() -> { equal(m.put(null,1), null); m.clear();}); + fs.add(() -> { m.putAll(sm); m.clear();}); if (cm != null) { - fs.add(new Fun(){void f(){ check(! cm.remove(null,null));}}); - fs.add(new Fun(){void f(){ equal(cm.putIfAbsent(null,1), 1);}}); - fs.add(new Fun(){void f(){ equal(cm.replace(null,1), null);}}); - fs.add(new Fun(){void f(){ equal(cm.replace(null,1, 1), 1);}}); + fs.add(() -> check(! cm.remove(null,null))); + fs.add(() -> equal(cm.putIfAbsent(null,1), 1)); + fs.add(() -> equal(cm.replace(null,1), null)); + fs.add(() -> equal(cm.replace(null,1, 1), 1)); } throwsConsistently(NullPointerException.class, fs); } @@ -1157,8 +1151,7 @@ public class MOAT { equalNext(it, 3); equalNext(it, 1); check(! it.hasNext()); - THROWS(NoSuchElementException.class, - new Fun(){void f(){it.next();}}); + THROWS(NoSuchElementException.class, () -> it.next()); } { @@ -1168,8 +1161,7 @@ public class MOAT { check(it.hasNext()); equal(it.next().getKey(), 3); check(it.hasNext()); equal(it.next().getKey(), 1); check(! it.hasNext()); - THROWS(NoSuchElementException.class, - new Fun(){void f(){it.next();}}); + THROWS(NoSuchElementException.class, () -> it.next()); } prepMapForDescItrTests(m); @@ -1239,8 +1231,7 @@ public class MOAT { equalNext(it, 3); equalNext(it, 1); check(! it.hasNext()); - THROWS(NoSuchElementException.class, - new Fun(){void f(){it.next();}}); + THROWS(NoSuchElementException.class, () -> it.next()); } prepSetForDescItrTests(s); @@ -1342,7 +1333,7 @@ public class MOAT { System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/Collections/AsLifoQueue.java b/test/java/util/Collections/AsLifoQueue.java index ddb98a745..59c08e85c 100644 --- a/test/java/util/Collections/AsLifoQueue.java +++ b/test/java/util/Collections/AsLifoQueue.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -56,8 +56,7 @@ public class AsLifoQueue { equal(q.size(), 3); check(! q.offer("d")); equal(q.size(), 3); - THROWS(IllegalStateException.class, - new Fun(){void f(){ q.add("d"); }}); + THROWS(IllegalStateException.class, () -> q.add("d")); equal(q.size(), 3); equal(q.toString(), "[c, b, a]"); equal(q.peek(), "c"); @@ -66,8 +65,7 @@ public class AsLifoQueue { equal(q.poll(), "b"); equal(q.peek(), "a"); equal(q.remove(), "a"); - THROWS(NoSuchElementException.class, - new Fun(){void f(){ q.remove(); }}); + THROWS(NoSuchElementException.class, () -> q.remove()); equal(q.poll(), null); check(q.isEmpty()); equal(q.size(), 0); @@ -88,7 +86,7 @@ public class AsLifoQueue { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/NavigableMap/LockStep.java b/test/java/util/NavigableMap/LockStep.java index adb8b1978..62ffc7287 100644 --- a/test/java/util/NavigableMap/LockStep.java +++ b/test/java/util/NavigableMap/LockStep.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -236,8 +236,8 @@ public class LockStep { Comparator cmp = comparator(s); if (s.isEmpty()) { THROWS(NoSuchElementException.class, - new Fun(){void f(){ s.first(); }}, - new Fun(){void f(){ s.last(); }}); + () -> s.first(), + () -> s.last()); equal(null, s.lower(1)); equal(null, s.floor(1)); equal(null, s.ceiling(1)); @@ -265,8 +265,7 @@ public class LockStep { }; for (final Iterator it : its) if (maybe(4)) - THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + THROWS(IllegalStateException.class, () -> it.remove()); Object prev = null; for (Object e : s) { check(s.contains(e)); @@ -284,7 +283,7 @@ public class LockStep { for (final Iterator it : its) { if (maybe(2)) check(! it.hasNext()); - Fun fun = new Fun(){void f(){ it.next(); }}; + Fun fun = () -> it.next(); THROWS(NoSuchElementException.class, fun, fun, fun); } } @@ -380,8 +379,8 @@ public class LockStep { Comparator cmp = comparator(m); if (m.isEmpty()) { THROWS(NoSuchElementException.class, - new Fun(){void f(){ m.firstKey(); }}, - new Fun(){void f(){ m.lastKey(); }}); + () -> m.firstKey(), + () -> m.lastKey()); equal(null, m.firstEntry()); equal(null, m.lastEntry()); equal(null, m.pollFirstEntry()); @@ -430,8 +429,7 @@ public class LockStep { Iterator[] its = concat(kits, vits, eits); for (final Iterator it : its) if (maybe(4)) - THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + THROWS(IllegalStateException.class, () -> it.remove()); Map.Entry prev = null; for (Map.Entry e : (Set) m.entrySet()) { Object k = e.getKey(); @@ -459,7 +457,7 @@ public class LockStep { for (final Iterator it : its) { if (maybe(2)) check(! it.hasNext()); - Fun fun = new Fun(){void f(){ it.next(); }}; + Fun fun = () -> it.next(); THROWS(NoSuchElementException.class, fun, fun, fun); } } @@ -633,7 +631,7 @@ public class LockStep { } static Fun remover(final Iterator it) { - return new Fun(){void f(){ it.remove(); }}; + return () -> it.remove(); } static MapFrobber randomRemover(NavigableMap m) { @@ -663,7 +661,7 @@ public class LockStep { it.remove(); if (maybe(2)) THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + () -> it.remove()); } checkUnusedKey(m, k);}}, new MapFrobber() {void frob(NavigableMap m) { @@ -673,7 +671,7 @@ public class LockStep { it.remove(); if (maybe(2)) THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + () -> it.remove()); } checkUnusedKey(m, k);}}, new MapFrobber() {void frob(NavigableMap m) { @@ -718,7 +716,7 @@ public class LockStep { it.remove(); if (maybe(2)) THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + () -> it.remove()); } checkUnusedElt(s, e);}}, new SetFrobber() {void frob(NavigableSet s) { @@ -728,7 +726,7 @@ public class LockStep { it.remove(); if (maybe(2)) THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + () -> it.remove()); } checkUnusedElt(s, e);}}, new SetFrobber() {void frob(NavigableSet s) { @@ -738,7 +736,7 @@ public class LockStep { it.remove(); if (maybe(2)) THROWS(IllegalStateException.class, - new Fun(){void f(){ it.remove(); }}); + () -> it.remove()); } checkUnusedElt(s, e);}} }; @@ -769,12 +767,12 @@ public class LockStep { for (final NavigableMap m : maps) { final Object e = usedKey(m); THROWS(IllegalArgumentException.class, - new Fun(){void f(){m.subMap(e,true,e,false) - .subMap(e,true,e,true);}}, - new Fun(){void f(){m.subMap(e,false,e,true) - .subMap(e,true,e,true);}}, - new Fun(){void f(){m.tailMap(e,false).tailMap(e,true);}}, - new Fun(){void f(){m.headMap(e,false).headMap(e,true);}}); + () -> {m.subMap(e,true,e,false) + .subMap(e,true,e,true);}, + () -> {m.subMap(e,false,e,true) + .subMap(e,true,e,true);}, + () -> m.tailMap(e,false).tailMap(e,true), + () -> m.headMap(e,false).headMap(e,true)); } //System.out.printf("%s%n", m1); for (int i = size; i > 0; i--) { @@ -811,12 +809,12 @@ public class LockStep { for (final NavigableSet s : sets) { final Object e = usedElt(s); THROWS(IllegalArgumentException.class, - new Fun(){void f(){s.subSet(e,true,e,false) - .subSet(e,true,e,true);}}, - new Fun(){void f(){s.subSet(e,false,e,true) - .subSet(e,true,e,true);}}, - new Fun(){void f(){s.tailSet(e,false).tailSet(e,true);}}, - new Fun(){void f(){s.headSet(e,false).headSet(e,true);}}); + () -> {s.subSet(e,true,e,false) + .subSet(e,true,e,true);}, + () -> {s.subSet(e,false,e,true) + .subSet(e,true,e,true);}, + () -> s.tailSet(e,false).tailSet(e,true), + () -> s.headSet(e,false).headSet(e,true)); } //System.out.printf("%s%n", s1); for (int i = size; i > 0; i--) { @@ -847,7 +845,7 @@ public class LockStep { System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/PriorityQueue/ForgetMeNot.java b/test/java/util/PriorityQueue/ForgetMeNot.java index f6970fa73..7778d1d79 100644 --- a/test/java/util/PriorityQueue/ForgetMeNot.java +++ b/test/java/util/PriorityQueue/ForgetMeNot.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -37,16 +37,14 @@ public class ForgetMeNot { private static void noMoreElements(final Iterator it) { for (int j = 0; j < 2; j++) { - THROWS(NoSuchElementException.class, - new Fun() { void f() { it.next(); }}); + THROWS(NoSuchElementException.class, () -> it.next()); check(! it.hasNext()); } } private static void removeIsCurrentlyIllegal(final Iterator it) { for (int j = 0; j < 2; j++) { - THROWS(IllegalStateException.class, - new Fun() { void f() { it.remove(); }}); + THROWS(IllegalStateException.class, () -> it.remove()); } } @@ -146,7 +144,7 @@ public class ForgetMeNot { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/concurrent/BlockingQueue/Interrupt.java b/test/java/util/concurrent/BlockingQueue/Interrupt.java index d8d55d990..10b85ca79 100644 --- a/test/java/util/concurrent/BlockingQueue/Interrupt.java +++ b/test/java/util/concurrent/BlockingQueue/Interrupt.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -70,19 +70,13 @@ public class Interrupt { (BlockingDeque) q : null; q.clear(); List fs = new ArrayList(); - fs.add(new Fun() { void f() throws Throwable - { q.take(); }}); - fs.add(new Fun() { void f() throws Throwable - { q.poll(60, SECONDS); }}); + fs.add(() -> q.take()); + fs.add(() -> q.poll(60, SECONDS)); if (deq != null) { - fs.add(new Fun() { void f() throws Throwable - { deq.takeFirst(); }}); - fs.add(new Fun() { void f() throws Throwable - { deq.takeLast(); }}); - fs.add(new Fun() { void f() throws Throwable - { deq.pollFirst(7, SECONDS); }}); - fs.add(new Fun() { void f() throws Throwable - { deq.pollLast(7, SECONDS); }}); + fs.add(() -> deq.takeFirst()); + fs.add(() -> deq.takeLast()); + fs.add(() -> deq.pollFirst(7, SECONDS)); + fs.add(() -> deq.pollLast(7, SECONDS)); } checkInterrupted(fs); @@ -93,19 +87,13 @@ public class Interrupt { catch (Throwable t) { unexpected(t); } fs.clear(); - fs.add(new Fun() { void f() throws Throwable - { q.put(1); }}); - fs.add(new Fun() { void f() throws Throwable - { q.offer(1, 7, SECONDS); }}); + fs.add(() -> q.put(1)); + fs.add(() -> q.offer(1, 7, SECONDS)); if (deq != null) { - fs.add(new Fun() { void f() throws Throwable - { deq.putFirst(1); }}); - fs.add(new Fun() { void f() throws Throwable - { deq.putLast(1); }}); - 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); }}); + fs.add(() -> deq.putFirst(1)); + fs.add(() -> deq.putLast(1)); + fs.add(() -> deq.offerFirst(1, 7, SECONDS)); + fs.add(() -> deq.offerLast(1, 7, SECONDS)); } checkInterrupted(fs); } catch (Throwable t) { @@ -136,5 +124,5 @@ public class Interrupt { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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;} } diff --git a/test/java/util/concurrent/CyclicBarrier/Basic.java b/test/java/util/concurrent/CyclicBarrier/Basic.java index 123481985..b6b8d637b 100644 --- a/test/java/util/concurrent/CyclicBarrier/Basic.java +++ b/test/java/util/concurrent/CyclicBarrier/Basic.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -40,10 +40,8 @@ public class Basic { equal(barrier.getNumberWaiting(), 0); THROWS(BrokenBarrierException.class, - new Fun() { public void f() throws Throwable { - barrier.await(); }}, - new Fun() { public void f() throws Throwable { - barrier.await(100, MILLISECONDS); }}); + () -> barrier.await(), + () -> barrier.await(100, MILLISECONDS)); } private static void reset(CyclicBarrier barrier) { @@ -417,7 +415,7 @@ public class Basic { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/concurrent/Executors/Throws.java b/test/java/util/concurrent/Executors/Throws.java index 424b60d6d..402472df3 100644 --- a/test/java/util/concurrent/Executors/Throws.java +++ b/test/java/util/concurrent/Executors/Throws.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -45,33 +45,31 @@ public class Throws { ThreadPoolExecutor executor) {}}; final RejectedExecutionHandler nullHandler = null; - THROWS( - NullPointerException.class, - new Fun(){void f(){ newFixedThreadPool(3, null); }}, - new Fun(){void f(){ newCachedThreadPool(null); }}, - new Fun(){void f(){ newSingleThreadScheduledExecutor(null); }}, - new Fun(){void f(){ newScheduledThreadPool(0, null); }}, - new Fun(){void f(){ unconfigurableExecutorService(null); }}, - new Fun(){void f(){ unconfigurableScheduledExecutorService(null); }}, - new Fun(){void f(){ callable(null, "foo"); }}, - new Fun(){void f(){ callable((Runnable) null); }}, - new Fun(){void f(){ callable((PrivilegedAction) null); }}, - new Fun(){void f(){ callable((PrivilegedExceptionAction) null); }}, - new Fun(){void f(){ privilegedCallable((Callable) null); }}, - new Fun(){void f(){ new ScheduledThreadPoolExecutor(0, nullFactory); }}, - new Fun(){void f(){ new ScheduledThreadPoolExecutor(0, nullFactory, reh); }}, - new Fun(){void f(){ new ScheduledThreadPoolExecutor(0, fac, nullHandler); }}); - - THROWS( - IllegalArgumentException.class, - new Fun(){void f(){ newFixedThreadPool(-42); }}, - new Fun(){void f(){ newFixedThreadPool(0) ; }}, - new Fun(){void f(){ newFixedThreadPool(-42, fac); }}, - new Fun(){void f(){ newFixedThreadPool(0, fac); }}, - new Fun(){void f(){ newScheduledThreadPool(-42); }}, - new Fun(){void f(){ new ScheduledThreadPoolExecutor(-42); }}, - new Fun(){void f(){ new ScheduledThreadPoolExecutor(-42, reh); }}, - new Fun(){void f(){ new ScheduledThreadPoolExecutor(-42, fac, reh); }}); + THROWS(NullPointerException.class, + () -> newFixedThreadPool(3, null), + () -> newCachedThreadPool(null), + () -> newSingleThreadScheduledExecutor(null), + () -> newScheduledThreadPool(0, null), + () -> unconfigurableExecutorService(null), + () -> unconfigurableScheduledExecutorService(null), + () -> callable(null, "foo"), + () -> callable((Runnable) null), + () -> callable((PrivilegedAction) null), + () -> callable((PrivilegedExceptionAction) null), + () -> privilegedCallable((Callable) null), + () -> new ScheduledThreadPoolExecutor(0, nullFactory), + () -> new ScheduledThreadPoolExecutor(0, nullFactory, reh), + () -> new ScheduledThreadPoolExecutor(0, fac, nullHandler)); + + THROWS(IllegalArgumentException.class, + () -> newFixedThreadPool(-42), + () -> newFixedThreadPool(0), + () -> newFixedThreadPool(-42, fac), + () -> newFixedThreadPool(0, fac), + () -> newScheduledThreadPool(-42), + () -> new ScheduledThreadPoolExecutor(-42), + () -> new ScheduledThreadPoolExecutor(-42, reh), + () -> new ScheduledThreadPoolExecutor(-42, fac, reh)); try { newFixedThreadPool(1).shutdownNow(); pass(); } catch (Throwable t) { unexpected(t); } @@ -122,7 +120,7 @@ public class Throws { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/concurrent/FutureTask/Customized.java b/test/java/util/concurrent/FutureTask/Customized.java index 15159ca0a..a1afd9015 100644 --- a/test/java/util/concurrent/FutureTask/Customized.java +++ b/test/java/util/concurrent/FutureTask/Customized.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -70,8 +70,7 @@ public class Customized { check(! task.isDone()); check(! task.isCancelled()); THROWS(TimeoutException.class, - new Fun(){void f() throws Throwable { - task.get(0L, TimeUnit.SECONDS); }}); + () -> task.get(0L, TimeUnit.SECONDS)); } static void checkDone(final FutureTask task) { @@ -86,20 +85,16 @@ public class Customized { check(task.isDone()); check(task.isCancelled()); THROWS(CancellationException.class, - new Fun(){void f() throws Throwable { - task.get(0L, TimeUnit.SECONDS); }}, - new Fun(){void f() throws Throwable { - task.get(); }}); + () -> task.get(0L, TimeUnit.SECONDS), + () -> task.get()); } static void checkThrew(final FutureTask task) { check(task.isDone()); check(! task.isCancelled()); THROWS(ExecutionException.class, - new Fun(){void f() throws Throwable { - task.get(0L, TimeUnit.SECONDS); }}, - new Fun(){void f() throws Throwable { - task.get(); }}); + () -> task.get(0L, TimeUnit.SECONDS), + () -> task.get()); } static void cancel(FutureTask task, boolean mayInterruptIfRunning) { @@ -203,7 +198,7 @@ public class Customized { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java b/test/java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java index aed43ac68..d89ee2833 100644 --- a/test/java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java +++ b/test/java/util/concurrent/ThreadPoolExecutor/ConfigChanges.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -72,7 +72,7 @@ public class ConfigChanges { check(((ThreadPoolExecutor) es).isTerminating() || es.isTerminated()); THROWS(RejectedExecutionException.class, - new Fun() {void f() {es.execute(nop);}}); + () -> es.execute(nop)); } } catch (Throwable t) { unexpected(t); } } @@ -241,7 +241,7 @@ public class ConfigChanges { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, 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 k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } diff --git a/test/java/util/concurrent/ThreadPoolExecutor/ShutdownNowExecuteRace.java b/test/java/util/concurrent/ThreadPoolExecutor/ShutdownNowExecuteRace.java index dbf82f22e..780aa4eeb 100644 --- a/test/java/util/concurrent/ThreadPoolExecutor/ShutdownNowExecuteRace.java +++ b/test/java/util/concurrent/ThreadPoolExecutor/ShutdownNowExecuteRace.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -81,13 +81,6 @@ public class ShutdownNowExecuteRace { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} - private abstract static class Fun {abstract void f() throws Throwable;} - static void THROWS(Class 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 { abstract void realRun() throws Throwable; public void run() { diff --git a/test/sun/nio/cs/FindOneCharEncoderBugs.java b/test/sun/nio/cs/FindOneCharEncoderBugs.java index 0b244e8c0..95ce0fca6 100644 --- a/test/sun/nio/cs/FindOneCharEncoderBugs.java +++ b/test/sun/nio/cs/FindOneCharEncoderBugs.java @@ -1,5 +1,5 @@ /* - * 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. * * This code is free software; you can redistribute it and/or modify it @@ -155,13 +155,6 @@ public class FindOneCharEncoderBugs { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} - private static abstract class Fun {abstract void f() throws Throwable;} - static void THROWS(Class 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 { abstract void realRun() throws Throwable; public void run() { -- GitLab