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:26 UTC
[6/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/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2CharFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2CharFilterFactory.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2CharFilterFactory.java
index da81777..90055f1 100644
--- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2CharFilterFactory.java
+++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2CharFilterFactory.java
@@ -38,14 +38,12 @@ public class TestICUNormalizer2CharFilterFactory extends BaseTokenStreamTestCase
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new ICUNormalizer2CharFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
// TODO: add tests for different forms
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2FilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2FilterFactory.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2FilterFactory.java
index 90a14f3..5533215 100644
--- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2FilterFactory.java
+++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUNormalizer2FilterFactory.java
@@ -39,14 +39,12 @@ public class TestICUNormalizer2FilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new ICUNormalizer2FilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
// TODO: add tests for different forms
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUTransformFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUTransformFilterFactory.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUTransformFilterFactory.java
index b74984c..a478217 100644
--- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUTransformFilterFactory.java
+++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUTransformFilterFactory.java
@@ -66,14 +66,12 @@ public class TestICUTransformFilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new ICUTransformFilterFactory(new HashMap<String,String>() {{
put("id", "Null");
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestCharArrayIterator.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestCharArrayIterator.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestCharArrayIterator.java
index 14d7f0f..28856fb 100644
--- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestCharArrayIterator.java
+++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestCharArrayIterator.java
@@ -86,12 +86,9 @@ public class TestCharArrayIterator extends LuceneTestCase {
public void testSetIndex() {
CharArrayIterator ci = new CharArrayIterator();
ci.setText("test".toCharArray(), 0, "test".length());
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
ci.setIndex(5);
- fail();
- } catch (Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
+ });
}
public void testClone() {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestICUTokenizerFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestICUTokenizerFactory.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestICUTokenizerFactory.java
index e288c4d..f44e745 100644
--- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestICUTokenizerFactory.java
+++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestICUTokenizerFactory.java
@@ -92,13 +92,11 @@ public class TestICUTokenizerFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new ICUTokenizerFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseBaseFormFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseBaseFormFilterFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseBaseFormFilterFactory.java
index b140516..e52d98c 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseBaseFormFilterFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseBaseFormFilterFactory.java
@@ -43,13 +43,11 @@ public class TestJapaneseBaseFormFilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapaneseBaseFormFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseIterationMarkCharFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseIterationMarkCharFilterFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseIterationMarkCharFilterFactory.java
index fe5ae66..e14c822 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseIterationMarkCharFilterFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseIterationMarkCharFilterFactory.java
@@ -91,13 +91,11 @@ public class TestJapaneseIterationMarkCharFilterFactory extends BaseTokenStreamT
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapaneseIterationMarkCharFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseKatakanaStemFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseKatakanaStemFilterFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseKatakanaStemFilterFactory.java
index 6a112e7..39c7a17 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseKatakanaStemFilterFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseKatakanaStemFilterFactory.java
@@ -43,13 +43,11 @@ public class TestJapaneseKatakanaStemFilterFactory extends BaseTokenStreamTestCa
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapaneseKatakanaStemFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseNumberFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseNumberFilterFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseNumberFilterFactory.java
index 44e3234..a92d3f0 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseNumberFilterFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseNumberFilterFactory.java
@@ -50,13 +50,11 @@ public class TestJapaneseNumberFilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapaneseNumberFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapanesePartOfSpeechStopFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapanesePartOfSpeechStopFilterFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapanesePartOfSpeechStopFilterFactory.java
index 979fd7f..501d2fc 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapanesePartOfSpeechStopFilterFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapanesePartOfSpeechStopFilterFactory.java
@@ -53,14 +53,12 @@ public class TestJapanesePartOfSpeechStopFilterFactory extends BaseTokenStreamTe
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapanesePartOfSpeechStopFilterFactory(new HashMap<String,String>() {{
put("luceneMatchVersion", Version.LATEST.toString());
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseReadingFormFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseReadingFormFilterFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseReadingFormFilterFactory.java
index 1b12ec1..266fd01 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseReadingFormFilterFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseReadingFormFilterFactory.java
@@ -42,13 +42,11 @@ public class TestJapaneseReadingFormFilterFactory extends BaseTokenStreamTestCas
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapaneseReadingFormFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizerFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizerFactory.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizerFactory.java
index 45bf603..bdf22cf 100644
--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizerFactory.java
+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizerFactory.java
@@ -111,14 +111,12 @@ public class TestJapaneseTokenizerFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new JapaneseTokenizerFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
private TokenStream makeTokenStream(HashMap<String, String> args, String in) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/morfologik/src/test/org/apache/lucene/analysis/morfologik/TestMorfologikFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/morfologik/src/test/org/apache/lucene/analysis/morfologik/TestMorfologikFilterFactory.java b/lucene/analysis/morfologik/src/test/org/apache/lucene/analysis/morfologik/TestMorfologikFilterFactory.java
index 9a597fc..d971dbd 100644
--- a/lucene/analysis/morfologik/src/test/org/apache/lucene/analysis/morfologik/TestMorfologikFilterFactory.java
+++ b/lucene/analysis/morfologik/src/test/org/apache/lucene/analysis/morfologik/TestMorfologikFilterFactory.java
@@ -75,26 +75,22 @@ public class TestMorfologikFilterFactory extends BaseTokenStreamTestCase {
public void testMissingDictionary() throws Exception {
final ResourceLoader loader = new ClasspathResourceLoader(TestMorfologikFilterFactory.class);
- try {
+ IOException expected = expectThrows(IOException.class, () -> {
Map<String,String> params = new HashMap<>();
params.put(MorfologikFilterFactory.DICTIONARY_ATTRIBUTE, "missing-dictionary-resource.dict");
MorfologikFilterFactory factory = new MorfologikFilterFactory(params);
factory.inform(loader);
- fail();
- } catch (IOException e) {
- assertTrue(e.getMessage().contains("Resource not found"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Resource not found"));
}
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
HashMap<String,String> params = new HashMap<String,String>();
params.put("bogusArg", "bogusValue");
new MorfologikFilterFactory(params);
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestBeiderMorseFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestBeiderMorseFilterFactory.java b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestBeiderMorseFilterFactory.java
index c29a9b4..5c9887e 100644
--- a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestBeiderMorseFilterFactory.java
+++ b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestBeiderMorseFilterFactory.java
@@ -62,13 +62,11 @@ public class TestBeiderMorseFilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new BeiderMorseFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDaitchMokotoffSoundexFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDaitchMokotoffSoundexFilterFactory.java b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDaitchMokotoffSoundexFilterFactory.java
index b73deb3..bdac2ad 100644
--- a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDaitchMokotoffSoundexFilterFactory.java
+++ b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDaitchMokotoffSoundexFilterFactory.java
@@ -53,13 +53,11 @@ public class TestDaitchMokotoffSoundexFilterFactory extends BaseTokenStreamTestC
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new DaitchMokotoffSoundexFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDoubleMetaphoneFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDoubleMetaphoneFilterFactory.java b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDoubleMetaphoneFilterFactory.java
index 24c8e14..6f70742 100644
--- a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDoubleMetaphoneFilterFactory.java
+++ b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestDoubleMetaphoneFilterFactory.java
@@ -53,13 +53,11 @@ public class TestDoubleMetaphoneFilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new DoubleMetaphoneFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestPhoneticFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestPhoneticFilterFactory.java b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestPhoneticFilterFactory.java
index ff20b65..f205076 100644
--- a/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestPhoneticFilterFactory.java
+++ b/lucene/analysis/phonetic/src/test/org/apache/lucene/analysis/phonetic/TestPhoneticFilterFactory.java
@@ -64,36 +64,30 @@ public class TestPhoneticFilterFactory extends BaseTokenStreamTestCase {
* Case: Failures and Exceptions
*/
public void testMissingEncoder() throws IOException {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new PhoneticFilterFactory(new HashMap<String,String>());
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Configuration Error: missing parameter 'encoder'"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Configuration Error: missing parameter 'encoder'"));
}
public void testUnknownEncoder() throws IOException {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
Map<String,String> args = new HashMap<>();
args.put("encoder", "XXX");
PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
factory.inform(new ClasspathResourceLoader(factory.getClass()));
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Error loading encoder"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Error loading encoder"));
}
public void testUnknownEncoderReflection() throws IOException {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
Map<String,String> args = new HashMap<>();
args.put("encoder", "org.apache.commons.codec.language.NonExistence");
PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
factory.inform(new ClasspathResourceLoader(factory.getClass()));
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Error loading encoder"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Error loading encoder"));
}
/**
@@ -172,15 +166,13 @@ public class TestPhoneticFilterFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new PhoneticFilterFactory(new HashMap<String,String>() {{
put("encoder", "Metaphone");
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
static void assertAlgorithm(String algName, String inject, String input,
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/smartcn/src/test/org/apache/lucene/analysis/cn/smart/TestHMMChineseTokenizerFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/smartcn/src/test/org/apache/lucene/analysis/cn/smart/TestHMMChineseTokenizerFactory.java b/lucene/analysis/smartcn/src/test/org/apache/lucene/analysis/cn/smart/TestHMMChineseTokenizerFactory.java
index e16a4fe..c329486 100644
--- a/lucene/analysis/smartcn/src/test/org/apache/lucene/analysis/cn/smart/TestHMMChineseTokenizerFactory.java
+++ b/lucene/analysis/smartcn/src/test/org/apache/lucene/analysis/cn/smart/TestHMMChineseTokenizerFactory.java
@@ -44,13 +44,11 @@ public class TestHMMChineseTokenizerFactory extends BaseTokenStreamTestCase {
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new HMMChineseTokenizerFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java
index cfb022b..7199755 100644
--- a/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java
+++ b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java
@@ -40,13 +40,11 @@ public class TestStempelPolishStemFilterFactory extends BaseTokenStreamTestCase
/** Test that bogus arguments result in exception */
public void testBogusArguments() throws Exception {
- try {
+ IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
new StempelPolishStemFilterFactory(new HashMap<String,String>() {{
put("bogusArg", "bogusValue");
}});
- fail();
- } catch (IllegalArgumentException expected) {
- assertTrue(expected.getMessage().contains("Unknown parameters"));
- }
+ });
+ assertTrue(expected.getMessage().contains("Unknown parameters"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/ae/OverridingParamsAEProviderTest.java
----------------------------------------------------------------------
diff --git a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/ae/OverridingParamsAEProviderTest.java b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/ae/OverridingParamsAEProviderTest.java
index 8f7e111..923210b 100644
--- a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/ae/OverridingParamsAEProviderTest.java
+++ b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/ae/OverridingParamsAEProviderTest.java
@@ -17,6 +17,7 @@
package org.apache.lucene.analysis.uima.ae;
+import org.apache.lucene.util.LuceneTestCase;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.resource.ResourceInitializationException;
import org.junit.Test;
@@ -24,24 +25,17 @@ import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
/**
* TestCase for {@link OverridingParamsAEProvider}
*/
-public class OverridingParamsAEProviderTest {
+public class OverridingParamsAEProviderTest extends LuceneTestCase {
@Test
public void testNullMapInitialization() throws Exception {
- try {
+ expectThrows(ResourceInitializationException.class, () -> {
AEProvider aeProvider = new OverridingParamsAEProvider("/uima/TestEntityAnnotatorAE.xml", null);
aeProvider.getAE();
- fail("should fail due to null Map passed");
- } catch (ResourceInitializationException e) {
- // everything ok
- }
+ });
}
@Test
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java
----------------------------------------------------------------------
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java
index 37f8c21..87625d2 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestMaxPositionInOldIndex.java
@@ -81,13 +81,10 @@ public class BuildMaxPositionIndex {
TestUtil.unzip(resource, path);
BaseDirectoryWrapper dir = newFSDirectory(path);
dir.setCheckIndexOnClose(false);
- try {
+ RuntimeException expected = expectThrows(RuntimeException.class, () -> {
TestUtil.checkIndex(dir, false, true);
- fail("corruption was not detected");
- } catch (RuntimeException re) {
- // expected
- assertTrue(re.getMessage().contains("pos 2147483647 > IndexWriter.MAX_POSITION=2147483519"));
- }
+ });
+ assertTrue(expected.getMessage().contains("pos 2147483647 > IndexWriter.MAX_POSITION=2147483519"));
// Also confirm merging detects this:
IndexWriterConfig iwc = newIndexWriterConfig();
@@ -95,14 +92,13 @@ public class BuildMaxPositionIndex {
iwc.setMergePolicy(newLogMergePolicy());
IndexWriter w = new IndexWriter(dir, iwc);
w.addDocument(new Document());
- try {
+ CorruptIndexException expectedCorruption = expectThrows(CorruptIndexException.class, () -> {
w.forceMerge(1);
- } catch (CorruptIndexException cie) {
- assertEquals(cie.getMessage(), new CorruptIndexException(cie.getOriginalMessage(), cie.getResourceDescription()).getMessage());
- // SerialMergeScheduler
- assertTrue("got message " + cie.getMessage(),
- cie.getMessage().contains("position=2147483647 is too large (> IndexWriter.MAX_POSITION=2147483519), field=\"foo\" doc=0 (resource=PerFieldPostings(segment=_0 formats=1)"));
- }
+ });
+ assertEquals(expectedCorruption.getMessage(), new CorruptIndexException(expectedCorruption.getOriginalMessage(), expectedCorruption.getResourceDescription()).getMessage());
+ // SerialMergeScheduler
+ assertTrue("got message " + expectedCorruption.getMessage(),
+ expectedCorruption.getMessage().contains("position=2147483647 is too large (> IndexWriter.MAX_POSITION=2147483519), field=\"foo\" doc=0 (resource=PerFieldPostings(segment=_0 formats=1)"));
w.close();
dir.close();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
----------------------------------------------------------------------
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
index b9b1957..5dbf660 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
@@ -258,13 +258,9 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
CountingHighlighterTestTask.numHighlightedResults = 0;
CountingHighlighterTestTask.numDocsRetrieved = 0;
// 3. execute the algorithm (required in every "logic" test)
- try {
- Benchmark benchmark = execBenchmark(algLines);
- assertTrue("CountingHighlighterTest should have thrown an exception", false);
- assertNotNull(benchmark); // (avoid compile warning on unused variable)
- } catch (Exception e) {
- assertTrue(true);
- }
+ expectThrows(Exception.class, () -> {
+ execBenchmark(algLines);
+ });
}
/**
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java
----------------------------------------------------------------------
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java
index c6fa60f..9e76700 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java
@@ -56,12 +56,9 @@ public class EnwikiContentSourceTest extends LuceneTestCase {
}
private void assertNoMoreDataException(EnwikiContentSource stdm) throws Exception {
- try {
+ expectThrows(NoMoreDataException.class, () -> {
stdm.getNextDocData(null);
- fail("Expecting NoMoreDataException");
- } catch (NoMoreDataException e) {
- // expected
- }
+ });
}
private final String PAGE1 =
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java
----------------------------------------------------------------------
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java
index 99236cd..197ce4a 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java
@@ -214,12 +214,9 @@ public class LineDocSourceTest extends BenchmarkTestCase {
writer.write(testCases[i]);
writer.newLine();
writer.close();
- try {
+ expectThrows(Exception.class, () -> {
doIndexAndSearchTest(file, null, null);
- fail("Some exception should have been thrown for: [" + testCases[i] + "]");
- } catch (Exception e) {
- // expected.
- }
+ });
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
----------------------------------------------------------------------
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
index bb87fdd..1257422 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
@@ -75,13 +75,9 @@ public class TrecContentSourceTest extends LuceneTestCase {
}
private void assertNoMoreDataException(StringableTrecSource stdm) throws Exception {
- boolean thrown = false;
- try {
+ expectThrows(NoMoreDataException.class, () -> {
stdm.getNextDocData(null);
- } catch (NoMoreDataException e) {
- thrown = true;
- }
- assertTrue("Expecting NoMoreDataException", thrown);
+ });
}
public void testOneDocument() throws Exception {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
----------------------------------------------------------------------
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
index 059650d..4e9972d 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
@@ -25,12 +25,9 @@ public class AltPackageTaskTest extends BenchmarkTestCase {
/** Benchmark should fail loading the algorithm when alt is not specified */
public void testWithoutAlt() throws Exception {
- try {
+ expectThrows(Exception.class, () -> {
execBenchmark(altAlg(false));
- assertFalse("Should have failed to run the algorithm",true);
- } catch(Exception e) {
- // expected exception, do nothing
- }
+ });
}
/** Benchmark should be able to load the algorithm when alt is specified */
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/codecs/src/test/org/apache/lucene/codecs/autoprefix/TestAutoPrefixTerms.java
----------------------------------------------------------------------
diff --git a/lucene/codecs/src/test/org/apache/lucene/codecs/autoprefix/TestAutoPrefixTerms.java b/lucene/codecs/src/test/org/apache/lucene/codecs/autoprefix/TestAutoPrefixTerms.java
index 726c3f0..316fc9a 100644
--- a/lucene/codecs/src/test/org/apache/lucene/codecs/autoprefix/TestAutoPrefixTerms.java
+++ b/lucene/codecs/src/test/org/apache/lucene/codecs/autoprefix/TestAutoPrefixTerms.java
@@ -648,11 +648,10 @@ public class TestAutoPrefixTerms extends LuceneTestCase {
Document doc = new Document();
doc.add(new Field("foo", "bar bar", ft));
w.addDocument(doc);
- try {
+ IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
w.commit();
- } catch (IllegalStateException ise) {
- assertEquals("ranges can only be indexed with IndexOptions.DOCS (field: foo)", ise.getMessage());
- }
+ });
+ assertEquals("ranges can only be indexed with IndexOptions.DOCS (field: foo)", expected.getMessage());
w.close();
dir.close();
}
@@ -668,11 +667,11 @@ public class TestAutoPrefixTerms extends LuceneTestCase {
Document doc = new Document();
doc.add(new Field("foo", "bar bar", ft));
w.addDocument(doc);
- try {
+ IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
w.commit();
- } catch (IllegalStateException ise) {
- assertEquals("ranges can only be indexed with IndexOptions.DOCS (field: foo)", ise.getMessage());
- }
+ });
+ assertEquals("ranges can only be indexed with IndexOptions.DOCS (field: foo)", expected.getMessage());
+
w.close();
dir.close();
}
@@ -688,11 +687,11 @@ public class TestAutoPrefixTerms extends LuceneTestCase {
Document doc = new Document();
doc.add(new Field("foo", "bar bar", ft));
w.addDocument(doc);
- try {
+ IllegalStateException expected = expectThrows(IllegalStateException.class, () -> {
w.commit();
- } catch (IllegalStateException ise) {
- assertEquals("ranges can only be indexed with IndexOptions.DOCS (field: foo)", ise.getMessage());
- }
+ });
+ assertEquals("ranges can only be indexed with IndexOptions.DOCS (field: foo)", 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/analysis/TestCachingTokenFilter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java b/lucene/core/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java
index db3f8e0..39248ee 100644
--- a/lucene/core/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java
+++ b/lucene/core/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java
@@ -121,12 +121,10 @@ public class TestCachingTokenFilter extends BaseTokenStreamTestCase {
final TokenStream input = analyzer.tokenStream("field", "abc");
CachingTokenFilter buffer = new CachingTokenFilter(input);
buffer.reset();//ok
- try {
+ IllegalStateException e = expectThrows(IllegalStateException.class, () -> {
buffer.reset();//bad (this used to work which we don't want)
- fail("didn't get expected exception");
- } catch (IllegalStateException e) {
- assertEquals("double reset()", e.getMessage());
- }
+ });
+ assertEquals("double reset()", e.getMessage());
}
private void checkTokens(TokenStream stream) throws IOException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java b/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
index 837b38a..dfaa20e 100644
--- a/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
+++ b/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
@@ -81,19 +81,13 @@ public class TestNumericTokenStream extends BaseTokenStreamTestCase {
public void testNotInitialized() throws Exception {
final LegacyNumericTokenStream stream=new LegacyNumericTokenStream();
- try {
+ expectThrows(IllegalStateException.class, () -> {
stream.reset();
- fail("reset() should not succeed.");
- } catch (IllegalStateException e) {
- // pass
- }
+ });
- try {
+ expectThrows(IllegalStateException.class, () -> {
stream.incrementToken();
- fail("incrementToken() should not succeed.");
- } catch (IllegalStateException e) {
- // pass
- }
+ });
stream.close();
}
@@ -103,18 +97,15 @@ public class TestNumericTokenStream extends BaseTokenStreamTestCase {
public void testCTA() throws Exception {
final LegacyNumericTokenStream stream=new LegacyNumericTokenStream();
- try {
+ IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
stream.addAttribute(CharTermAttribute.class);
- fail("Succeeded to add CharTermAttribute.");
- } catch (IllegalArgumentException iae) {
- assertTrue(iae.getMessage().startsWith("LegacyNumericTokenStream does not support"));
- }
- try {
+ });
+ assertTrue(e.getMessage().startsWith("LegacyNumericTokenStream does not support"));
+
+ e = expectThrows(IllegalArgumentException.class, () -> {
stream.addAttribute(TestAttribute.class);
- fail("Succeeded to add TestAttribute.");
- } catch (IllegalArgumentException iae) {
- assertTrue(iae.getMessage().startsWith("LegacyNumericTokenStream does not support"));
- }
+ });
+ assertTrue(e.getMessage().startsWith("LegacyNumericTokenStream does not support"));
stream.close();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java b/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
index e02dd02..81dd576 100644
--- a/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
+++ b/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
@@ -191,17 +191,13 @@ public class TestCharTermAttributeImpl extends LuceneTestCase {
t.append((CharSequence) t2, 1, 2);
assertEquals("4teste", t.toString());
- try {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
t.append((CharSequence) t2, 1, 5);
- fail("Should throw IndexOutOfBoundsException");
- } catch(IndexOutOfBoundsException iobe) {
- }
-
- try {
+ });
+
+ expectThrows(IndexOutOfBoundsException.class, () -> {
t.append((CharSequence) t2, 1, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch(IndexOutOfBoundsException iobe) {
- }
+ });
t.append((CharSequence) null);
assertEquals("4testenull", t.toString());
@@ -259,29 +255,21 @@ public class TestCharTermAttributeImpl extends LuceneTestCase {
t.append("test");
assertEquals("test", t.toString());
- try {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
t.charAt(-1);
- fail("Should throw IndexOutOfBoundsException");
- } catch(IndexOutOfBoundsException iobe) {
- }
+ });
- try {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
t.charAt(4);
- fail("Should throw IndexOutOfBoundsException");
- } catch(IndexOutOfBoundsException iobe) {
- }
+ });
- try {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
t.subSequence(0, 5);
- fail("Should throw IndexOutOfBoundsException");
- } catch(IndexOutOfBoundsException iobe) {
- }
+ });
- try {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
t.subSequence(5, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch(IndexOutOfBoundsException iobe) {
- }
+ });
}
public static <T extends AttributeImpl> T assertCloneIsEqual(T att) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java
index 6acd053..1a2ab62 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat.java
@@ -66,12 +66,9 @@ public class TestBlockPostingsFormat extends BasePostingsFormatTestCase {
}
private void shouldFail(int minItemsInBlock, int maxItemsInBlock) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
new Lucene50PostingsFormat(minItemsInBlock, maxItemsInBlock);
- fail("did not hit exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
+ });
}
public void testInvalidBlockSizes() throws Exception {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java
index 1fe84aa..59e4814 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java
@@ -70,18 +70,12 @@ public class TestLucene50StoredFieldsFormatHighCompression extends BaseStoredFie
}
public void testInvalidOptions() throws Exception {
- try {
+ expectThrows(NullPointerException.class, () -> {
new Lucene60Codec(null);
- fail("didn't hit exception");
- } catch (NullPointerException expected) {
- // expected
- }
+ });
- try {
+ expectThrows(NullPointerException.class, () -> {
new Lucene50StoredFieldsFormat(null);
- fail("didn't hit exception");
- } catch (NullPointerException expected) {
- // expected
- }
+ });
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java b/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java
index ed99ff0..fc1aaaf 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java
@@ -35,19 +35,17 @@ public class TestDateTools extends LuceneTestCase {
d = DateTools.stringToDate("20040705091055990");
assertEquals("2004-07-05 09:10:55:990", isoFormat(d));
- try {
- d = DateTools.stringToDate("97"); // no date
- fail();
- } catch(ParseException e) { /* expected exception */ }
- try {
- d = DateTools.stringToDate("200401011235009999"); // no date
- fail();
- } catch(ParseException e) { /* expected exception */ }
- try {
- d = DateTools.stringToDate("aaaa"); // no date
- fail();
- } catch(ParseException e) { /* expected exception */ }
+ expectThrows(ParseException.class, () -> {
+ DateTools.stringToDate("97"); // no date
+ });
+
+ expectThrows(ParseException.class, () -> {
+ DateTools.stringToDate("200401011235009999"); // no date
+ });
+ expectThrows(ParseException.class, () -> {
+ DateTools.stringToDate("aaaa"); // no date
+ });
}
public void testStringtoTime() throws ParseException {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
index 41e1f62..bd873ec 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
@@ -135,12 +135,9 @@ public class TestDocument extends LuceneTestCase {
ft.setStored(true);
new Field("name", "value", ft); // okay
new StringField("name", "value", Field.Store.NO); // okay
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
new Field("name", "value", new FieldType());
- fail();
- } catch (IllegalArgumentException e) {
- // expected exception
- }
+ });
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
@@ -150,12 +147,9 @@ public class TestDocument extends LuceneTestCase {
ft2.setStored(true);
ft2.setStoreTermVectors(true);
doc.add(new Field("name", "value", ft2));
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
- fail();
- } catch (IllegalArgumentException e) {
- // expected exception
- }
+ });
w.close();
dir.close();
}
@@ -167,25 +161,18 @@ public class TestDocument extends LuceneTestCase {
assertEquals(0, doc.getFields().size());
}
+ /** test that Document.getFields() actually returns an immutable list */
public void testGetFieldsImmutable() {
Document doc = makeDocumentWithFields();
assertEquals(10, doc.getFields().size());
List<IndexableField> fields = doc.getFields();
- try {
- fields.add( new StringField("name", "value", Field.Store.NO) );
- fail("Document.getFields() should return immutable List");
- }
- catch (UnsupportedOperationException e) {
- // OK
- }
+ expectThrows(UnsupportedOperationException.class, () -> {
+ fields.add(new StringField("name", "value", Field.Store.NO));
+ });
- try {
+ expectThrows(UnsupportedOperationException.class, () -> {
fields.clear();
- fail("Document.getFields() should return immutable List");
- }
- catch (UnsupportedOperationException e) {
- // OK
- }
+ });
}
/**
@@ -344,14 +331,11 @@ public class TestDocument extends LuceneTestCase {
// LUCENE-3616
public void testInvalidFields() {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
Tokenizer tok = new MockTokenizer();
tok.setReader(new StringReader(""));
new Field("foo", tok, StringField.TYPE_STORED);
- fail("did not hit expected exc");
- } catch (IllegalArgumentException iae) {
- // expected
- }
+ });
}
public void testNumericFieldAsString() throws Exception {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/document/TestField.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestField.java b/lucene/core/src/test/org/apache/lucene/document/TestField.java
index 85336bc..3ac7990 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestField.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestField.java
@@ -439,111 +439,75 @@ public class TestField extends LuceneTestCase {
}
private void trySetByteValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setByteValue((byte) 10);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetBytesValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setBytesValue(new byte[] { 5, 5 });
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetBytesRefValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setBytesValue(new BytesRef("bogus"));
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetDoubleValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setDoubleValue(Double.MAX_VALUE);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetIntValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setIntValue(Integer.MAX_VALUE);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetLongValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setLongValue(Long.MAX_VALUE);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetFloatValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setFloatValue(Float.MAX_VALUE);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetReaderValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setReaderValue(new StringReader("BOO!"));
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetShortValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setShortValue(Short.MAX_VALUE);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetStringValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setStringValue("BOO!");
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetTokenStreamValue(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setTokenStream(new CannedTokenStream(new Token("foo", 0, 3)));
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
private void trySetBoost(Field f) {
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
f.setBoost(5.0f);
- fail();
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
index 2a2bfd2..d1148ef 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java
@@ -305,16 +305,13 @@ public class TestAddIndexes extends LuceneTestCase {
addDocs(writer, 100);
writer.close();
- writer = newWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
- try {
- // cannot add self
- writer.addIndexes(aux, dir);
- assertTrue(false);
- }
- catch (IllegalArgumentException e) {
- assertEquals(100, writer.maxDoc());
- }
- writer.close();
+ // cannot add self
+ IndexWriter writer2 = newWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
+ expectThrows(IllegalArgumentException.class, () -> {
+ writer2.addIndexes(aux, dir);
+ });
+ assertEquals(100, writer2.maxDoc());
+ writer2.close();
// make sure the index is correct
verifyNumDocs(dir, 100);
@@ -1167,12 +1164,9 @@ public class TestAddIndexes extends LuceneTestCase {
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
conf.setCodec(TestUtil.alwaysPostingsFormat(new MemoryPostingsFormat()));
IndexWriter w = new IndexWriter(dir, conf);
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
w.addIndexes(toAdd);
- fail("no such codec");
- } catch (IllegalArgumentException ex) {
- // expected
- }
+ });
w.close();
IndexReader open = DirectoryReader.open(dir);
assertEquals(0, open.numDocs());
@@ -1180,12 +1174,9 @@ public class TestAddIndexes extends LuceneTestCase {
dir.close();
}
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
DirectoryReader.open(toAdd);
- fail("no such codec");
- } catch (IllegalArgumentException ex) {
- // expected
- }
+ });
toAdd.close();
}
@@ -1282,12 +1273,9 @@ public class TestAddIndexes extends LuceneTestCase {
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
RandomIndexWriter w2 = new RandomIndexWriter(random(), dest, iwc);
- try {
+ expectThrows(LockObtainFailedException.class, () -> {
w2.addIndexes(src);
- fail("did not hit expected exception");
- } catch (LockObtainFailedException lofe) {
- // expected
- }
+ });
w1.close();
w2.close();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestBinaryDocValuesUpdates.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBinaryDocValuesUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestBinaryDocValuesUpdates.java
index a8d3870..4025f58 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestBinaryDocValuesUpdates.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBinaryDocValuesUpdates.java
@@ -431,19 +431,13 @@ public class TestBinaryDocValuesUpdates extends LuceneTestCase {
writer.commit();
writer.addDocument(doc); // in-memory document
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
writer.updateBinaryDocValue(new Term("key", "doc"), "bdv", toBytes(17L));
- fail("should not have allowed creating new fields through update");
- } catch (IllegalArgumentException e) {
- // ok
- }
+ });
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
writer.updateBinaryDocValue(new Term("key", "doc"), "foo", toBytes(17L));
- fail("should not have allowed updating an existing field to binary-dv");
- } catch (IllegalArgumentException e) {
- // ok
- }
+ });
writer.close();
dir.close();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestCodecUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCodecUtil.java b/lucene/core/src/test/org/apache/lucene/index/TestCodecUtil.java
index 79fbdeb..9752ce3 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestCodecUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestCodecUtil.java
@@ -54,23 +54,17 @@ public class TestCodecUtil extends LuceneTestCase {
}
RAMFile file = new RAMFile();
IndexOutput output = new RAMOutputStream(file, true);
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
CodecUtil.writeHeader(output, tooLong.toString(), 5);
- fail("didn't get expected exception");
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
public void testWriteNonAsciiHeader() throws Exception {
RAMFile file = new RAMFile();
IndexOutput output = new RAMOutputStream(file, true);
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
CodecUtil.writeHeader(output, "\u1234", 5);
- fail("didn't get expected exception");
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
public void testReadHeaderWrongMagic() throws Exception {
@@ -80,12 +74,9 @@ public class TestCodecUtil extends LuceneTestCase {
output.close();
IndexInput input = new RAMInputStream("file", file);
- try {
+ expectThrows(CorruptIndexException.class, () -> {
CodecUtil.checkHeader(input, "bogus", 1, 1);
- fail("didn't get expected exception");
- } catch (CorruptIndexException expected) {
- // expected
- }
+ });
}
public void testChecksumEntireFile() throws Exception {
@@ -111,15 +102,13 @@ public class TestCodecUtil extends LuceneTestCase {
ChecksumIndexInput input = new BufferedChecksumIndexInput(new RAMInputStream("file", file));
Exception mine = new RuntimeException("fake exception");
- try {
+ RuntimeException expected = expectThrows(RuntimeException.class, () -> {
CodecUtil.checkFooter(input, mine);
- fail("didn't get expected exception");
- } catch (RuntimeException expected) {
- assertEquals("fake exception", expected.getMessage());
- Throwable suppressed[] = expected.getSuppressed();
- assertEquals(1, suppressed.length);
- assertTrue(suppressed[0].getMessage().contains("checksum passed"));
- }
+ });
+ assertEquals("fake exception", expected.getMessage());
+ Throwable suppressed[] = expected.getSuppressed();
+ assertEquals(1, suppressed.length);
+ assertTrue(suppressed[0].getMessage().contains("checksum passed"));
input.close();
}
@@ -135,15 +124,13 @@ public class TestCodecUtil extends LuceneTestCase {
CodecUtil.checkHeader(input, "FooBar", 5, 5);
assertEquals("this is the data", input.readString());
Exception mine = new RuntimeException("fake exception");
- try {
+ RuntimeException expected = expectThrows(RuntimeException.class, () -> {
CodecUtil.checkFooter(input, mine);
- fail("didn't get expected exception");
- } catch (RuntimeException expected) {
- assertEquals("fake exception", expected.getMessage());
- Throwable suppressed[] = expected.getSuppressed();
- assertEquals(1, suppressed.length);
- assertTrue(suppressed[0].getMessage().contains("checksum passed"));
- }
+ });
+ assertEquals("fake exception", expected.getMessage());
+ Throwable suppressed[] = expected.getSuppressed();
+ assertEquals(1, suppressed.length);
+ assertTrue(suppressed[0].getMessage().contains("checksum passed"));
input.close();
}
@@ -161,15 +148,13 @@ public class TestCodecUtil extends LuceneTestCase {
// bogusly read a byte too far (can happen)
input.readByte();
Exception mine = new RuntimeException("fake exception");
- try {
+ RuntimeException expected = expectThrows(RuntimeException.class, () -> {
CodecUtil.checkFooter(input, mine);
- fail("didn't get expected exception");
- } catch (RuntimeException expected) {
- assertEquals("fake exception", expected.getMessage());
- Throwable suppressed[] = expected.getSuppressed();
- assertEquals(1, suppressed.length);
- assertTrue(suppressed[0].getMessage().contains("checksum status indeterminate"));
- }
+ });
+ assertEquals("fake exception", expected.getMessage());
+ Throwable suppressed[] = expected.getSuppressed();
+ assertEquals(1, suppressed.length);
+ assertTrue(suppressed[0].getMessage().contains("checksum status indeterminate"));
input.close();
}
@@ -187,15 +172,13 @@ public class TestCodecUtil extends LuceneTestCase {
CodecUtil.checkHeader(input, "FooBar", 5, 5);
assertEquals("this is the data", input.readString());
Exception mine = new RuntimeException("fake exception");
- try {
+ RuntimeException expected = expectThrows(RuntimeException.class, () -> {
CodecUtil.checkFooter(input, mine);
- fail("didn't get expected exception");
- } catch (RuntimeException expected) {
- assertEquals("fake exception", expected.getMessage());
- Throwable suppressed[] = expected.getSuppressed();
- assertEquals(1, suppressed.length);
- assertTrue(suppressed[0].getMessage().contains("checksum failed"));
- }
+ });
+ assertEquals("fake exception", expected.getMessage());
+ Throwable suppressed[] = expected.getSuppressed();
+ assertEquals(1, suppressed.length);
+ assertTrue(suppressed[0].getMessage().contains("checksum failed"));
input.close();
}
@@ -219,12 +202,9 @@ public class TestCodecUtil extends LuceneTestCase {
}
RAMFile file = new RAMFile();
IndexOutput output = new RAMOutputStream(file, true);
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
CodecUtil.writeIndexHeader(output, "foobar", 5, StringHelper.randomId(), tooLong.toString());
- fail("didn't get expected exception");
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
public void testWriteVeryLongSuffix() throws Exception {
@@ -248,12 +228,9 @@ public class TestCodecUtil extends LuceneTestCase {
public void testWriteNonAsciiSuffix() throws Exception {
RAMFile file = new RAMFile();
IndexOutput output = new RAMOutputStream(file, true);
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
CodecUtil.writeIndexHeader(output, "foobar", 5, StringHelper.randomId(), "\u1234");
- fail("didn't get expected exception");
- } catch (IllegalArgumentException expected) {
- // expected
- }
+ });
}
public void testReadBogusCRC() throws Exception {
@@ -267,12 +244,9 @@ public class TestCodecUtil extends LuceneTestCase {
IndexInput input = new RAMInputStream("file", file);
// read 3 bogus values
for (int i = 0; i < 3; i++) {
- try {
+ expectThrows(CorruptIndexException.class, () -> {
CodecUtil.readCRC(input);
- fail("didn't get expected exception");
- } catch (CorruptIndexException expected) {
- // expected
- }
+ });
}
// good value
CodecUtil.readCRC(input);
@@ -311,28 +285,19 @@ public class TestCodecUtil extends LuceneTestCase {
};
fakeChecksum.set(-1L); // bad
- try {
+ expectThrows(IllegalStateException.class, () -> {
CodecUtil.writeCRC(fakeOutput);
- fail("didn't get expected exception");
- } catch (IllegalStateException expected) {
- // expected exception
- }
+ });
fakeChecksum.set(1L << 32); // bad
- try {
+ expectThrows(IllegalStateException.class, () -> {
CodecUtil.writeCRC(fakeOutput);
- fail("didn't get expected exception");
- } catch (IllegalStateException expected) {
- // expected exception
- }
+ });
fakeChecksum.set(-(1L << 32)); // bad
- try {
+ expectThrows(IllegalStateException.class, () -> {
CodecUtil.writeCRC(fakeOutput);
- fail("didn't get expected exception");
- } catch (IllegalStateException expected) {
- // expected exception
- }
+ });
fakeChecksum.set((1L << 32) - 1); // ok
CodecUtil.writeCRC(fakeOutput);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java b/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
index 4c1bada..5e885e3 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java
@@ -395,18 +395,12 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
public void testInvalidMaxMergeCountAndThreads() throws Exception {
ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler();
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
cms.setMaxMergesAndThreads(ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS, 3);
- fail("did not hit exception");
- } catch (IllegalArgumentException iae) {
- // good
- }
- try {
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
cms.setMaxMergesAndThreads(3, ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS);
- fail("did not hit exception");
- } catch (IllegalArgumentException iae) {
- // good
- }
+ });
}
public void testLiveMaxMergeCount() throws Exception {
@@ -605,19 +599,13 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
assertEquals(4, cms.getMaxMergeCount());
assertEquals(3, cms.getMaxThreadCount());
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
cms.setMaxMergesAndThreads(ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS, 4);
- fail("did not hit exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
+ });
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
cms.setMaxMergesAndThreads(4, ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS);
- fail("did not hit exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
+ });
cms.setMaxMergesAndThreads(ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS, ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS);
assertEquals(ConcurrentMergeScheduler.AUTO_DETECT_MERGES_AND_THREADS, cms.getMaxMergeCount());
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
index aebfb50..9fd20ab 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
@@ -72,13 +72,11 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
crashAfterCreateOutput.setCrashAfterCreateOutput("pending_segments_2");
indexWriter.addDocument(getDocument());
- try {
- // tries to write segments_2 but hits fake exc:
+ // tries to write segments_2 but hits fake exc:
+ expectThrows(CrashingException.class, () -> {
indexWriter.commit();
- fail("should have hit CrashingException");
- } catch (CrashingException e) {
- // expected
- }
+ });
+
// writes segments_3
indexWriter.close();
assertFalse(slowFileExists(realDirectory, "segments_2"));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
index f65b079..24b2c50 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
@@ -718,12 +718,9 @@ public class TestDirectoryReader extends LuceneTestCase {
public void testNoDir() throws Throwable {
Path tempDir = createTempDir("doesnotexist");
Directory dir = newFSDirectory(tempDir);
- try {
+ expectThrows(IndexNotFoundException.class, () -> {
DirectoryReader.open(dir);
- fail("did not hit expected exception");
- } catch (IndexNotFoundException nsde) {
- // expected
- }
+ });
dir.close();
}
@@ -955,12 +952,9 @@ public class TestDirectoryReader extends LuceneTestCase {
DirectoryReader r = writer.getReader();
writer.close();
r.document(0);
- try {
+ expectThrows(IllegalArgumentException.class, () -> {
r.document(1);
- fail("did not hit exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
+ });
r.close();
dir.close();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java
index 189ef20..6afa091 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java
@@ -672,13 +672,9 @@ public class TestDirectoryReaderReopen extends LuceneTestCase {
// Now reopen:
//System.out.println("TEST: now reopen");
- try {
- IndexReader r2 = DirectoryReader.openIfChanged(r);
- //System.out.println("got " + r2);
- fail("didn't hit exception");
- } catch (FakeIOException fio) {
- // expected
- }
+ expectThrows(FakeIOException.class, () -> {
+ DirectoryReader.openIfChanged(r);
+ });
IndexSearcher s = newSearcher(r);
assertEquals(1, s.search(new TermQuery(new Term("id", "id")), 1).totalHits);
@@ -726,12 +722,9 @@ public class TestDirectoryReaderReopen extends LuceneTestCase {
w.commit();
w.close();
- try {
+ expectThrows(IllegalStateException.class, () -> {
DirectoryReader.openIfChanged(r);
- fail("didn't hit expected exception");
- } catch (IllegalStateException ise) {
- // expected
- }
+ });
r.close();
w.close();
@@ -772,12 +765,9 @@ public class TestDirectoryReaderReopen extends LuceneTestCase {
w.commit();
w.close();
- try {
+ expectThrows(IllegalStateException.class, () -> {
DirectoryReader.openIfChanged(r);
- fail("didn't hit expected exception");
- } catch (IllegalStateException ise) {
- // expected
- }
+ });
r.close();
dir.close();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java b/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java
index 1e93478..17e0f2e 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java
@@ -76,14 +76,12 @@ public class TestDocInverterPerFieldErrorInfo extends LuceneTestCase {
writer = new IndexWriter(dir, c);
Document doc = new Document();
doc.add(newField("distinctiveFieldName", "aaa ", storedTextType));
- try {
+ expectThrows(BadNews.class, () -> {
writer.addDocument(doc);
- fail("Failed to fail.");
- } catch(BadNews badNews) {
- infoPrintStream.flush();
- String infoStream = new String(infoBytes.toByteArray(), IOUtils.UTF_8);
- assertTrue(infoStream.contains("distinctiveFieldName"));
- }
+ });
+ infoPrintStream.flush();
+ String infoStream = new String(infoBytes.toByteArray(), IOUtils.UTF_8);
+ assertTrue(infoStream.contains("distinctiveFieldName"));
writer.close();
dir.close();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/189e985b/lucene/core/src/test/org/apache/lucene/index/TestDocValues.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValues.java
index b8573cb..ad4d60c 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDocValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValues.java
@@ -69,30 +69,24 @@ public class TestDocValues extends LuceneTestCase {
LeafReader r = getOnlySegmentReader(dr);
// errors
- try {
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getBinary(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSorted(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedSet(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getDocsWithField(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
+ });
dr.close();
iw.close();
@@ -117,18 +111,15 @@ public class TestDocValues extends LuceneTestCase {
assertNotNull(DocValues.getDocsWithField(r, "foo"));
// errors
- try {
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getBinary(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSorted(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedSet(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
+ });
dr.close();
iw.close();
@@ -152,22 +143,18 @@ public class TestDocValues extends LuceneTestCase {
assertNotNull(DocValues.getDocsWithField(r, "foo"));
// errors
- try {
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSorted(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedSet(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
+ });
dr.close();
iw.close();
@@ -193,14 +180,12 @@ public class TestDocValues extends LuceneTestCase {
assertNotNull(DocValues.getDocsWithField(r, "foo"));
// errors
- try {
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
+ });
dr.close();
iw.close();
@@ -224,22 +209,18 @@ public class TestDocValues extends LuceneTestCase {
assertNotNull(DocValues.getDocsWithField(r, "foo"));
// errors
- try {
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getBinary(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSorted(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
+ });
dr.close();
iw.close();
@@ -263,22 +244,18 @@ public class TestDocValues extends LuceneTestCase {
assertNotNull(DocValues.getDocsWithField(r, "foo"));
// errors
- try {
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getBinary(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getNumeric(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSorted(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
- try {
+ });
+ expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedSet(r, "foo");
- fail();
- } catch (IllegalStateException expected) {}
+ });
dr.close();
iw.close();