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:24 UTC

[4/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/index/TestParallelLeafReader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestParallelLeafReader.java b/lucene/core/src/test/org/apache/lucene/index/TestParallelLeafReader.java
index ff6fab6..31aa603 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestParallelLeafReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestParallelLeafReader.java
@@ -126,12 +126,10 @@ public class TestParallelLeafReader extends LuceneTestCase {
 
     ir1.close();
     
-    try {
+    // should already be closed because inner reader is closed!
+    expectThrows(AlreadyClosedException.class, () -> {
       pr.document(0);
-      fail("ParallelLeafReader should be already closed because inner reader was closed!");
-    } catch (AlreadyClosedException e) {
-      // pass
-    }
+    });
     
     // noop:
     pr.close();
@@ -154,21 +152,17 @@ public class TestParallelLeafReader extends LuceneTestCase {
     LeafReader ir1 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1));
     LeafReader ir2 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir2));
 
-    try {
+    // indexes don't have the same number of documents
+    expectThrows(IllegalArgumentException.class, () -> {
       new ParallelLeafReader(ir1, ir2);
-      fail("didn't get exptected exception: indexes don't have same number of documents");
-    } catch (IllegalArgumentException e) {
-      // expected exception
-    }
+    });
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new ParallelLeafReader(random().nextBoolean(),
                                new LeafReader[] {ir1, ir2},
                                new LeafReader[] {ir1, ir2});
-      fail("didn't get expected exception: indexes don't have same number of documents");
-    } catch (IllegalArgumentException e) {
-      // expected exception
-    }
+    });
+
     // check RefCounts
     assertEquals(1, ir1.getRefCount());
     assertEquals(1, ir2.getRefCount());
@@ -230,14 +224,11 @@ public class TestParallelLeafReader extends LuceneTestCase {
     pr.close();
     
     // no main readers
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new ParallelLeafReader(true,
         new LeafReader[0],
         new LeafReader[] {ir1});
-      fail("didn't get expected exception: need a non-empty main-reader array");
-    } catch (IllegalArgumentException iae) {
-      // pass
-    }
+    });
     
     dir1.close();
     dir2.close();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java b/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
index 3b0117d..a90a5d2 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
@@ -133,12 +133,11 @@ public class TestPayloadsOnVectors extends LuceneTestCase {
     customType.setStoreTermVectorPayloads(true);
     customType.setStoreTermVectorOffsets(random().nextBoolean());
     doc.add(new Field("field", "foo", customType));
-    try {
+
+    expectThrows(IllegalArgumentException.class, () -> {
       writer.addDocument(doc);
-      fail();
-    } catch (IllegalArgumentException expected) {
-      // expected
-    }
+    });
+
     writer.close();
     dir.close();
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
index 0ace804..f4a6024 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
@@ -103,13 +103,12 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
   @Test
   public void testMissingSnapshots() throws Exception {
     Directory dir = newDirectory();
-    try {
+
+    expectThrows(IllegalStateException.class, () -> {
       new PersistentSnapshotDeletionPolicy(
                                            new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
-      fail("did not hit expected exception");
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
+
     dir.close();
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
index 0eb5e8f..3e1fe2d 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
@@ -60,12 +60,10 @@ public class TestPointValues extends LuceneTestCase {
     Document doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4]));
     doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", iae.getMessage());
-    }
+    });
+    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
     w.close();
     dir.close();
   }
@@ -77,14 +75,14 @@ public class TestPointValues extends LuceneTestCase {
     Document doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4]));
     w.addDocument(doc);
-    doc = new Document();
-    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    try {
-      w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", iae.getMessage());
-    }
+
+    Document doc2 = new Document();
+    doc2.add(new BinaryPoint("dim", new byte[4], new byte[4]));
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w.addDocument(doc2);
+    });
+    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
+
     w.close();
     dir.close();
   }
@@ -97,14 +95,14 @@ public class TestPointValues extends LuceneTestCase {
     doc.add(new BinaryPoint("dim", new byte[4]));
     w.addDocument(doc);
     w.commit();
-    doc = new Document();
-    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    try {
-      w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", iae.getMessage());
-    }
+
+    Document doc2 = new Document();
+    doc2.add(new BinaryPoint("dim", new byte[4], new byte[4]));
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w.addDocument(doc2);
+    });
+    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
+
     w.close();
     dir.close();
   }
@@ -118,16 +116,16 @@ public class TestPointValues extends LuceneTestCase {
     w.addDocument(doc);
     w.close();
     iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir, iwc);
-    doc = new Document();
-    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    try {
-      w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", iae.getMessage());
-    }
-    w.close();
+
+    IndexWriter w2 = new IndexWriter(dir, iwc);
+    Document doc2 = new Document();
+    doc2.add(new BinaryPoint("dim", new byte[4], new byte[4]));
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w2.addDocument(doc2);
+    });
+    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
+
+    w2.close();
     dir.close();
   }
 
@@ -141,17 +139,16 @@ public class TestPointValues extends LuceneTestCase {
     w.close();
 
     Directory dir2 = newDirectory();
-    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir2, iwc);
+    IndexWriter w2 = new IndexWriter(dir2, new IndexWriterConfig(new MockAnalyzer(random())));
     doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    w.addDocument(doc);
-    try {
-      w.addIndexes(new Directory[] {dir});
-    } catch (IllegalArgumentException iae) {
-      assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", iae.getMessage());
-    }
-    IOUtils.close(w, dir, dir2);
+    w2.addDocument(doc);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w2.addIndexes(new Directory[] {dir});
+    });
+    assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", expected.getMessage());
+
+    IOUtils.close(w2, dir, dir2);
   }
 
   public void testIllegalDimChangeViaAddIndexesCodecReader() throws Exception {
@@ -164,18 +161,17 @@ public class TestPointValues extends LuceneTestCase {
     w.close();
 
     Directory dir2 = newDirectory();
-    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir2, iwc);
+    IndexWriter w2 = new IndexWriter(dir2, new IndexWriterConfig(new MockAnalyzer(random())));
     doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    w.addDocument(doc);
+    w2.addDocument(doc);
     DirectoryReader r = DirectoryReader.open(dir);
-    try {
-      w.addIndexes(new CodecReader[] {getOnlySegmentReader(r)});
-    } catch (IllegalArgumentException iae) {
-      assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", iae.getMessage());
-    }
-    IOUtils.close(r, w, dir, dir2);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w2.addIndexes(new CodecReader[] {getOnlySegmentReader(r)});
+    });
+    assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", expected.getMessage());
+
+    IOUtils.close(r, w2, dir, dir2);
   }
 
   public void testIllegalDimChangeViaAddIndexesSlowCodecReader() throws Exception {
@@ -189,17 +185,17 @@ public class TestPointValues extends LuceneTestCase {
 
     Directory dir2 = newDirectory();
     iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir2, iwc);
+    IndexWriter w2 = new IndexWriter(dir2, iwc);
     doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
-    w.addDocument(doc);
+    w2.addDocument(doc);
     DirectoryReader r = DirectoryReader.open(dir);
-    try {
-      TestUtil.addIndexesSlowly(w, r);
-    } catch (IllegalArgumentException iae) {
-      assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", iae.getMessage());
-    }
-    IOUtils.close(r, w, dir, dir2);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      TestUtil.addIndexesSlowly(w2, r);
+    });
+    assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", expected.getMessage());
+
+    IOUtils.close(r, w2, dir, dir2);
   }
 
   public void testIllegalNumBytesChangeOneDoc() throws Exception {
@@ -209,12 +205,11 @@ public class TestPointValues extends LuceneTestCase {
     Document doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4]));
     doc.add(new BinaryPoint("dim", new byte[6]));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", iae.getMessage());
-    }
+    });
+    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
+
     w.close();
     dir.close();
   }
@@ -226,14 +221,14 @@ public class TestPointValues extends LuceneTestCase {
     Document doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[4]));
     w.addDocument(doc);
-    doc = new Document();
-    doc.add(new BinaryPoint("dim", new byte[6]));
-    try {
-      w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", iae.getMessage());
-    }
+
+    Document doc2 = new Document();
+    doc2.add(new BinaryPoint("dim", new byte[6]));
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w.addDocument(doc2);
+    });
+    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
+
     w.close();
     dir.close();
   }
@@ -246,14 +241,14 @@ public class TestPointValues extends LuceneTestCase {
     doc.add(new BinaryPoint("dim", new byte[4]));
     w.addDocument(doc);
     w.commit();
-    doc = new Document();
-    doc.add(new BinaryPoint("dim", new byte[6]));
-    try {
-      w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", iae.getMessage());
-    }
+    
+    Document doc2 = new Document();
+    doc2.add(new BinaryPoint("dim", new byte[6]));
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w.addDocument(doc2);
+    });
+    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
+
     w.close();
     dir.close();
   }
@@ -266,17 +261,18 @@ public class TestPointValues extends LuceneTestCase {
     doc.add(new BinaryPoint("dim", new byte[4]));
     w.addDocument(doc);
     w.close();
+    
     iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir, iwc);
-    doc = new Document();
-    doc.add(new BinaryPoint("dim", new byte[6]));
-    try {
-      w.addDocument(doc);
-    } catch (IllegalArgumentException iae) {
-      // expected
-      assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", iae.getMessage());
-    }
-    w.close();
+    IndexWriter w2 = new IndexWriter(dir, iwc);
+    Document doc2 = new Document();
+    doc2.add(new BinaryPoint("dim", new byte[6]));
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w2.addDocument(doc2);
+    });
+    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
+
+    w2.close();
     dir.close();
   }
 
@@ -291,16 +287,16 @@ public class TestPointValues extends LuceneTestCase {
 
     Directory dir2 = newDirectory();
     iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir2, iwc);
+    IndexWriter w2 = new IndexWriter(dir2, iwc);
     doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[6]));
-    w.addDocument(doc);
-    try {
-      w.addIndexes(new Directory[] {dir});
-    } catch (IllegalArgumentException iae) {
-      assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", iae.getMessage());
-    }
-    IOUtils.close(w, dir, dir2);
+    w2.addDocument(doc);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w2.addIndexes(new Directory[] {dir});
+    });
+    assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", expected.getMessage());
+
+    IOUtils.close(w2, dir, dir2);
   }
 
   public void testIllegalNumBytesChangeViaAddIndexesCodecReader() throws Exception {
@@ -314,17 +310,17 @@ public class TestPointValues extends LuceneTestCase {
 
     Directory dir2 = newDirectory();
     iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir2, iwc);
+    IndexWriter w2 = new IndexWriter(dir2, iwc);
     doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[6]));
-    w.addDocument(doc);
+    w2.addDocument(doc);
     DirectoryReader r = DirectoryReader.open(dir);
-    try {
-      w.addIndexes(new CodecReader[] {getOnlySegmentReader(r)});
-    } catch (IllegalArgumentException iae) {
-      assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", iae.getMessage());
-    }
-    IOUtils.close(r, w, dir, dir2);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w2.addIndexes(new CodecReader[] {getOnlySegmentReader(r)});
+    });
+    assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", expected.getMessage());
+
+    IOUtils.close(r, w2, dir, dir2);
   }
 
   public void testIllegalNumBytesChangeViaAddIndexesSlowCodecReader() throws Exception {
@@ -338,17 +334,17 @@ public class TestPointValues extends LuceneTestCase {
 
     Directory dir2 = newDirectory();
     iwc = new IndexWriterConfig(new MockAnalyzer(random()));
-    w = new IndexWriter(dir2, iwc);
+    IndexWriter w2 = new IndexWriter(dir2, iwc);
     doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[6]));
-    w.addDocument(doc);
+    w2.addDocument(doc);
     DirectoryReader r = DirectoryReader.open(dir);
-    try {
-      TestUtil.addIndexesSlowly(w, r);
-    } catch (IllegalArgumentException iae) {
-      assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", iae.getMessage());
-    }
-    IOUtils.close(r, w, dir, dir2);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      TestUtil.addIndexesSlowly(w2, r);
+    });
+    assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", expected.getMessage());
+
+    IOUtils.close(r, w2, dir, dir2);
   }
 
   public void testIllegalTooManyBytes() throws Exception {
@@ -357,15 +353,13 @@ public class TestPointValues extends LuceneTestCase {
     IndexWriter w = new IndexWriter(dir, iwc);
     Document doc = new Document();
     doc.add(new BinaryPoint("dim", new byte[PointValues.MAX_NUM_BYTES+1]));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
-    doc = new Document();
-    doc.add(new IntPoint("dim", 17));
-    w.addDocument(doc);
+    });
+
+    Document doc2 = new Document();
+    doc2.add(new IntPoint("dim", 17));
+    w.addDocument(doc2);
     w.close();
     dir.close();
   }
@@ -380,15 +374,13 @@ public class TestPointValues extends LuceneTestCase {
       values[i] = new byte[4];
     }
     doc.add(new BinaryPoint("dim", values));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
-    doc = new Document();
-    doc.add(new IntPoint("dim", 17));
-    w.addDocument(doc);
+    });
+
+    Document doc2 = new Document();
+    doc2.add(new IntPoint("dim", 17));
+    w.addDocument(doc2);
     w.close();
     dir.close();
   }
@@ -441,69 +433,49 @@ public class TestPointValues extends LuceneTestCase {
 
   public void testInvalidIntPointUsage() throws Exception {
     IntPoint field = new IntPoint("field", 17, 42);
-    try {
-      field.setIntValue(14);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // good
-    }
 
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
+      field.setIntValue(14);
+    });
+    
+    expectThrows(IllegalStateException.class, () -> {
       field.numericValue();
-      fail("did not hit exception");
-    } catch (IllegalStateException ise) {
-      // good
-    }
+    });
   }
 
   public void testInvalidLongPointUsage() throws Exception {
     LongPoint field = new LongPoint("field", 17, 42);
-    try {
+
+    expectThrows(IllegalArgumentException.class, () -> {
       field.setLongValue(14);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // good
-    }
+    });
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       field.numericValue();
-      fail("did not hit exception");
-    } catch (IllegalStateException ise) {
-      // good
-    }
+    });
   }
 
   public void testInvalidFloatPointUsage() throws Exception {
     FloatPoint field = new FloatPoint("field", 17, 42);
-    try {
+
+    expectThrows(IllegalArgumentException.class, () -> {
       field.setFloatValue(14);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // good
-    }
+    });
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       field.numericValue();
-      fail("did not hit exception");
-    } catch (IllegalStateException ise) {
-      // good
-    }
+    });
   }
 
   public void testInvalidDoublePointUsage() throws Exception {
     DoublePoint field = new DoublePoint("field", 17, 42);
-    try {
+
+    expectThrows(IllegalArgumentException.class, () -> {
       field.setDoubleValue(14);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // good
-    }
+    });
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       field.numericValue();
-      fail("did not hit exception");
-    } catch (IllegalStateException ise) {
-      // good
-    }
+    });
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java b/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
index bf01c8a..aff0bd9 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
@@ -402,48 +402,36 @@ public class TestPostingsOffsets extends LuceneTestCase {
   
   // NOTE: the next two tests aren't that good as we need an EvilToken...
   public void testNegativeOffsets() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       checkTokens(new Token[] { 
           makeToken("foo", 1, -1, -1)
       });
-      fail();
-    } catch (IllegalArgumentException expected) {
-      //expected
-    }
+    });
   }
   
   public void testIllegalOffsets() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       checkTokens(new Token[] { 
           makeToken("foo", 1, 1, 0)
       });
-      fail();
-    } catch (IllegalArgumentException expected) {
-      //expected
-    }
+    });
   }
   
   public void testIllegalOffsetsAcrossFieldInstances() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       checkTokens(new Token[] { makeToken("use", 1, 150, 160) }, 
                   new Token[] { makeToken("use", 1, 50, 60) });
-      fail();
-    } catch (IllegalArgumentException expected) {
-      //expected
-    }
+    });
   }
    
   public void testBackwardsOffsets() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       checkTokens(new Token[] { 
          makeToken("foo", 1, 0, 3),
          makeToken("foo", 1, 4, 7),
          makeToken("foo", 0, 3, 6)
       });
-      fail();
-    } catch (IllegalArgumentException expected) {
-      // expected
-    }
+    });
   }
   
   public void testStackedTokens() throws Exception {
@@ -471,14 +459,14 @@ public class TestPostingsOffsets extends LuceneTestCase {
     // add good document
     Document doc = new Document();
     iw.addDocument(doc);
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
       ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
       doc.add(new Field("foo", "bar", ft));
       doc.add(new Field("foo", "bar", ft));
       iw.addDocument(doc);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {}
+    });
+    iw.commit();
     iw.close();
 
     // make sure we see our good doc

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java
index e43bc0e..f008afe 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java
@@ -204,25 +204,21 @@ public class TestSegmentReader extends LuceneTestCase {
   
   public void testOutOfBoundsAccess() throws IOException {
     int numDocs = reader.maxDoc();
-    try {
+
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       reader.document(-1);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {}
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       reader.getTermVectors(-1);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {}
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       reader.document(numDocs);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {}
+    });
     
-    try {
+    expectThrows(IndexOutOfBoundsException.class, () -> {
       reader.getTermVectors(numDocs);
-      fail();
-    } catch (IndexOutOfBoundsException expected) {}
-    
+    });    
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
index ad87ed8..c72e26d 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
@@ -113,13 +113,10 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase {
         .setMaxBufferedDocs(2));
 
     // Verify we catch misuse:
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       dp.snapshot();
-      fail("did not hit exception");
-    } catch(IllegalStateException ise) {
-      // expected
-    }
-    dp = (SnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
+    });
+
     writer.commit();
     
     final Thread t = new Thread() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
index fad0755..4b2a060 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
@@ -336,7 +336,7 @@ public class TestTermVectorsReader extends LuceneTestCase {
     reader.close();
   }
 
-  public void testIllegalIndexableField() throws Exception {
+  public void testIllegalPayloadsWithoutPositions() throws Exception {
     Directory dir = newDirectory();
     MockAnalyzer a = new MockAnalyzer(random());
     a.setEnableChecks(false);
@@ -346,116 +346,149 @@ public class TestTermVectorsReader extends LuceneTestCase {
     ft.setStoreTermVectorPayloads(true);
     Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
-      w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot index term vector payloads without term vector positions (field=\"field\")", iae.getMessage());
-    }
 
-    ft = new FieldType(TextField.TYPE_NOT_STORED);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      w.addDocument(doc);
+    });
+    assertEquals("cannot index term vector payloads without term vector positions (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
+  
+  public void testIllegalOffsetsWithoutVectors() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
     ft.setStoreTermVectors(false);
     ft.setStoreTermVectorOffsets(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot index term vector offsets when term vectors are not indexed (field=\"field\")", iae.getMessage());
-    }
+    });
+    assertEquals("cannot index term vector offsets when term vectors are not indexed (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
 
-    ft = new FieldType(TextField.TYPE_NOT_STORED);
+  public void testIllegalPositionsWithoutVectors() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
     ft.setStoreTermVectors(false);
     ft.setStoreTermVectorPositions(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
-      w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot index term vector positions when term vectors are not indexed (field=\"field\")", iae.getMessage());
-    }
 
-    ft = new FieldType(TextField.TYPE_NOT_STORED);
-    ft.setStoreTermVectors(false);
-    ft.setStoreTermVectorPayloads(true);
-    doc = new Document();
-    doc.add(new Field("field", "value", ft));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot index term vector payloads when term vectors are not indexed (field=\"field\")", iae.getMessage());
-    }
+    });
+    assertEquals("cannot index term vector positions when term vectors are not indexed (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
 
-    ft = new FieldType(TextField.TYPE_NOT_STORED);
-    ft.setStoreTermVectors(true);
+  public void testIllegalVectorPayloadsWithoutVectors() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
+    ft.setStoreTermVectors(false);
     ft.setStoreTermVectorPayloads(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot index term vector payloads without term vector positions (field=\"field\")", iae.getMessage());
-    }
+    });
+    assertEquals("cannot index term vector payloads when term vectors are not indexed (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
 
-    ft = new FieldType(StoredField.TYPE);
+  public void testIllegalVectorsWithoutIndexed() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(StoredField.TYPE);
     ft.setStoreTermVectors(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot store term vectors for a field that is not indexed (field=\"field\")", iae.getMessage());
-    }
+    });
+    assertEquals("cannot store term vectors for a field that is not indexed (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
 
-    ft = new FieldType(StoredField.TYPE);
+  public void testIllegalVectorPositionsWithoutIndexed() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(StoredField.TYPE);
     ft.setStoreTermVectorPositions(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot store term vector positions for a field that is not indexed (field=\"field\")", iae.getMessage());
-    }
+    });
+    assertEquals("cannot store term vector positions for a field that is not indexed (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
 
-    ft = new FieldType(StoredField.TYPE);
+  public void testIllegalVectorOffsetsWithoutIndexed() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(StoredField.TYPE);
     ft.setStoreTermVectorOffsets(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot store term vector offsets for a field that is not indexed (field=\"field\")", iae.getMessage());
-    }
-
-    ft = new FieldType(StoredField.TYPE);
+    });
+    assertEquals("cannot store term vector offsets for a field that is not indexed (field=\"field\")", expected.getMessage());
+    
+    w.close();
+    dir.close();
+  }
+  
+  public void testIllegalVectorPayloadsWithoutIndexed() throws Exception {
+    Directory dir = newDirectory();
+    MockAnalyzer a = new MockAnalyzer(random());
+    a.setEnableChecks(false);
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
+    FieldType ft = new FieldType(StoredField.TYPE);
     ft.setStoreTermVectorPayloads(true);
-    doc = new Document();
+    Document doc = new Document();
     doc.add(new Field("field", "value", ft));
-    try {
+    
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       w.addDocument(doc);
-      fail("did not hit exception");
-    } catch (IllegalArgumentException iae) {
-      // Expected
-      assertEquals("cannot store term vector payloads for a field that is not indexed (field=\"field\")", iae.getMessage());
-    }
+    });
+    assertEquals("cannot store term vector payloads for a field that is not indexed (field=\"field\")", expected.getMessage());
 
     w.close();
-    
     dir.close();
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsWriter.java
index f1ce915..11f1503 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsWriter.java
@@ -635,13 +635,11 @@ public class TestTermVectorsWriter extends LuceneTestCase {
     doc.add(new Field("field", "value2", ft2));
     
     // ensure broken doc hits exception
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       iw.addDocument(doc);
-      fail("didn't hit expected exception");
-    } catch (IllegalArgumentException iae) {
-      assertNotNull(iae.getMessage());
-      assertTrue(iae.getMessage().startsWith("all instances of a given field name must have the same term vectors settings"));
-    }
+    });
+    assertNotNull(expected.getMessage());
+    assertTrue(expected.getMessage().startsWith("all instances of a given field name must have the same term vectors settings"));
     
     // ensure good docs are still ok
     IndexReader ir = iw.getReader();
@@ -665,12 +663,11 @@ public class TestTermVectorsWriter extends LuceneTestCase {
     ft.setStoreTermVectors(true);
     ft.freeze();
     doc.add(new Field("field", "value", ft));
-    try {
+
+    expectThrows(IllegalArgumentException.class, () -> {
       iw.addDocument(doc);
-      fail("should have hit exc");
-    } catch (IllegalArgumentException iae) {
-      // expected
-    }
+    });
+
     IndexReader r = DirectoryReader.open(iw);
 
     // Make sure the exc didn't lose our first document:

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
index 1c83e06..c8a87d3 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTieredMergePolicy.java
@@ -170,12 +170,9 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
     tmp.setMaxMergedSegmentMB(Long.MAX_VALUE/1024/1024.);
     assertEquals(Long.MAX_VALUE/1024/1024., tmp.getMaxMergedSegmentMB(), EPSILON*Long.MAX_VALUE);
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       tmp.setMaxMergedSegmentMB(-2.0);
-      fail("Didn't throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {
-      // pass
-    }
+    });
     
     tmp.setFloorSegmentMB(2.0);
     assertEquals(2.0, tmp.getFloorSegmentMB(), EPSILON);
@@ -186,12 +183,9 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
     tmp.setFloorSegmentMB(Long.MAX_VALUE/1024/1024.);
     assertEquals(Long.MAX_VALUE/1024/1024., tmp.getFloorSegmentMB(), EPSILON*Long.MAX_VALUE);
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       tmp.setFloorSegmentMB(-2.0);
-      fail("Didn't throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {
-      // pass
-    }
+    });
     
     tmp.setMaxCFSSegmentSizeMB(2.0);
     assertEquals(2.0, tmp.getMaxCFSSegmentSizeMB(), EPSILON);
@@ -202,12 +196,9 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
     tmp.setMaxCFSSegmentSizeMB(Long.MAX_VALUE/1024/1024.);
     assertEquals(Long.MAX_VALUE/1024/1024., tmp.getMaxCFSSegmentSizeMB(), EPSILON*Long.MAX_VALUE);
     
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       tmp.setMaxCFSSegmentSizeMB(-2.0);
-      fail("Didn't throw IllegalArgumentException");
-    } catch (IllegalArgumentException iae) {
-      // pass
-    }
+    });
     
     // TODO: Add more checks for other non-double setters!
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/MultiCollectorTest.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/MultiCollectorTest.java b/lucene/core/src/test/org/apache/lucene/search/MultiCollectorTest.java
index fe63741..de97954 100644
--- a/lucene/core/src/test/org/apache/lucene/search/MultiCollectorTest.java
+++ b/lucene/core/src/test/org/apache/lucene/search/MultiCollectorTest.java
@@ -59,12 +59,9 @@ public class MultiCollectorTest extends LuceneTestCase {
   @Test
   public void testNullCollectors() throws Exception {
     // Tests that the collector rejects all null collectors.
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       MultiCollector.wrap(null, null);
-      fail("only null collectors should not be supported");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
+    });
 
     // Tests that the collector handles some null collectors well. If it
     // doesn't, an NPE would be thrown.
@@ -141,12 +138,9 @@ public class MultiCollectorTest extends LuceneTestCase {
     
     final LeafReaderContext ctx = reader.leaves().get(0);
 
-    try {
+    expectThrows(AssertionError.class, () -> {
       collector(false, ScoreCachingWrappingScorer.class).getLeafCollector(ctx).setScorer(new FakeScorer());
-      fail("The collector was configured to expect a ScoreCachingWrappingScorer and did not fail when pass in a FakeScorer");
-    } catch (AssertionError e) {
-      // expected
-    }
+    });
 
     // no collector needs scores => no caching
     Collector c1 = collector(false, FakeScorer.class);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
index 5e16bcb..3970355 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
@@ -189,12 +189,9 @@ public class TestBooleanQuery extends LuceneTestCase {
   }
 
   public void testException() {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       BooleanQuery.setMaxClauseCount(0);
-      fail();
-    } catch (IllegalArgumentException e) {
-      // okay
-    }
+    });
   }
 
   // LUCENE-1630

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java
index 1886919..89304ba 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java
@@ -99,12 +99,9 @@ public class TestCachingCollector extends LuceneTestCase {
     
     assertFalse("CachingCollector should not be cached due to low memory limit", cc.isCached());
     
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       cc.replay(new NoOpCollector());
-      fail("replay should fail if CachingCollector is not cached");
-    } catch (IllegalStateException e) {
-      // expected
-    }
+    });
   }
   
   public void testCachedArraysAllocation() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
index 2ed7c43..8217eb1 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
@@ -422,12 +422,10 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc
       }
       };
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       new SearcherManager(w.w, false, false, theEvilOne);
-      fail("didn't hit expected exception");
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
+
     w.close();
     other.close();
     dir.close();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
index 7f36902..79dc157 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
@@ -449,52 +449,39 @@ public class TestFuzzyQuery extends LuceneTestCase {
     assertEquals(1, hits.length);
     assertEquals("foobar", searcher.doc(hits[0].doc).get("field"));
     
-    try {
-      q = new FuzzyQuery(new Term("field", "t"), 3);
-      fail();
-    } catch (IllegalArgumentException expected) {
-      // expected
-    }
-      
+    expectThrows(IllegalArgumentException.class, () -> {
+      new FuzzyQuery(new Term("field", "t"), 3);
+    });
+
     reader.close();
     index.close();
   }
 
   public void testValidation() {
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       new FuzzyQuery(new Term("field", "foo"), -1, 0, 1, false);
-      fail("Expected error for illegal max edits value");
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("maxEdits"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("maxEdits"));
 
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new FuzzyQuery(new Term("field", "foo"), LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE + 1, 0, 1, false);
-      fail("Expected error for illegal max edits value");
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("maxEdits must be between"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("maxEdits must be between"));
 
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new FuzzyQuery(new Term("field", "foo"), 1, -1, 1, false);
-      fail("Expected error for illegal prefix length value");
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("prefixLength cannot be negative"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("prefixLength cannot be negative"));
 
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new FuzzyQuery(new Term("field", "foo"), 1, 0, -1, false);
-      fail("Expected error for illegal max expansions value");
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("maxExpansions must be positive"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("maxExpansions must be positive"));
 
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new FuzzyQuery(new Term("field", "foo"), 1, 0, -1, false);
-      fail("Expected error for illegal max expansions value");
-    } catch (IllegalArgumentException e) {
-      assertTrue(e.getMessage().contains("maxExpansions must be positive"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("maxExpansions must be positive"));
   }
   
   private void addDoc(String text, RandomIndexWriter writer) throws IOException {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
index c561d64..e7cdfcd 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java
@@ -129,14 +129,11 @@ public class TestIndexSearcher extends LuceneTestCase {
     w.close();
 
     IndexSearcher s = new IndexSearcher(r);
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       s.searchAfter(new ScoreDoc(r.maxDoc(), 0.54f), new MatchAllDocsQuery(), 10);
-      fail("should have hit IllegalArgumentException when searchAfter exceeds maxDoc");
-    } catch (IllegalArgumentException e) {
-      // ok
-    } finally {
-      IOUtils.close(r, dir);
-    }
+    });
+
+    IOUtils.close(r, dir);
   }
 
   public void testCount() throws IOException {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java
index 4ef54da..3b4e1bd 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java
@@ -152,12 +152,9 @@ public class TestMultiCollector extends LuceneTestCase {
     assertFalse(setScorerCalled1.get());
     assertTrue(setScorerCalled2.get());
 
-    try {
+    expectThrows(CollectionTerminatedException.class, () -> {
       leafCollector.collect(1);
-      fail();
-    } catch (CollectionTerminatedException e) {
-      // expected
-    }
+    });
 
     setScorerCalled1.set(false);
     setScorerCalled2.set(false);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
index d2fec0e..5c81fed 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
@@ -125,13 +125,10 @@ public class TestMultiPhraseQuery extends LuceneTestCase {
                                     // foobar pizza
     
     MultiPhraseQuery query4 = new MultiPhraseQuery();
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       query4.add(new Term("field1", "foo"));
       query4.add(new Term("field2", "foobar"));
-      fail();
-    } catch (IllegalArgumentException e) {
-      // okay, all terms must belong to the same field
-    }
+    });
     
     writer.close();
     reader.close();
@@ -571,12 +568,9 @@ public class TestMultiPhraseQuery extends LuceneTestCase {
     MultiPhraseQuery query = new MultiPhraseQuery();
     query.add(new Term("field", "two"));
     query.add(new Term("field", "one"));
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       query.setSlop(-2);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      // expected exception
-    }
+    });
   }
   
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java
index 3772d45..458dd68 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java
@@ -215,12 +215,12 @@ public class TestMultiTermQueryRewrites extends LuceneTestCase {
     final MultiTermQuery mtq = TermRangeQuery.newStringRange("data", "2", "7", true, true);
     mtq.setRewriteMethod(method);
     try {
-      multiSearcherDupls.rewrite(mtq);
-      fail("Should throw BooleanQuery.TooManyClauses");
-    } catch (BooleanQuery.TooManyClauses e) {
+      BooleanQuery.TooManyClauses expected = expectThrows(BooleanQuery.TooManyClauses.class, () -> {
+        multiSearcherDupls.rewrite(mtq);
+      });
       //  Maybe remove this assert in later versions, when internal API changes:
       assertEquals("Should throw BooleanQuery.TooManyClauses with a stacktrace containing checkMaxClauseCount()",
-        "checkMaxClauseCount", e.getStackTrace()[0].getMethodName());
+        "checkMaxClauseCount", expected.getStackTrace()[0].getMethodName());
     } finally {
       BooleanQuery.setMaxClauseCount(savedMaxClauseCount);
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
index c9f8f97..cf77903 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
@@ -693,33 +693,24 @@ public class TestPhraseQuery extends LuceneTestCase {
   }
   
   public void testNegativeSlop() throws Exception {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new PhraseQuery(-2, "field", "two", "one");
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      // expected exception
-    }
+    });
   }
 
   public void testNegativePosition() throws Exception {
     PhraseQuery.Builder builder = new PhraseQuery.Builder();
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       builder.add(new Term("field", "two"), -42);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      // expected exception
-    }
+    });
   }
 
   public void testBackwardPositions() throws Exception {
     PhraseQuery.Builder builder = new PhraseQuery.Builder();
     builder.add(new Term("field", "one"), 1);
     builder.add(new Term("field", "two"), 5);
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       builder.add(new Term("field", "three"), 4);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      // expected exception
-    }
+    });
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
index 3fca681..5758546 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
@@ -948,11 +948,10 @@ public class TestPointQueries extends LuceneTestCase {
     // no wrapping, else the exc might happen in executor thread:
     IndexSearcher s = new IndexSearcher(r);
     byte[][] point = new byte[2][];
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       s.count(new PointRangeQuery("value", point, new boolean[] {true, true}, point, new boolean[] {true, true}));
-    } catch (IllegalArgumentException iae) {
-      assertEquals("field=\"value\" was indexed with numDims=1 but this query has numDims=2", iae.getMessage());
-    }
+    });
+    assertEquals("field=\"value\" was indexed with numDims=1 but this query has numDims=2", expected.getMessage());
 
     IOUtils.close(r, w, dir);
   }
@@ -972,11 +971,10 @@ public class TestPointQueries extends LuceneTestCase {
     IndexSearcher s = new IndexSearcher(r);
     byte[][] point = new byte[1][];
     point[0] = new byte[10];
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       s.count(new PointRangeQuery("value", point, new boolean[] {true}, point, new boolean[] {true}));
-    } catch (IllegalArgumentException iae) {
-      assertEquals("field=\"value\" was indexed with bytesPerDim=8 but this query has bytesPerDim=10", iae.getMessage());
-    }
+    });
+    assertEquals("field=\"value\" was indexed with bytesPerDim=8 but this query has bytesPerDim=10", expected.getMessage());
 
     IOUtils.close(r, w, dir);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java b/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java
index f33acf9..02419b8 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSearcherManager.java
@@ -280,12 +280,9 @@ public class TestSearcherManager extends ThreadedIndexingAndSearchingTestCase {
     searcherManager.close();
     awaitClose.countDown();
     thread.join();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       searcherManager.acquire();
-      fail("already closed");
-    } catch (AlreadyClosedException ex) {
-      // expected
-    }
+    });
     assertFalse(success.get());
     assertTrue(triedReopen.get());
     assertNull("" + exc[0], exc[0]);
@@ -325,12 +322,9 @@ public class TestSearcherManager extends ThreadedIndexingAndSearchingTestCase {
     acquire = sm.acquire();
     acquire.getIndexReader().decRef();
     sm.release(acquire);
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       sm.acquire();
-      fail("acquire should have thrown an IllegalStateException since we modified the refCount outside of the manager");
-    } catch (IllegalStateException ex) {
-      //
-    }
+    });
 
     // sm.close(); -- already closed
     writer.close();
@@ -348,19 +342,16 @@ public class TestSearcherManager extends ThreadedIndexingAndSearchingTestCase {
     // this should succeed;
     sm.release(s);
     
-    try {
-      // this should fail
+    // this should fail
+    expectThrows(AlreadyClosedException.class, () -> {
       sm.acquire();
-    } catch (AlreadyClosedException e) {
-      // ok
-    }
+    });
     
-    try {
-      // this should fail
+    // this should fail
+    expectThrows(AlreadyClosedException.class, () -> {
       sm.maybeRefresh();
-    } catch (AlreadyClosedException e) {
-      // ok
-    }
+    });
+
     dir.close();
   }
 
@@ -405,16 +396,12 @@ public class TestSearcherManager extends ThreadedIndexingAndSearchingTestCase {
       }
       };
 
-    try {
+    expectThrows(IllegalStateException.class, () -> {
       new SearcherManager(dir, theEvilOne);
-    } catch (IllegalStateException ise) {
-      // expected
-    }
-    try {
+    });
+    expectThrows(IllegalStateException.class, () -> {
       new SearcherManager(w.w, random.nextBoolean(), false, theEvilOne);
-    } catch (IllegalStateException ise) {
-      // expected
-    }
+    });
     w.close();
     other.close();
     dir.close();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java
index 95e9865..bc0a2d0 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSynonymQuery.java
@@ -40,10 +40,9 @@ public class TestSynonymQuery extends LuceneTestCase {
   }
   
   public void testBogusParams() {
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       new SynonymQuery(new Term("field1", "a"), new Term("field2", "b"));
-      fail();
-    } catch (IllegalArgumentException expected) {}
+    });
   }
 
   public void testToString() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
index cadc3ce..30061b5 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
@@ -185,15 +185,12 @@ public class TestTermScorer extends LuceneTestCase {
     IndexSearcher indexSearcher = new IndexSearcher(forbiddenNorms);
     
     Weight weight = indexSearcher.createNormalizedWeight(termQuery, true);
-    try {
+    expectThrows(AssertionError.class, () -> {
       weight.scorer(forbiddenNorms.getContext()).iterator().nextDoc();
-      fail("Should load norms");
-    } catch (AssertionError e) {
-      // ok
-    }
+    });
     
-    weight = indexSearcher.createNormalizedWeight(termQuery, false);
+    Weight weight2 = indexSearcher.createNormalizedWeight(termQuery, false);
     // should not fail this time since norms are not necessary
-    weight.scorer(forbiddenNorms.getContext()).iterator().nextDoc();
+    weight2.scorer(forbiddenNorms.getContext()).iterator().nextDoc();
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
index b98de80..d26006c 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
@@ -181,18 +181,10 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
     myHc.setSlowDown(SLOW_DOWN);
     Collector tlCollector = createTimedCollector(myHc, TIME_ALLOWED, greedy);
 
-    // search
-    TimeExceededException timeoutException = null;
-    try {
+    // search: must get exception
+    TimeExceededException timeoutException = expectThrows(TimeExceededException.class, () -> {
       search(tlCollector);
-    } catch (TimeExceededException x) {
-      timeoutException = x;
-    } catch (Exception e) {
-      assertTrue("Unexpected exception: "+e, false); //==fail
-    }
-    
-    // must get exception
-    assertNotNull( "Timeout expected!", timeoutException );
+    });
 
     // greediness affect last doc collected
     int exceptionDoc = timeoutException.getLastDocCollected();
@@ -275,18 +267,13 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
   public void testNoHits() throws IOException {
     MyHitCollector myHc = new MyHitCollector();
     Collector collector = createTimedCollector(myHc, -1, random().nextBoolean());
-    // search
-    TimeExceededException timeoutException = null;
-    try {
+    // search: must get exception
+    expectThrows(TimeExceededException.class, () -> {
       BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder(); // won't match - we only test if we check timeout when collectors are pulled
       booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "one")), BooleanClause.Occur.MUST);
       booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "blueberry")), BooleanClause.Occur.MUST);
       searcher.search(booleanQuery.build(), collector);
-    } catch (TimeExceededException x) {
-      timeoutException = x;
-    }
-    // must get exception
-    assertNotNull("Timeout expected!", timeoutException);
+    });
     assertEquals(-1, myHc.getLastDocCollected());
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/similarities/TestBM25Similarity.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/similarities/TestBM25Similarity.java b/lucene/core/src/test/org/apache/lucene/search/similarities/TestBM25Similarity.java
index f653971..dc43406 100644
--- a/lucene/core/src/test/org/apache/lucene/search/similarities/TestBM25Similarity.java
+++ b/lucene/core/src/test/org/apache/lucene/search/similarities/TestBM25Similarity.java
@@ -35,48 +35,41 @@ public class TestBM25Similarity extends LuceneTestCase {
   }
   
   public void testIllegalK1() {
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(Float.POSITIVE_INFINITY, 0.75f);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal k1 value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal k1 value"));
     
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(-1, 0.75f);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal k1 value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal k1 value"));
     
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(Float.NaN, 0.75f);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal k1 value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal k1 value"));
   }
   
   public void testIllegalB() {
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(1.2f, 2f);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal b value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal b value"));
     
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(1.2f, -1f);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal b value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal b value"));
     
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(1.2f, Float.POSITIVE_INFINITY);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal b value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal b value"));
     
-    try {
+    expected = expectThrows(IllegalArgumentException.class, () -> {
       new BM25Similarity(1.2f, Float.NaN);
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("illegal b value"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("illegal b value"));
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNearQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNearQuery.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNearQuery.java
index b010147..fbc098c 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNearQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNearQuery.java
@@ -48,12 +48,10 @@ public class TestSpanNearQuery extends LuceneTestCase {
   public void testDifferentField() throws Exception {
     SpanTermQuery q1 = new SpanTermQuery(new Term("field1", "foo"));
     SpanTermQuery q2 = new SpanTermQuery(new Term("field2", "bar"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       new SpanNearQuery(new SpanQuery[] { q1, q2 }, 10, true);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("must have same field"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("must have same field"));
   }
   
   public void testNoPositions() throws IOException {
@@ -70,12 +68,11 @@ public class TestSpanNearQuery extends LuceneTestCase {
     SpanTermQuery query = new SpanTermQuery(new Term("foo", "bar"));
     SpanTermQuery query2 = new SpanTermQuery(new Term("foo", "baz"));
 
-    try {
+    IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
       is.search(new SpanNearQuery(new SpanQuery[] { query, query2 }, 10, true), 5);
-      fail("didn't get expected exception");
-    } catch (IllegalStateException expected) {
-      assertTrue(expected.getMessage().contains("was indexed without position data"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("was indexed without position data"));
+
     ir.close();
     dir.close();
   }
@@ -83,18 +80,14 @@ public class TestSpanNearQuery extends LuceneTestCase {
   public void testBuilder() throws Exception {
 
     // Can't add subclauses from different fields
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       SpanNearQuery.newOrderedNearQuery("field1").addClause(new SpanTermQuery(new Term("field2", "term")));
-      fail("Expected an error when adding a clause with a different field");
-    }
-    catch (IllegalArgumentException e) {}
+    });
 
     // Can't add gaps to unordered queries
-    try {
+    expectThrows(IllegalArgumentException.class, () -> {
       SpanNearQuery.newUnorderedNearQuery("field1").addGap(1);
-      fail("Expected an error when adding a gap to an unordered query");
-    }
-    catch (IllegalArgumentException e) {}
+    });
 
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNotQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNotQuery.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNotQuery.java
index 79026bb..4ffb270 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNotQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanNotQuery.java
@@ -48,12 +48,10 @@ public class TestSpanNotQuery extends LuceneTestCase {
   public void testDifferentField() throws Exception {
     SpanTermQuery q1 = new SpanTermQuery(new Term("field1", "foo"));
     SpanTermQuery q2 = new SpanTermQuery(new Term("field2", "bar"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       new SpanNotQuery(q1, q2);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("must have same field"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("must have same field"));
   }
   
   public void testNoPositions() throws IOException {
@@ -70,12 +68,11 @@ public class TestSpanNotQuery extends LuceneTestCase {
     SpanTermQuery query = new SpanTermQuery(new Term("foo", "bar"));
     SpanTermQuery query2 = new SpanTermQuery(new Term("foo", "baz"));
 
-    try {
+    IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
       is.search(new SpanNotQuery(query, query2), 5);
-      fail("didn't get expected exception");
-    } catch (IllegalStateException expected) {
-      assertTrue(expected.getMessage().contains("was indexed without position data"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("was indexed without position data"));
+
     ir.close();
     dir.close();
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanOrQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanOrQuery.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanOrQuery.java
index 6f3c41f..b0fe485 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanOrQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanOrQuery.java
@@ -45,11 +45,9 @@ public class TestSpanOrQuery extends LuceneTestCase {
   public void testDifferentField() throws Exception {
     SpanTermQuery q1 = new SpanTermQuery(new Term("field1", "foo"));
     SpanTermQuery q2 = new SpanTermQuery(new Term("field2", "bar"));
-    try {
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
       new SpanOrQuery(q1, q2);
-      fail("didn't get expected exception");
-    } catch (IllegalArgumentException expected) {
-      assertTrue(expected.getMessage().contains("must have same field"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("must have same field"));
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanTermQuery.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanTermQuery.java
index 97951bf..a1498ce 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanTermQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanTermQuery.java
@@ -53,12 +53,11 @@ public class TestSpanTermQuery extends LuceneTestCase {
     
     IndexSearcher is = new IndexSearcher(ir);
     SpanTermQuery query = new SpanTermQuery(new Term("foo", "bar"));
-    try {
+    IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
       is.search(query, 5);
-      fail("didn't get expected exception");
-    } catch (IllegalStateException expected) {
-      assertTrue(expected.getMessage().contains("was indexed without position data"));
-    }
+    });
+    assertTrue(expected.getMessage().contains("was indexed without position data"));
+
     ir.close();
     dir.close();
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
index df81d8f..178d792 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
@@ -142,26 +142,24 @@ public class TestBufferedIndexInput extends LuceneTestCase {
      input.seek(pos);
      checkReadBytes(input, 10, pos);  
      input.seek(pos);
-     try {
+     // block read past end of file
+     expectThrows(IOException.class, () -> {
        checkReadBytes(input, 11, pos);
-           fail("Block read past end of file");
-       } catch (IOException e) {
-           /* success */
-       }
+     });
+
      input.seek(pos);
-     try {
+
+     // block read past end of file
+     expectThrows(IOException.class, () -> {
        checkReadBytes(input, 50, pos);
-           fail("Block read past end of file");
-       } catch (IOException e) {
-           /* success */
-       }
+     });
+
      input.seek(pos);
-     try {
+
+     // block read past end of file
+     expectThrows(IOException.class, () -> {
        checkReadBytes(input, 100000, pos);
-           fail("Block read past end of file");
-       } catch (IOException e) {
-           /* success */
-       }
+     });
   }
 
     // byten emulates a file - byten(n) returns the n'th byte in that file.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
index 99f9e0c..571119d 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
@@ -89,12 +89,9 @@ public class TestDirectory extends LuceneTestCase {
       Lock lock = dir.obtainLock(lockname);
 
       for (Directory other : dirs) {
-        try {
+        expectThrows(LockObtainFailedException.class, () -> {
           other.obtainLock(lockname);
-          fail("didnt get exception");
-        } catch (LockObtainFailedException e) {
-          // OK
-        }
+        });
       }
 
       lock.close();
@@ -131,12 +128,9 @@ public class TestDirectory extends LuceneTestCase {
       IndexOutput out = fsDir.createOutput("afile", newIOContext(random()));
       out.close();
       assertTrue(slowFileExists(fsDir, "afile"));
-      try {
+      expectThrows(IOException.class, () -> {
         new SimpleFSDirectory(path.resolve("afile"));
-        fail("did not hit expected exception");
-      } catch (IOException nsde) {
-        // Expected
-      }
+      });
     } finally {
       fsDir.close();
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
index bdd3dfa..927c913 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
@@ -101,12 +101,10 @@ public class TestFileSwitchDirectory extends BaseDirectoryTestCase {
     Path primDir = createTempDir("foo");
     Path secondDir = createTempDir("bar");
     Directory dir = newFSSwitchDirectory(primDir, secondDir, Collections.<String>emptySet());
-    try {
+    expectThrows(IndexNotFoundException.class, () -> {
       DirectoryReader.open(dir);
-      fail("did not hit expected exception");
-    } catch (IndexNotFoundException nsde) {
-      // expected
-    }
+    });
+
     dir.close();
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
index 3b6ef22..76632cb 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
@@ -59,24 +59,16 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
     IndexInput two = one.clone();
     IndexInput three = two.clone(); // clone of clone
     one.close();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       one.readVInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
-    try {
+    });
+    expectThrows(AlreadyClosedException.class, () -> {
       two.readVInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
-    try {
+    });
+    expectThrows(AlreadyClosedException.class, () -> {
       three.readVInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
+    });
+
     two.close();
     three.close();
     // test double close of master:
@@ -94,12 +86,9 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
     IndexInput three = two.clone(); // clone of clone
     two.close();
     assertEquals(5, one.readVInt());
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       two.readVInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
+    });
     assertEquals(5, three.readVInt());
     one.close();
     three.close();
@@ -118,30 +107,19 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
     IndexInput three = one.clone(); // clone of clone
     IndexInput four = two.clone(); // clone of clone
     slicer.close();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       one.readInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
-    try {
+    });
+    expectThrows(AlreadyClosedException.class, () -> {
       two.readInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
-    try {
+    });
+    expectThrows(AlreadyClosedException.class, () -> {
       three.readInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
-    try {
+    });
+    expectThrows(AlreadyClosedException.class, () -> {
       four.readInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
+    });
+
     one.close();
     two.close();
     three.close();
@@ -161,17 +139,14 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
     IndexInput one = slicer.slice("first int", 0, 4);
     IndexInput two = slicer.slice("second int", 4, 4);
     one.close();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       one.readInt();
-      fail("Must throw AlreadyClosedException");
-    } catch (AlreadyClosedException ignore) {
-      // pass
-    }
+    });
     assertEquals(2, two.readInt());
-    // reopen a new slice "one":
-    one = slicer.slice("first int", 0, 4);
-    assertEquals(1, one.readInt());
-    one.close();
+    // reopen a new slice "another":
+    IndexInput another = slicer.slice("first int", 0, 4);
+    assertEquals(1, another.readInt());
+    another.close();
     two.close();
     slicer.close();
     mmapDir.close();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java b/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java
index 4e62daf..5d202bf 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestNativeFSLockFactory.java
@@ -50,14 +50,11 @@ public class TestNativeFSLockFactory extends BaseLockFactoryTestCase {
     NativeFSLockFactory.NativeFSLock lock =  (NativeFSLockFactory.NativeFSLock) dir.obtainLock("test.lock");
     lock.ensureValid();
     lock.lock.release();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       lock.ensureValid();
-      fail("no exception");
-    } catch (AlreadyClosedException expected) {
-      // ok
-    } finally {
-      IOUtils.closeWhileHandlingException(lock);
-    }
+    });
+
+    IOUtils.closeWhileHandlingException(lock);
     dir.close();
   }
   
@@ -67,14 +64,11 @@ public class TestNativeFSLockFactory extends BaseLockFactoryTestCase {
     NativeFSLockFactory.NativeFSLock lock =  (NativeFSLockFactory.NativeFSLock) dir.obtainLock("test.lock");
     lock.ensureValid();
     lock.channel.close();
-    try {
+    expectThrows(AlreadyClosedException.class, () -> {
       lock.ensureValid();
-      fail("no exception");
-    } catch (AlreadyClosedException expected) {
-      // ok
-    } finally {
-      IOUtils.closeWhileHandlingException(lock);
-    }
+    });
+
+    IOUtils.closeWhileHandlingException(lock);
     dir.close();
   }
   
@@ -88,14 +82,11 @@ public class TestNativeFSLockFactory extends BaseLockFactoryTestCase {
 
       dir.deleteFile("test.lock");
 
-      try {
+      expectThrows(IOException.class, () -> {
         lock.ensureValid();
-        fail("no exception");
-      } catch (IOException expected) {
-        // ok
-      } finally {
-        IOUtils.closeWhileHandlingException(lock);
-      }
+      });
+      
+      IOUtils.closeWhileHandlingException(lock);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
index c5d3066..d4e8bfc 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
@@ -175,17 +175,14 @@ public class TestRAMDirectory extends BaseDirectoryTestCase {
       }
 
       try (IndexInput is = dir.openInput("foo", newIOContext(random))) {
-        try {
+        expectThrows(EOFException.class, () -> {
           is.seek(0);
           // Here, I go past EOF.
           is.seek(len + random().nextInt(2048));
           // since EOF is not enforced by the previous call in RAMInputStream
           // this call to readBytes should throw the exception.
           is.readBytes(bytes, 0, 16);
-          fail("Did not get EOFException");
-        } catch (EOFException eof) {
-          // expected!
-        }
+        });
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java b/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java
index 84bdd9f..ec50498 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestSimpleFSLockFactory.java
@@ -46,14 +46,10 @@ public class TestSimpleFSLockFactory extends BaseLockFactoryTestCase {
         assumeNoException("test requires the ability to delete a locked file", e);
       }
     
-      try {
+      expectThrows(IOException.class, () -> {
         lock.ensureValid();
-        fail("no exception");
-      } catch (IOException expected) {
-        // ok
-      } finally {
-        IOUtils.closeWhileHandlingException(lock);
-      }
+      });
+      IOUtils.closeWhileHandlingException(lock);
     } finally {
       // Do this in finally clause in case the assumeNoException is false:
       dir.close();