You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/02/19 18:13:23 UTC

[3/8] lucene-solr git commit: LUCENE-7037: Switch all exceptions tests to expectThrows()

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestSingleInstanceLockFactory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestSingleInstanceLockFactory.java b/lucene/core/src/test/org/apache/lucene/store/TestSingleInstanceLockFactory.java
index be0bef2..14863ff 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestSingleInstanceLockFactory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestSingleInstanceLockFactory.java
@@ -44,16 +44,10 @@ public class TestSingleInstanceLockFactory extends BaseLockFactoryTestCase {
     IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())));
     
     // Create a 2nd IndexWriter.  This should fail:
-    IndexWriter writer2 = null;
-    try {
-      writer2 = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
-      fail("Should have hit an IOException with two IndexWriters on default SingleInstanceLockFactory");
-    } catch (IOException e) {
-    }
+    expectThrows(IOException.class, () -> {
+      new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
+    });
     
     writer.close();
-    if (writer2 != null) {
-      writer2.close();
-    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
index c289120..77471f9 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
@@ -50,12 +50,9 @@ public class TestArrayUtil extends LuceneTestCase {
   }
 
   public void testTooBig() {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       ArrayUtil.oversize(ArrayUtil.MAX_ARRAY_LENGTH+1, 1);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
   }
 
   public void testExactLimit() {
@@ -74,48 +71,32 @@ public class TestArrayUtil extends LuceneTestCase {
   }
 
   public void testParseInt() throws Exception {
-    int test;
-    try {
-      test = ArrayUtil.parseInt("".toCharArray());
-      assertTrue(false);
-    } catch (NumberFormatException e) {
-      //expected
-    }
-    try {
-      test = ArrayUtil.parseInt("foo".toCharArray());
-      assertTrue(false);
-    } catch (NumberFormatException e) {
-      //expected
-    }
-    try {
-      test = ArrayUtil.parseInt(String.valueOf(Long.MAX_VALUE).toCharArray());
-      assertTrue(false);
-    } catch (NumberFormatException e) {
-      //expected
-    }
-    try {
-      test = ArrayUtil.parseInt("0.34".toCharArray());
-      assertTrue(false);
-    } catch (NumberFormatException e) {
-      //expected
-    }
+    expectThrows(NumberFormatException.class, () -> {
+      ArrayUtil.parseInt("".toCharArray());
+    });
 
-    try {
-      test = ArrayUtil.parseInt("1".toCharArray());
-      assertTrue(test + " does not equal: " + 1, test == 1);
-      test = ArrayUtil.parseInt("-10000".toCharArray());
-      assertTrue(test + " does not equal: " + -10000, test == -10000);
-      test = ArrayUtil.parseInt("1923".toCharArray());
-      assertTrue(test + " does not equal: " + 1923, test == 1923);
-      test = ArrayUtil.parseInt("-1".toCharArray());
-      assertTrue(test + " does not equal: " + -1, test == -1);
-      test = ArrayUtil.parseInt("foo 1923 bar".toCharArray(), 4, 4);
-      assertTrue(test + " does not equal: " + 1923, test == 1923);
-    } catch (NumberFormatException e) {
-      e.printStackTrace();
-      assertTrue(false);
-    }
+    expectThrows(NumberFormatException.class, () -> {
+      ArrayUtil.parseInt("foo".toCharArray());
+    });
+
+    expectThrows(NumberFormatException.class, () -> {
+      ArrayUtil.parseInt(String.valueOf(Long.MAX_VALUE).toCharArray());
+    });
+
+    expectThrows(NumberFormatException.class, () -> {
+      ArrayUtil.parseInt("0.34".toCharArray());
+    });
 
+    int test = ArrayUtil.parseInt("1".toCharArray());
+    assertTrue(test + " does not equal: " + 1, test == 1);
+    test = ArrayUtil.parseInt("-10000".toCharArray());
+    assertTrue(test + " does not equal: " + -10000, test == -10000);
+    test = ArrayUtil.parseInt("1923".toCharArray());
+    assertTrue(test + " does not equal: " + 1923, test == 1923);
+    test = ArrayUtil.parseInt("-1".toCharArray());
+    assertTrue(test + " does not equal: " + -1, test == -1);
+    test = ArrayUtil.parseInt("foo 1923 bar".toCharArray(), 4, 4);
+    assertTrue(test + " does not equal: " + 1923, test == 1923);
   }
 
   public void testSliceEquals() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java b/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
index 83becc7..df6c513 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
@@ -71,12 +71,10 @@ public class TestAttributeSource extends LuceneTestCase {
     // init a third instance missing one Attribute
     AttributeSource src3 = new AttributeSource();
     termAtt = src3.addAttribute(CharTermAttribute.class);
-    try {
+    // The third instance is missing the TypeAttribute, so restoreState() should throw IllegalArgumentException
+    expectThrows(IllegalArgumentException.class, () -> {
       src3.restoreState(state);
-      fail("The third instance is missing the TypeAttribute, so restoreState() should throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {
-      // pass
-    }
+    });
   }
   
   public void testCloneAttributes() {
@@ -133,24 +131,22 @@ public class TestAttributeSource extends LuceneTestCase {
   
   @SuppressWarnings({"rawtypes","unchecked"})
   public void testInvalidArguments() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       AttributeSource src = new AttributeSource();
       src.addAttribute(Token.class);
       fail("Should throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {}
+    });
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       AttributeSource src = new AttributeSource(Token.TOKEN_ATTRIBUTE_FACTORY);
       src.addAttribute(Token.class);
-      fail("Should throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {}
+    });
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       AttributeSource src = new AttributeSource();
       // break this by unsafe cast
       src.addAttribute((Class) Iterator.class);
-      fail("Should throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {}
+    });
   }
   
   public void testLUCENE_3042() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestCharsRef.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestCharsRef.java b/lucene/core/src/test/org/apache/lucene/util/TestCharsRef.java
index c9e5a38..0a4c884 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestCharsRef.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestCharsRef.java
@@ -74,19 +74,13 @@ public class TestCharsRef extends LuceneTestCase {
     
     assertEquals('b', c.charAt(1));
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       c.charAt(-1);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       c.charAt(3);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {
-      // expected exception
-    }
+    });
   }
   
   // LUCENE-3590: fix off-by-one in subsequence, and fully obey interface
@@ -115,32 +109,20 @@ public class TestCharsRef extends LuceneTestCase {
     // empty subsequence
     assertEquals("", c.subSequence(0, 0).toString());
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       c.subSequence(-1, 1);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       c.subSequence(0, -1);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       c.subSequence(0, 4);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       c.subSequence(2, 1);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {
-      // expected exception
-    }
+    });
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java b/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java
index d2340cb..847553a 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java
@@ -28,12 +28,9 @@ public class TestFilterIterator extends LuceneTestCase {
 
   private static void assertNoMore(Iterator<?> it) {
     assertFalse(it.hasNext());
-    try {
+    expectThrows(NoSuchElementException.class, () -> {
       it.next();
-      fail("Should throw NoSuchElementException");
-    } catch (NoSuchElementException nsee) {
-      // pass
-    }
+    });
     assertFalse(it.hasNext());
   }
 
@@ -132,12 +129,9 @@ public class TestFilterIterator extends LuceneTestCase {
       }
     };
     assertEquals("a", it.next());
-    try {
+    expectThrows(UnsupportedOperationException.class, () -> {
       it.remove();
-      fail("Should throw UnsupportedOperationException");
-    } catch (UnsupportedOperationException oue) {
-      // pass
-    }
+    });
   }
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
index dc9e3e7..f068b11 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
@@ -110,12 +110,9 @@ public class TestIOUtils extends LuceneTestCase {
     
     // exception: file doesn't exist
     Path fake = dir.resolve("nonexistent");
-    try {
+    expectThrows(IOException.class, () -> {
       IOUtils.spins(fake);
-      fail();
-    } catch (IOException expected) {
-      // ok
-    }
+    });
   }
   
   // fake up a filestore to test some underlying methods

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
index 1d9c41e..621ab96 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
@@ -75,12 +75,10 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
       assertEquals( "forward and back conversion should generate same long", vals[i], LegacyNumericUtils.prefixCodedToLong(prefixVals[i].get()) );
 
       // test if decoding values as int fails correctly
-      try {
-        LegacyNumericUtils.prefixCodedToInt(prefixVals[i].get());
-        fail("decoding a prefix coded long value as int should fail");
-      } catch (NumberFormatException e) {
-        // worked
-      }
+      final int index = i;
+      expectThrows(NumberFormatException.class, () -> {
+        LegacyNumericUtils.prefixCodedToInt(prefixVals[index].get());
+      });
     }
     
     // check sort order (prefixVals should be ascending)
@@ -115,12 +113,10 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
       assertEquals( "forward and back conversion should generate same int", vals[i], LegacyNumericUtils.prefixCodedToInt(prefixVals[i].get()) );
       
       // test if decoding values as long fails correctly
-      try {
-        LegacyNumericUtils.prefixCodedToLong(prefixVals[i].get());
-        fail("decoding a prefix coded int value as long should fail");
-      } catch (NumberFormatException e) {
-        // worked
-      }
+      final int index = i;
+      expectThrows(NumberFormatException.class, () -> {
+        LegacyNumericUtils.prefixCodedToLong(prefixVals[index].get());
+      });
     }
     
     // check sort order (prefixVals should be ascending)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestNamedSPILoader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestNamedSPILoader.java b/lucene/core/src/test/org/apache/lucene/util/TestNamedSPILoader.java
index 3194e7b..a093090 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestNamedSPILoader.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestNamedSPILoader.java
@@ -33,10 +33,9 @@ public class TestNamedSPILoader extends LuceneTestCase {
   
   // we want an exception if it's not found.
   public void testBogusLookup() {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       Codec.forName("dskfdskfsdfksdfdsf");
-      fail();
-    } catch (IllegalArgumentException expected) {}
+    });
   }
   
   public void testAvailableServices() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
index 5a46c14..5322531 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
@@ -184,23 +184,17 @@ public class TestOfflineSorter extends LuceneTestCase {
     BufferSize.megabytes(2047);
     BufferSize.megabytes(1);
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       BufferSize.megabytes(2048);
-      fail("max mb is 2047");
-    } catch (IllegalArgumentException e) {
-    }
+    });
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       BufferSize.megabytes(0);
-      fail("min mb is 0.5");
-    } catch (IllegalArgumentException e) {
-    }
+    });
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       BufferSize.megabytes(-1);
-      fail("min mb is 0.5");
-    } catch (IllegalArgumentException e) {
-    }
+    });
   }
 
   public void testThreadSafety() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java b/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java
index cd202fe..ba28490 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestPriorityQueue.java
@@ -191,43 +191,43 @@ public class TestPriorityQueue extends LuceneTestCase {
     }
   }
 
-  public void testIterator() {
+  public void testIteratorEmpty() {
     IntegerQueue queue = new IntegerQueue(3);
     
     Iterator<Integer> it = queue.iterator();
     assertFalse(it.hasNext());
-    try {
+    expectThrows(NoSuchElementException.class, () -> {
       it.next();
-      fail();
-    } catch (NoSuchElementException e) {
-      // ok
-    }
+    });
+  }
+  
+  public void testIteratorOne() {
+    IntegerQueue queue = new IntegerQueue(3);
 
     queue.add(1);
-    it = queue.iterator();
+    Iterator<Integer> it = queue.iterator();
     assertTrue(it.hasNext());
     assertEquals(Integer.valueOf(1), it.next());
     assertFalse(it.hasNext());
-    try {
+    expectThrows(NoSuchElementException.class, () -> {
       it.next();
-      fail();
-    } catch (NoSuchElementException e) {
-      // ok
-    }
+    });
+  }
+  
+  public void testIteratorTwo() {
+    IntegerQueue queue = new IntegerQueue(3);
 
+    queue.add(1);
     queue.add(2);
-    it = queue.iterator();
+    Iterator<Integer> it = queue.iterator();
     assertTrue(it.hasNext());
     assertEquals(Integer.valueOf(1), it.next());
     assertTrue(it.hasNext());
     assertEquals(Integer.valueOf(2), it.next());
     assertFalse(it.hasNext());
-    try {
+    expectThrows(NoSuchElementException.class, () -> {
       it.next();
-      fail();
-    } catch (NoSuchElementException e) {
-      // ok
-    }
+    });
   }
 
   public void testIteratorRandom() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
index 0ef25ee..d86cdf2 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
@@ -127,13 +127,9 @@ public class TestUnicodeUtil extends LuceneTestCase {
   }
 
   private void assertcodePointCountThrowsAssertionOn(byte... bytes) {
-    boolean threwAssertion = false;
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       UnicodeUtil.codePointCount(new BytesRef(bytes));
-    } catch (IllegalArgumentException e) {
-      threwAssertion = true;
-    }
-    assertTrue(threwAssertion);
+    });
   }
 
   public void testUTF8toUTF32() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVersion.java b/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
index fd02ce2..9feadd2 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
@@ -58,34 +58,25 @@ public class TestVersion extends LuceneTestCase {
   }
   
   public void testParseLenientlyExceptions() {
-    try {
+    ParseException expected = expectThrows(ParseException.class, () -> {
       Version.parseLeniently("LUCENE");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("LUCENE"));
-    }
-    try {
+    });
+    assertTrue(expected.getMessage().contains("LUCENE"));
+
+    expected = expectThrows(ParseException.class, () -> {
       Version.parseLeniently("LUCENE_610");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("LUCENE_610"));
-    }
-    try {
+    });
+    assertTrue(expected.getMessage().contains("LUCENE_610"));
+
+    expected = expectThrows(ParseException.class, () -> {
       Version.parseLeniently("LUCENE61");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("LUCENE61"));
-    }
-    try {
+    });
+    assertTrue(expected.getMessage().contains("LUCENE61"));
+
+    expected = expectThrows(ParseException.class, () -> {
       Version.parseLeniently("LUCENE_6.0.0");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("LUCENE_6.0.0"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("LUCENE_6.0.0"));
   }
 
   public void testParseLenientlyOnAllConstants() throws Exception {
@@ -116,101 +107,65 @@ public class TestVersion extends LuceneTestCase {
   }
 
   public void testParseExceptions() {
-    try {
+    ParseException expected = expectThrows(ParseException.class, () -> {
       Version.parse("LUCENE_6_0_0");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("LUCENE_6_0_0"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("LUCENE_6_0_0"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.256");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.256"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.256"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.-1");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.-1"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.-1"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.1.256");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.1.256"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.1.256"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.1.-1");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.1.-1"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.1.-1"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.1.1.3");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.1.1.3"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.1.1.3"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.1.1.-1");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.1.1.-1"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.1.1.-1"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.1.1.1");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.1.1.1"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.1.1.1"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.1.1.2");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.1.1.2"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.1.1.2"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.0.0.0");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.0.0.0"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.0.0.0"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6.0.0.1.42");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6.0.0.1.42"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6.0.0.1.42"));
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       Version.parse("6..0.1");
-      fail();
-    } catch (ParseException pe) {
-      // pass
-      assertTrue(pe.getMessage().contains("6..0.1"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("6..0.1"));
   }
   
   public void testDeprecations() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java b/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
index 38d217d..4dfe86b 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
@@ -16,7 +16,6 @@
  */
 package org.apache.lucene.util;
 
-
 public class TestVirtualMethod extends LuceneTestCase {
 
   private static final VirtualMethod<TestVirtualMethod> publicTestMethod =
@@ -71,35 +70,26 @@ public class TestVirtualMethod extends LuceneTestCase {
 
   @SuppressWarnings({"rawtypes","unchecked"})
   public void testExceptions() {
-    try {
+    // LuceneTestCase is not a subclass and can never override publicTest(String)
+    expectThrows(IllegalArgumentException.class, () -> {
       // cast to Class to remove generics:
       publicTestMethod.getImplementationDistance((Class) LuceneTestCase.class);
-      fail("LuceneTestCase is not a subclass and can never override publicTest(String)");
-    } catch (IllegalArgumentException arg) {
-      // pass
-    }
+    });
     
-    try {
+    // Method bogus() does not exist, so IAE should be thrown
+    expectThrows(IllegalArgumentException.class, () -> {
       new VirtualMethod<>(TestVirtualMethod.class, "bogus");
-      fail("Method bogus() does not exist, so IAE should be thrown");
-    } catch (IllegalArgumentException arg) {
-      // pass
-    }
+    });
     
-    try {
+    // Method publicTest(String) is not declared in TestClass2, so IAE should be thrown
+    expectThrows(IllegalArgumentException.class, () -> {
       new VirtualMethod<>(TestClass2.class, "publicTest", String.class);
-      fail("Method publicTest(String) is not declared in TestClass2, so IAE should be thrown");
-    } catch (IllegalArgumentException arg) {
-      // pass
-    }
+    });
 
-    try {
-      // try to create a second instance of the same baseClass / method combination
+    // try to create a second instance of the same baseClass / method combination
+    expectThrows(UnsupportedOperationException.class, () -> {
       new VirtualMethod<>(TestVirtualMethod.class, "publicTest", String.class);
-      fail("Violating singleton status succeeded");
-    } catch (UnsupportedOperationException arg) {
-      // pass
-    }
+    });
   }
   
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
index 4e0c7a5..76e42ab 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java
@@ -141,11 +141,9 @@ public class TestWeakIdentityMap extends LuceneTestCase {
     
     Iterator<String> it = map.keyIterator();
     assertFalse(it.hasNext());
-    try {
+    expectThrows(NoSuchElementException.class, () -> {
       it.next();
-      fail("Should throw NoSuchElementException");
-    } catch (NoSuchElementException nse) {
-    }
+    });
     
     key1 = new String("foo");
     key2 = new String("foo");

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/automaton/FiniteStringsIteratorTest.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/FiniteStringsIteratorTest.java b/lucene/core/src/test/org/apache/lucene/util/automaton/FiniteStringsIteratorTest.java
index 57113d0..4edc7ad 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/FiniteStringsIteratorTest.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/FiniteStringsIteratorTest.java
@@ -17,6 +17,7 @@
 package org.apache.lucene.util.automaton;
 
 
+import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.IntsRef;
 import org.apache.lucene.util.IntsRefBuilder;
@@ -133,14 +134,11 @@ public class FiniteStringsIteratorTest extends LuceneTestCase {
 
 
   public void testWithCycle() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       Automaton a = new RegExp("abc.*", RegExp.NONE).toAutomaton();
       FiniteStringsIterator iterator = new FiniteStringsIterator(a);
       getFiniteStrings(iterator);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
   }
 
   public void testSingletonNoLimit() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/automaton/LimitedFiniteStringsIteratorTest.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/LimitedFiniteStringsIteratorTest.java b/lucene/core/src/test/org/apache/lucene/util/automaton/LimitedFiniteStringsIteratorTest.java
index ddaa65a..5303417 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/LimitedFiniteStringsIteratorTest.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/LimitedFiniteStringsIteratorTest.java
@@ -19,6 +19,7 @@ package org.apache.lucene.util.automaton;
 
 import java.util.List;
 
+import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.util.IntsRef;
 import org.apache.lucene.util.IntsRefBuilder;
 import org.apache.lucene.util.LuceneTestCase;
@@ -52,22 +53,17 @@ public class LimitedFiniteStringsIteratorTest extends LuceneTestCase {
 
   public void testInvalidLimitNegative() {
     Automaton a = AutomatonTestUtil.randomAutomaton(random());
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new LimitedFiniteStringsIterator(a, -7);
       fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
   }
 
   public void testInvalidLimitNull() {
     Automaton a = AutomatonTestUtil.randomAutomaton(random());
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new LimitedFiniteStringsIterator(a, 0);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
   }
 
   public void testSingleton() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
index 83c5738..e4a09dc 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java
@@ -325,12 +325,9 @@ public class TestAutomaton extends LuceneTestCase {
     int s2 = a.createState();
     a.addTransition(s1, s2, 'a');
     a.addTransition(s2, s2, 'a');
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       a.addTransition(s1, s2, 'b');
-      fail("didn't hit expected exception");
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
   }
 
   public void testBuilderRandom() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
index afb8e36..b9ac619 100644
--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
@@ -48,34 +48,30 @@ public class TestRegExp extends LuceneTestCase {
   public void testDeterminizeTooManyStates() {
     // LUCENE-6046
     String source = "[ac]*a[ac]{50,200}";
-    try {
+    TooComplexToDeterminizeException expected = expectThrows(TooComplexToDeterminizeException.class, () -> {
       new RegExp(source).toAutomaton();
-      fail();
-    } catch (TooComplexToDeterminizeException e) {
-      assert(e.getMessage().contains(source));
-    }
+    });
+    assertTrue(expected.getMessage().contains(source));
   }
 
   // LUCENE-6713
   public void testSerializeTooManyStatesToDeterminizeExc() throws Exception {
     // LUCENE-6046
     String source = "[ac]*a[ac]{50,200}";
-    try {
+    TooComplexToDeterminizeException expected = expectThrows(TooComplexToDeterminizeException.class, () -> {
       new RegExp(source).toAutomaton();
-      fail();
-    } catch (TooComplexToDeterminizeException e) {
-      assert(e.getMessage().contains(source));
+    });
+    assertTrue(expected.getMessage().contains(source));
 
-      ByteArrayOutputStream bos = new ByteArrayOutputStream();
-      ObjectOutput out = new ObjectOutputStream(bos);   
-      out.writeObject(e);
-      byte[] bytes = bos.toByteArray();
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutput out = new ObjectOutputStream(bos);   
+    out.writeObject(expected);
+    byte[] bytes = bos.toByteArray();
 
-      ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
-      ObjectInput in = new ObjectInputStream(bis);
-      TooComplexToDeterminizeException e2 = (TooComplexToDeterminizeException) in.readObject();
-      assertNotNull(e2.getMessage());
-    }
+    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+    ObjectInput in = new ObjectInputStream(bis);
+    TooComplexToDeterminizeException e2 = (TooComplexToDeterminizeException) in.readObject();
+    assertNotNull(e2.getMessage());
   }
 
   // LUCENE-6046

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java b/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
index 67819bd..8cee5c6 100644
--- a/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
+++ b/lucene/core/src/test/org/apache/lucene/util/bkd/TestBKD.java
@@ -429,11 +429,10 @@ public class TestBKD extends LuceneTestCase {
 
   public void testTooLittleHeap() throws Exception { 
     try (Directory dir = getDirectory(0)) {
-      new BKDWriter(dir, "bkd", 1, 16, 1000000, 0.001);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertTrue(iae.getMessage().contains("either increase maxMBSortInHeap or decrease maxPointsInLeafNode"));
+      IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+        new BKDWriter(dir, "bkd", 1, 16, 1000000, 0.001);
+      });
+      assertTrue(expected.getMessage().contains("either increase maxMBSortInHeap or decrease maxPointsInLeafNode"));
     }
   }
 
@@ -563,11 +562,10 @@ public class TestBKD extends LuceneTestCase {
     Arrays.fill(bytes, (byte) 0xff);
     byte[] one = new byte[4];
     one[3] = 1;
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       NumericUtils.add(4, 0, bytes, one, new byte[4]);
-    } catch (IllegalArgumentException iae) {
-      assertEquals("a + b overflows bytesPerDim=4", iae.getMessage());
-    }
+    });
+    assertEquals("a + b overflows bytesPerDim=4", expected.getMessage());
   }
   
   public void testNumericUtilsSubtract() throws Exception {
@@ -607,11 +605,10 @@ public class TestBKD extends LuceneTestCase {
     v1[3] = (byte) 0xf0;
     byte[] v2 = new byte[4];
     v2[3] = (byte) 0xf1;
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       NumericUtils.subtract(4, 0, v1, v2, new byte[4]);
-    } catch (IllegalArgumentException iae) {
-      assertEquals("a < b", iae.getMessage());
-    }
+    });
+    assertEquals("a < b", expected.getMessage());
   }
 
   /** docIDs can be null, for the single valued case, else it maps value to docID */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java b/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
index 4d72a69..774a2ce 100644
--- a/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
+++ b/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
@@ -66,12 +66,11 @@ public class TestDirectPacked extends LuceneTestCase {
     writer.add(0);
     writer.add(2);
     writer.add(1);
-    try {
+    IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
       writer.finish();
-      fail("didn't get expected exception");
-    } catch (IllegalStateException expected) {
-      assertTrue(expected.getMessage().startsWith("Wrong number of values added"));
-    }
+    });
+    assertTrue(expected.getMessage().startsWith("Wrong number of values added"));
+
     output.close();
     dir.close();
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
index 4062134..ce3447e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
+++ b/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
@@ -1033,12 +1033,9 @@ public class TestPackedInts extends LuceneTestCase {
         }
         assertEquals(arr.length, buf.size());
         final PackedLongValues values = buf.build();
-        try {
+        expectThrows(IllegalStateException.class, () -> {
           buf.add(random().nextLong());
-          fail("expected an exception");
-        } catch (IllegalStateException e) {
-          // ok
-        }
+        });
         assertEquals(arr.length, values.size());
 
         for (int i = 0; i < arr.length; ++i) {
@@ -1160,12 +1157,9 @@ public class TestPackedInts extends LuceneTestCase {
         assertEquals(i, it.ord());
       }
       assertEquals(fp, in instanceof ByteArrayDataInput ? ((ByteArrayDataInput) in).getPosition() : ((IndexInput) in).getFilePointer());
-      try {
+      expectThrows(IOException.class, () -> {
         it.next();
-        assertTrue(false);
-      } catch (IOException e) {
-        // OK
-      }
+      });
 
       if (in instanceof ByteArrayDataInput) {
         ((ByteArrayDataInput) in).setPosition(0);
@@ -1187,12 +1181,9 @@ public class TestPackedInts extends LuceneTestCase {
         }
       }
       assertEquals(fp, in instanceof ByteArrayDataInput ? ((ByteArrayDataInput) in).getPosition() : ((IndexInput) in).getFilePointer());
-      try {
+      expectThrows(IOException.class, () -> {
         it2.skip(1);
-        assertTrue(false);
-      } catch (IOException e) {
-        // OK
-      }
+      });
 
       in1.seek(0L);
       final BlockPackedReader reader = new BlockPackedReader(in1, PackedInts.VERSION_CURRENT, blockSize, valueCount, random().nextBoolean());

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValidation.java
----------------------------------------------------------------------
diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValidation.java b/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValidation.java
index 9aa9a39..56086b9 100644
--- a/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValidation.java
+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValidation.java
@@ -42,47 +42,39 @@ public class TestExpressionValidation extends LuceneTestCase {
     SimpleBindings bindings = new SimpleBindings();
     bindings.add(new SortField("valid", SortField.Type.INT));
     bindings.add("invalid", JavascriptCompiler.compile("badreference"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Invalid reference"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Invalid reference"));
   }
   
   public void testInvalidExternal2() throws Exception {
     SimpleBindings bindings = new SimpleBindings();
     bindings.add(new SortField("valid", SortField.Type.INT));
     bindings.add("invalid", JavascriptCompiler.compile("valid + badreference"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Invalid reference"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Invalid reference"));
   }
   
   public void testSelfRecursion() throws Exception {
     SimpleBindings bindings = new SimpleBindings();
     bindings.add("cycle0", JavascriptCompiler.compile("cycle0"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Cycle detected"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Cycle detected"));
   }
   
   public void testCoRecursion() throws Exception {
     SimpleBindings bindings = new SimpleBindings();
     bindings.add("cycle0", JavascriptCompiler.compile("cycle1"));
     bindings.add("cycle1", JavascriptCompiler.compile("cycle0"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Cycle detected"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Cycle detected"));
   }
   
   public void testCoRecursion2() throws Exception {
@@ -90,12 +82,10 @@ public class TestExpressionValidation extends LuceneTestCase {
     bindings.add("cycle0", JavascriptCompiler.compile("cycle1"));
     bindings.add("cycle1", JavascriptCompiler.compile("cycle2"));
     bindings.add("cycle2", JavascriptCompiler.compile("cycle0"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Cycle detected"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Cycle detected"));
   }
   
   public void testCoRecursion3() throws Exception {
@@ -103,12 +93,10 @@ public class TestExpressionValidation extends LuceneTestCase {
     bindings.add("cycle0", JavascriptCompiler.compile("100"));
     bindings.add("cycle1", JavascriptCompiler.compile("cycle0 + cycle2"));
     bindings.add("cycle2", JavascriptCompiler.compile("cycle0 + cycle1"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Cycle detected"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Cycle detected"));
   }
   
   public void testCoRecursion4() throws Exception {
@@ -117,11 +105,9 @@ public class TestExpressionValidation extends LuceneTestCase {
     bindings.add("cycle1", JavascriptCompiler.compile("100"));
     bindings.add("cycle2", JavascriptCompiler.compile("cycle1 + cycle0 + cycle3"));
     bindings.add("cycle3", JavascriptCompiler.compile("cycle0 + cycle1 + cycle2"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       bindings.validate();
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("Cycle detected"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("Cycle detected"));
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java
----------------------------------------------------------------------
diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java
index ca807e2..7c46b05 100644
--- a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java
+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java
@@ -39,13 +39,11 @@ public class TestCustomFunctions extends LuceneTestCase {
   /** empty list of methods */
   public void testEmpty() throws Exception {
     Map<String,Method> functions = Collections.emptyMap();
-    try {
+    ParseException expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("sqrt(20)", functions, getClass().getClassLoader());
-      fail();
-    } catch (ParseException expected) {
-      assertEquals("Invalid expression 'sqrt(20)': Unrecognized function call (sqrt).", expected.getMessage());
-      assertEquals(expected.getErrorOffset(), 0);
-    }
+    });
+    assertEquals("Invalid expression 'sqrt(20)': Unrecognized function call (sqrt).", expected.getMessage());
+    assertEquals(expected.getErrorOffset(), 0);
   }
   
   /** using the default map explicitly */
@@ -96,38 +94,23 @@ public class TestCustomFunctions extends LuceneTestCase {
 
   /** tests invalid methods that are not allowed to become variables to be mapped */
   public void testInvalidVariableMethods() {
-    try {
+    ParseException expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("method()");
-      fail();
-    } catch (IllegalArgumentException exception) {
-      fail();
-    } catch (ParseException expected) {
-      //expected
-      assertEquals("Invalid expression 'method()': Unrecognized function call (method).", expected.getMessage());
-      assertEquals(0, expected.getErrorOffset());
-    }
+    });
+    assertEquals("Invalid expression 'method()': Unrecognized function call (method).", expected.getMessage());
+    assertEquals(0, expected.getErrorOffset());
 
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("method.method(1)");
-      fail();
-    } catch (IllegalArgumentException exception) {
-      fail();
-    } catch (ParseException expected) {
-      //expected
-      assertEquals("Invalid expression 'method.method(1)': Unrecognized function call (method.method).", expected.getMessage());
-      assertEquals(0, expected.getErrorOffset());
-    }
+    });
+    assertEquals("Invalid expression 'method.method(1)': Unrecognized function call (method.method).", expected.getMessage());
+    assertEquals(0, expected.getErrorOffset());
     
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("1 + method()");
-      fail();
-    } catch (IllegalArgumentException exception) {
-      fail();
-    } catch (ParseException expected) {
-      //expected
-      assertEquals("Invalid expression '1 + method()': Unrecognized function call (method).", expected.getMessage());
-      assertEquals(4, expected.getErrorOffset());
-    }
+    });
+    assertEquals("Invalid expression '1 + method()': Unrecognized function call (method).", expected.getMessage());
+    assertEquals(4, expected.getErrorOffset());
   }
 
   public static String bogusReturnType() { return "bogus!"; }
@@ -136,12 +119,10 @@ public class TestCustomFunctions extends LuceneTestCase {
   public void testWrongReturnType() throws Exception {
     Map<String,Method> functions = new HashMap<>();
     functions.put("foo", getClass().getMethod("bogusReturnType"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("foo()", functions, getClass().getClassLoader());
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("does not return a double"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("does not return a double"));
   }
   
   public static double bogusParameterType(String s) { return 0; }
@@ -150,12 +131,10 @@ public class TestCustomFunctions extends LuceneTestCase {
   public void testWrongParameterType() throws Exception {
     Map<String,Method> functions = new HashMap<>();
     functions.put("foo", getClass().getMethod("bogusParameterType", String.class));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("foo(2)", functions, getClass().getClassLoader());
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("must take only double parameters"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("must take only double parameters"));
   }
   
   public double nonStaticMethod() { return 0; }
@@ -164,12 +143,10 @@ public class TestCustomFunctions extends LuceneTestCase {
   public void testWrongNotStatic() throws Exception {
     Map<String,Method> functions = new HashMap<>();
     functions.put("foo", getClass().getMethod("nonStaticMethod"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("foo()", functions, getClass().getClassLoader());
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("is not static"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("is not static"));
   }
   
   static double nonPublicMethod() { return 0; }
@@ -178,12 +155,10 @@ public class TestCustomFunctions extends LuceneTestCase {
   public void testWrongNotPublic() throws Exception {
     Map<String,Method> functions = new HashMap<>();
     functions.put("foo", getClass().getDeclaredMethod("nonPublicMethod"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("foo()", functions, getClass().getClassLoader());
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("not public"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("not public"));
   }
 
   static class NestedNotPublic {
@@ -194,12 +169,10 @@ public class TestCustomFunctions extends LuceneTestCase {
   public void testWrongNestedNotPublic() throws Exception {
     Map<String,Method> functions = new HashMap<>();
     functions.put("foo", NestedNotPublic.class.getMethod("method"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("foo()", functions, getClass().getClassLoader());
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("not public"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("not public"));
   }
   
   /** Classloader that can be used to create a fake static class that has one method returning a static var */
@@ -250,12 +223,10 @@ public class TestCustomFunctions extends LuceneTestCase {
     assertEquals(2.0, expr.evaluate(0, null), DELTA);
     
     // use our classloader, not the foreign one, which should fail!
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("bar()", functions, thisLoader);
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("is not declared by a class which is accessible by the given parent ClassLoader"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("is not declared by a class which is accessible by the given parent ClassLoader"));
     
     // mix foreign and default functions
     Map<String,Method> mixedFunctions = new HashMap<>(JavascriptCompiler.DEFAULT_FUNCTIONS);
@@ -266,12 +237,10 @@ public class TestCustomFunctions extends LuceneTestCase {
     assertEquals(Math.sqrt(20), expr.evaluate(0, null), DELTA);
     
     // use our classloader, not the foreign one, which should fail!
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       JavascriptCompiler.compile("bar()", mixedFunctions, thisLoader);
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("is not declared by a class which is accessible by the given parent ClassLoader"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("is not declared by a class which is accessible by the given parent ClassLoader"));
   }
   
   static String MESSAGE = "This should not happen but it happens";
@@ -286,17 +255,15 @@ public class TestCustomFunctions extends LuceneTestCase {
     functions.put("foo", StaticThrowingException.class.getMethod("method"));
     String source = "3 * foo() / 5";
     Expression expr = JavascriptCompiler.compile(source, functions, getClass().getClassLoader());
-    try {
+    ArithmeticException expected = expectThrows(ArithmeticException.class, () -> {
       expr.evaluate(0, null);
-      fail();
-    } catch (ArithmeticException e) {
-      assertEquals(MESSAGE, e.getMessage());
-      StringWriter sw = new StringWriter();
-      PrintWriter pw = new PrintWriter(sw);
-      e.printStackTrace(pw);
-      pw.flush();
-      assertTrue(sw.toString().contains("JavascriptCompiler$CompiledExpression.evaluate(" + source + ")"));
-    }
+    });
+    assertEquals(MESSAGE, expected.getMessage());
+    StringWriter sw = new StringWriter();
+    PrintWriter pw = new PrintWriter(sw);
+    expected.printStackTrace(pw);
+    pw.flush();
+    assertTrue(sw.toString().contains("JavascriptCompiler$CompiledExpression.evaluate(" + source + ")"));
   }
 
   /** test that namespaces work with custom expressions. */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java
----------------------------------------------------------------------
diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java
index 8a95321..9941865 100644
--- a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java
+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java
@@ -90,124 +90,84 @@ public class TestJavascriptCompiler extends LuceneTestCase {
   }
 
   void doTestInvalidVariable(String variable) {
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile(variable);
-      fail("\"" + variable + " should have failed to compile");
-    }
-    catch (ParseException expected) {
-      //expected
-    }
+    });
   }
 
   public void testInvalidLexer() throws Exception {
-    try {
+    ParseException expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("\n .");
-      fail();
-    } catch (ParseException pe) {
-      assertTrue(pe.getMessage().contains("unexpected character '.' on line (2) position (1)"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("unexpected character '.' on line (2) position (1)"));
   }
 
   public void testInvalidCompiles() throws Exception {
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("100 100");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("7*/-8");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("0y1234");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("500EE");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("500.5EE");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
   }
   
   public void testEmpty() {
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("()");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
     
-    try {
+    expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("   \r\n   \n \t");
-      fail();
-    } catch (ParseException expected) {
-      // expected exception
-    }
+    });
   }
   
   public void testNull() throws Exception {
-    try {
+    expectThrows(NullPointerException.class, () -> {
       JavascriptCompiler.compile(null);
-      fail();
-    } catch (NullPointerException expected) {
-      // expected exception
-    }
+    });
   }
   
   public void testWrongArity() throws Exception {
-    try {
+    ParseException expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("tan()");
       fail();
-    } catch (ParseException expected) {
-      assertEquals("Invalid expression 'tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage());
-      assertEquals(expected.getErrorOffset(), 0);
-    }
+    });
+    assertEquals("Invalid expression 'tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage());
+    assertEquals(expected.getErrorOffset(), 0);
     
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("tan(1, 1)");
-      fail();
-    } catch (ParseException expected) {
-      assertTrue(expected.getMessage().contains("arguments for function call"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("arguments for function call"));
     
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile(" tan()");
-      fail();
-    } catch (ParseException expected) {
-      assertEquals("Invalid expression ' tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage());
-      assertEquals(expected.getErrorOffset(), 1);
-    }
+    });
+    assertEquals("Invalid expression ' tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage());
+    assertEquals(expected.getErrorOffset(), 1);
     
-    try {
+    expected = expectThrows(ParseException.class, () -> {
       JavascriptCompiler.compile("1 + tan()");
-      fail();
-    } catch (ParseException expected) {
-      assertEquals("Invalid expression '1 + tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage());
-      assertEquals(expected.getErrorOffset(), 4);
-    }
+    });
+    assertEquals("Invalid expression '1 + tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage());
+    assertEquals(expected.getErrorOffset(), 4);
   }
 
   public void testVariableNormalization() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
index 27e1bd6..7d154b3 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
@@ -104,32 +104,19 @@ public class TestRangeFacetCounts extends FacetTestCase {
     d.close();
   }
 
-  @SuppressWarnings("unused")
   public void testUselessRange() {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new LongRange("useless", 7, true, 6, true);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new LongRange("useless", 7, true, 7, false);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new DoubleRange("useless", 7.0, true, 6.0, true);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new DoubleRange("useless", 7.0, true, 7.0, false);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
   }
 
   public void testLongMinMax() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
index 736a8a7..7659be8 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
@@ -124,12 +124,9 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
 
     searcher.search(new MatchAllDocsQuery(), c);
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       new SortedSetDocValuesFacetCounts(state, c);
-      fail("did not hit expected exception");
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
 
     r.close();
     writer.close();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
index 41171b3..436c78b 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
@@ -155,110 +155,61 @@ public class TestFacetLabel extends FacetTestCase {
       new String[] { "test", null, "foo" }, // null in the middle
     };
 
+    // empty or null components should not be allowed.
     for (String[] components : components_tests) {
-      try {
-        assertNotNull(new FacetLabel(components));
-        fail("empty or null components should not be allowed: " + Arrays.toString(components));
-      } catch (IllegalArgumentException e) {
-        // expected
-      }
-      try {
+      expectThrows(IllegalArgumentException.class, () -> {
+        new FacetLabel(components);
+      });
+      expectThrows(IllegalArgumentException.class, () -> {
         new FacetField("dim", components);
-        fail("empty or null components should not be allowed: " + Arrays.toString(components));
-      } catch (IllegalArgumentException e) {
-        // expected
-      }
-      try {
+      });
+      expectThrows(IllegalArgumentException.class, () -> {
         new AssociationFacetField(new BytesRef(), "dim", components);
-        fail("empty or null components should not be allowed: " + Arrays.toString(components));
-      } catch (IllegalArgumentException e) {
-        // expected
-      }
-      try {
+      });
+      expectThrows(IllegalArgumentException.class, () -> {
         new IntAssociationFacetField(17, "dim", components);
-        fail("empty or null components should not be allowed: " + Arrays.toString(components));
-      } catch (IllegalArgumentException e) {
-        // expected
-      }
-      try {
+      });
+      expectThrows(IllegalArgumentException.class, () -> {
         new FloatAssociationFacetField(17.0f, "dim", components);
-        fail("empty or null components should not be allowed: " + Arrays.toString(components));
-      } catch (IllegalArgumentException e) {
-        // expected
-      }
+      });
     }
-    try {
+
+    expectThrows(IllegalArgumentException.class, () -> {
       new FacetField(null, new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new FacetField("", new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new IntAssociationFacetField(17, null, new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new IntAssociationFacetField(17, "", new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new FloatAssociationFacetField(17.0f, null, new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new FloatAssociationFacetField(17.0f, "", new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new AssociationFacetField(new BytesRef(), null, new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new AssociationFacetField(new BytesRef(), "", new String[] {"abc"});
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new SortedSetDocValuesFacetField(null, "abc");
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new SortedSetDocValuesFacetField("", "abc");
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new SortedSetDocValuesFacetField("dim", null);
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalArgumentException.class, () -> {
       new SortedSetDocValuesFacetField("dim", "");
-      fail("empty or null components should not be allowed");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
+    });
   }
 
   @Test
@@ -273,11 +224,10 @@ public class TestFacetLabel extends FacetTestCase {
       break;
     }
 
-    try {
-      assertNotNull(new FacetLabel("dim", bigComp));
-      fail("long paths should not be allowed; len=" + bigComp.length());
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
+    // long paths should not be allowed
+    final String longPath = bigComp;
+    expectThrows(IllegalArgumentException.class, () -> {
+      new FacetLabel("dim", longPath);
+    });
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestSearcherTaxonomyManager.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestSearcherTaxonomyManager.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestSearcherTaxonomyManager.java
index c6a8b5f..a1e0344 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestSearcherTaxonomyManager.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestSearcherTaxonomyManager.java
@@ -274,12 +274,9 @@ public class TestSearcherTaxonomyManager extends FacetTestCase {
     tw.replaceTaxonomy(taxoDir2);
     taxoDir2.close();
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       mgr.maybeRefresh();
-      fail("should have hit exception");
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
 
     w.close();
     IOUtils.close(mgr, tw, taxoDir, dir);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
index 559683f..ecf1401 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
@@ -490,25 +490,15 @@ public class TestTaxonomyCombined extends FacetTestCase {
     }
 
     // check parent of of invalid ordinals:
-    try {
+    expectThrows(ArrayIndexOutOfBoundsException.class, () -> {
       tw.getParent(-1);
-      fail("getParent for -1 should throw exception");
-    } catch (ArrayIndexOutOfBoundsException e) {
-      // ok
-    }
-    try {
+    });
+    expectThrows(ArrayIndexOutOfBoundsException.class, () -> {
       tw.getParent(TaxonomyReader.INVALID_ORDINAL);
-      fail("getParent for INVALID_ORDINAL should throw exception");
-    } catch (ArrayIndexOutOfBoundsException e) {
-      // ok
-    }
-    try {
-      int parent = tw.getParent(tr.getSize());
-      fail("getParent for getSize() should throw exception, but returned "
-          + parent);
-    } catch (ArrayIndexOutOfBoundsException e) {
-      // ok
-    }
+    });
+    expectThrows(ArrayIndexOutOfBoundsException.class, () -> {
+      tw.getParent(tr.getSize());
+    });
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java
index a300e47..b065a8d 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetAssociations.java
@@ -142,19 +142,13 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
     IndexSearcher searcher = newSearcher(reader);
     searcher.search(new MatchAllDocsQuery(), fc);
     Facets facets = new TaxonomyFacetSumFloatAssociations(taxoReader, config, fc);
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getSpecificValue("float");
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getTopChildren(10, "float");
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
   }
 
   public void testMixedTypesInSameIndexField() throws Exception {
@@ -168,12 +162,9 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
     Document doc = new Document();
     doc.add(new IntAssociationFacetField(14, "a", "x"));
     doc.add(new FloatAssociationFacetField(55.0f, "b", "y"));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       writer.addDocument(config.build(taxoWriter, doc));
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException exc) {
-      // expected
-    }
+    });
     writer.close();
     IOUtils.close(taxoWriter, dir, taxoDir);
   }
@@ -189,12 +180,10 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
 
     Document doc = new Document();
     doc.add(new IntAssociationFacetField(14, "a", "x"));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       writer.addDocument(config.build(taxoWriter, doc));
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException exc) {
-      // expected
-    }
+    });
+
     writer.close();
     IOUtils.close(taxoWriter, dir, taxoDir);
   }
@@ -210,12 +199,10 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
 
     Document doc = new Document();
     doc.add(new IntAssociationFacetField(14, "a", "x"));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       writer.addDocument(config.build(taxoWriter, doc));
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException exc) {
-      // expected
-    }
+    });
+
     writer.close();
     IOUtils.close(taxoWriter, dir, taxoDir);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
index 78787e4..20bfdb5 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java
@@ -243,19 +243,13 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
     List<FacetResult> results = facets.getAllDims(10);
     assertTrue(results.isEmpty());
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getSpecificValue("a");
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getTopChildren(10, "a");
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
 
     writer.close();
     IOUtils.close(taxoWriter, searcher.getIndexReader(), taxoReader, taxoDir, dir);
@@ -317,12 +311,9 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
     searcher.search(new MatchAllDocsQuery(), c);
     Facets facets = getTaxonomyFacetCounts(taxoReader, config, c);
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getSpecificValue("a");
-      fail("didn't hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
 
     FacetResult result = facets.getTopChildren(10, "a");
     assertEquals(1, result.labelValues.length);
@@ -404,12 +395,9 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
     assertEquals(1, facets.getTopChildren(10, "dim").value);
     assertEquals(1, facets.getTopChildren(10, "dim2").value);
     assertEquals(1, facets.getTopChildren(10, "dim3").value);
-    try {
-      assertEquals(1, facets.getSpecificValue("dim"));
-      fail("didn't hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    expectThrows(IllegalArgumentException.class, () -> {
+      facets.getSpecificValue("dim");
+    });
     assertEquals(1, facets.getSpecificValue("dim2"));
     assertEquals(1, facets.getSpecificValue("dim3"));
     writer.close();
@@ -479,12 +467,10 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
     Document doc = new Document();
     doc.add(newTextField("field", "text", Field.Store.NO));
     doc.add(new FacetField("a", "path", "other"));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       config.build(taxoWriter, doc);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
+
     writer.close();
     IOUtils.close(taxoWriter, dir, taxoDir);
   }
@@ -502,12 +488,10 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {
     doc.add(newTextField("field", "text", Field.Store.NO));
     doc.add(new FacetField("a", "path"));
     doc.add(new FacetField("a", "path2"));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       config.build(taxoWriter, doc);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
+
     writer.close();
     IOUtils.close(taxoWriter, dir, taxoDir);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
index 09aa5df..0ad90ba 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
@@ -229,19 +229,13 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
     List<FacetResult> results = facets.getAllDims(10);
     assertTrue(results.isEmpty());
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getSpecificValue("a");
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       facets.getTopChildren(10, "a");
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
 
     IOUtils.close(searcher.getIndexReader(), taxoReader, dir, taxoDir);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java
index 9b117c0..1982048 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java
@@ -110,12 +110,10 @@ public class TestDirectoryTaxonomyReader extends FacetTestCase {
     
     DirectoryTaxonomyReader ltr = new DirectoryTaxonomyReader(dir);
     ltr.close();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       ltr.getSize();
-      fail("An AlreadyClosedException should have been thrown here");
-    } catch (AlreadyClosedException ace) {
-      // good!
-    }
+    });
+
     dir.close();
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
index 2e98598..2edee33 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
@@ -134,13 +134,11 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
     DirectoryTaxonomyWriter dtw = new DirectoryTaxonomyWriter(dir);
     dtw.addCategory(new FacetLabel("a"));
     dtw.rollback();
-    try {
+    // should not have succeeded to add a category following rollback.
+    expectThrows(AlreadyClosedException.class, () -> {
       dtw.addCategory(new FacetLabel("a"));
-      fail("should not have succeeded to add a category following rollback.");
-    } catch (AlreadyClosedException e) {
-      // expected
-    }
-    
+    });
+
     dir.close();
   }
   
@@ -162,12 +160,11 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
     Directory dir = newDirectory();
     DirectoryTaxonomyWriter dtw = new DirectoryTaxonomyWriter(dir);
     dtw.close();
-    try {
+    // should not succeed to add a category following close.
+    expectThrows(AlreadyClosedException.class, () -> {
       dtw.addCategory(new FacetLabel("a"));
-      fail("should not have succeeded to add a category following close.");
-    } catch (AlreadyClosedException e) {
-      // expected
-    }
+    });
+
     dir.close();
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java
index 6574b62..4b7e66b 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java
@@ -405,19 +405,15 @@ public class TestPostingsHighlighter extends LuceneTestCase {
     Query query = new TermQuery(new Term("body", "test"));
     TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
     assertEquals(2, topDocs.totalHits);
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       highlighter.highlight("body", query, searcher, topDocs, 2);
-      fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       highlighter.highlight("title", new TermQuery(new Term("title", "test")), searcher, topDocs, 2);
       fail("did not hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
+
     ir.close();
     dir.close();
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
index f21e0dd..98ec2d6 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
@@ -28,13 +28,10 @@ public class SimpleFragListBuilderTest extends AbstractTestCase {
   }
   
   public void testTooSmallFragSize() throws Exception {
-    try{
+    expectThrows(IllegalArgumentException.class, () -> {
       SimpleFragListBuilder sflb = new SimpleFragListBuilder();
-      sflb.createFieldFragList( fpl(new TermQuery(new Term(F, "a")), "b c d" ), sflb.minFragCharSize - 1 );
-      fail( "IllegalArgumentException must be thrown" );
-    }
-    catch ( IllegalArgumentException expected ) {
-    }
+      sflb.createFieldFragList(fpl(new TermQuery(new Term(F, "a")), "b c d"), sflb.minFragCharSize - 1);
+    });
   }
   
   public void testSmallerFragSizeThanTermQuery() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
index e331c8a..a198774 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
@@ -1458,12 +1458,10 @@ public class TestBlockJoin extends LuceneTestCase {
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(new Sort(new SortField("parentID", SortField.Type.STRING)),
                                                                   10, true, true);
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       newSearcher(r).search(parentQuery.build(), c);
-      fail("should have hit exception");
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
+
 
     r.close();
     d.close();