lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccurr...@apache.org
Subject svn commit: r1326749 [1/2] - in /incubator/lucene.net/trunk: src/core/Index/ src/core/Store/ test/contrib/Analyzers/Ru/ test/contrib/FastVectorHighlighter/ test/contrib/SpellChecker/Test/ test/core/Analysis/ test/core/Document/ test/core/Index/ test/co...
Date Mon, 16 Apr 2012 19:11:51 GMT
Author: ccurrens
Date: Mon Apr 16 19:11:49 2012
New Revision: 1326749

URL: http://svn.apache.org/viewvc?rev=1326749&view=rev
Log:
[LUCENENET-435] - Changed code to use Assert.Throws<T> instead of Try..Catch and Assert.Fail

Modified:
    incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs
    incubator/lucene.net/trunk/src/core/Index/IndexWriter.cs
    incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs
    incubator/lucene.net/trunk/src/core/Store/FSDirectory.cs
    incubator/lucene.net/trunk/src/core/Store/Lock.cs
    incubator/lucene.net/trunk/test/contrib/Analyzers/Ru/TestRussianAnalyzer.cs
    incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/SimpleFragListBuilderTest.cs
    incubator/lucene.net/trunk/test/contrib/SpellChecker/Test/TestSpellChecker.cs
    incubator/lucene.net/trunk/test/core/Analysis/TestCharArraySet.cs
    incubator/lucene.net/trunk/test/core/Analysis/TestNumericTokenStream.cs
    incubator/lucene.net/trunk/test/core/Document/TestBinaryDocument.cs
    incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs
    incubator/lucene.net/trunk/test/core/Document/TestDocument.cs
    incubator/lucene.net/trunk/test/core/Index/TestCompoundFile.cs
    incubator/lucene.net/trunk/test/core/Index/TestDirectoryReader.cs
    incubator/lucene.net/trunk/test/core/Index/TestFieldsReader.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexReader.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexReaderClone.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexReaderCloneNorms.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexReaderReopen.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexWriter.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexWriterDelete.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexWriterExceptions.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexWriterMerging.cs
    incubator/lucene.net/trunk/test/core/Index/TestIndexWriterReader.cs
    incubator/lucene.net/trunk/test/core/Index/TestLazyBug.cs
    incubator/lucene.net/trunk/test/core/Index/TestMultiLevelSkipList.cs
    incubator/lucene.net/trunk/test/core/Index/TestParallelReader.cs
    incubator/lucene.net/trunk/test/core/Index/TestPayloads.cs
    incubator/lucene.net/trunk/test/core/Index/TestSnapshotDeletionPolicy.cs
    incubator/lucene.net/trunk/test/core/Index/TestTermVectorsReader.cs
    incubator/lucene.net/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs
    incubator/lucene.net/trunk/test/core/QueryParser/TestQueryParser.cs
    incubator/lucene.net/trunk/test/core/Search/CheckHits.cs
    incubator/lucene.net/trunk/test/core/Search/TestBooleanMinShouldMatch.cs
    incubator/lucene.net/trunk/test/core/Search/TestBooleanQuery.cs
    incubator/lucene.net/trunk/test/core/Search/TestFuzzyQuery.cs
    incubator/lucene.net/trunk/test/core/Search/TestMultiPhraseQuery.cs
    incubator/lucene.net/trunk/test/core/Store/TestBufferedIndexInput.cs
    incubator/lucene.net/trunk/test/core/Store/TestDirectory.cs
    incubator/lucene.net/trunk/test/core/Store/TestLock.cs
    incubator/lucene.net/trunk/test/core/Store/TestLockFactory.cs
    incubator/lucene.net/trunk/test/core/Support/TestIDisposable.cs
    incubator/lucene.net/trunk/test/core/Support/TestWeakHashTable.cs
    incubator/lucene.net/trunk/test/core/Util/TestAttributeSource.cs
    incubator/lucene.net/trunk/test/core/Util/TestNumericUtils.cs
    incubator/lucene.net/trunk/test/core/Util/TestOpenBitSet.cs
    incubator/lucene.net/trunk/test/core/Util/TestSortedVIntList.cs
    incubator/lucene.net/trunk/test/core/Util/TestStringIntern.cs

Modified: incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs Mon Apr 16 19:11:49 2012
@@ -88,15 +88,22 @@ namespace Lucene.Net.Index
 						input.SetModifiedUTF8StringsMode();
 						byNumber.Clear();
 						byName.Clear();
+
+					    bool rethrow = false;
 						try
 						{
 							Read(input, name);
 						}
 						catch (System.Exception t)
-						{
-                            // Ignore any new exception & throw original IOE
-                            throw ioe;
+                        {
+                            // Ignore any new exception & set to throw original IOE
+						    rethrow = true;
 						}
+                        if(rethrow)
+                        {
+                            // Preserve stack trace
+                            throw;
+                        }
 					}
 					else
 					{

Modified: incubator/lucene.net/trunk/src/core/Index/IndexWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/IndexWriter.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/IndexWriter.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/IndexWriter.cs Mon Apr 16 19:11:49 2012
@@ -4630,17 +4630,18 @@ namespace Lucene.Net.Index
 				// rollbackTransaction code in addIndexes* is
 				// executed.
 				if (merge.isExternal)
-					throw (MergePolicy.MergeAbortedException) t;
+					throw t;
 			}
-			else if (t is System.IO.IOException)
-				throw (System.IO.IOException) t;
-			else if (t is System.SystemException)
-				throw (System.SystemException) t;
-			else if (t is System.ApplicationException)
-				throw (System.ApplicationException) t;
-			// Should not get here
-			else
-				throw new System.SystemException(null, t);
+            else if (t is System.IO.IOException || t is System.SystemException || t is System.ApplicationException)
+            {
+                throw t;
+            }
+            else
+            {
+                // Should not get here
+                System.Diagnostics.Debug.Fail("Exception is not expected type!");
+                throw new System.SystemException(null, t);
+            }
 		}
 		
 		public void Merge_ForNUnit(MergePolicy.OneMerge merge)

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs Mon Apr 16 19:11:49 2012
@@ -744,10 +744,8 @@ namespace Lucene.Net.Index
 							// got.
 							throw exc;
 						}
-						else
-						{
-							retry = true;
-						}
+
+						retry = true;
 					}
 					else if (0 == method)
 					{

Modified: incubator/lucene.net/trunk/src/core/Store/FSDirectory.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/FSDirectory.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/FSDirectory.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/FSDirectory.cs Mon Apr 16 19:11:49 2012
@@ -392,7 +392,7 @@ namespace Lucene.Net.Store
 					try
 					{
 						// Pause 5 msec
-						System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 5));
+						System.Threading.Thread.Sleep(5);
 					}
 					catch (System.Threading.ThreadInterruptedException ie)
 					{
@@ -405,7 +405,8 @@ namespace Lucene.Net.Store
 					}
 				}
 			}
-			if (!success)
+
+			if (!success && exc != null)
 			// Throw original exception
 				throw exc;
 		}

Modified: incubator/lucene.net/trunk/src/core/Store/Lock.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Store/Lock.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Store/Lock.cs (original)
+++ incubator/lucene.net/trunk/src/core/Store/Lock.cs Mon Apr 16 19:11:49 2012
@@ -91,20 +91,14 @@ namespace Lucene.Net.Store
 					{
 						reason += (": " + failureReason);
 					}
-                    LockObtainFailedException e;
-                    if (failureReason != null)
-                    {
-                        e = new LockObtainFailedException(reason, failureReason);
-                    }
-                    else
-                    {
-                        e = new LockObtainFailedException(reason);
-                    }
+				    var e = failureReason != null
+				                ? new LockObtainFailedException(reason, failureReason)
+				                : new LockObtainFailedException(reason);
                     throw e;
 				}
 				try
 				{
-					System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * LOCK_POLL_INTERVAL));
+					System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(LOCK_POLL_INTERVAL));
 				}
 				catch (System.Threading.ThreadInterruptedException e)
 				{

Modified: incubator/lucene.net/trunk/test/contrib/Analyzers/Ru/TestRussianAnalyzer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Analyzers/Ru/TestRussianAnalyzer.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Analyzers/Ru/TestRussianAnalyzer.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Analyzers/Ru/TestRussianAnalyzer.cs Mon Apr 16 19:11:49 2012
@@ -84,6 +84,7 @@ namespace Lucene.Net.Analyzers.Ru
             TokenStream stream = ra.TokenStream("", reader);
 
             ITermAttribute termText = stream.GetAttribute<ITermAttribute>();
+            
             try
             {
                 Assert.True(stream.IncrementToken());

Modified: incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/SimpleFragListBuilderTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/SimpleFragListBuilderTest.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/SimpleFragListBuilderTest.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/FastVectorHighlighter/SimpleFragListBuilderTest.cs Mon Apr 16 19:11:49 2012
@@ -41,15 +41,10 @@ namespace Lucene.Net.Search.Vectorhighli
         [Test]
         public void TestTooSmallFragSize()
         {
-            try
-            {
-                SimpleFragListBuilder sflb = new SimpleFragListBuilder();
-                sflb.CreateFieldFragList(fpl("a", "b c d"), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE - 1);
-                Assert.Fail("IllegalArgumentException must be thrown");
-            }
-            catch (ArgumentException)
-            {
-            }
+            SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+            Assert.Throws<ArgumentException>(
+                () => sflb.CreateFieldFragList(fpl("a", "b c d"), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE - 1),
+                "ArgumentException must be thrown");
         }
 
         [Test]

Modified: incubator/lucene.net/trunk/test/contrib/SpellChecker/Test/TestSpellChecker.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/SpellChecker/Test/TestSpellChecker.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/SpellChecker/Test/TestSpellChecker.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/SpellChecker/Test/TestSpellChecker.cs Mon Apr 16 19:11:49 2012
@@ -232,68 +232,32 @@ namespace SpellChecker.Net.Test.Search.S
             var r = IndexReader.Open(userindex, true);
             spellChecker.ClearIndex();
             const string field = "field1";
-            
+
             Addwords(r, "field1");
             int num_field1 = this.Numdoc();
-            
+
             Addwords(r, "field2");
             int num_field2 = this.Numdoc();
-            
+
             Assert.AreEqual(num_field2, num_field1 + 1);
-            
+
             CheckCommonSuggestions(r);
             AssertLastSearcherOpen(4);
             spellChecker.Close();
             AssertSearchersClosed();
-            
-            try
-            {
-                spellChecker.Close();
-                Assert.Fail("spellchecker was already closed");
-            }
-            catch (AlreadyClosedException e)
-            {
-                // expected
-            }
-            try
-            {
-                CheckCommonSuggestions(r);
-                Assert.Fail("spellchecker was already closed");
-            }
-            catch (AlreadyClosedException e)
-            {
-                // expected
-            }
 
-            try
-            {
-                spellChecker.ClearIndex();
-                Assert.Fail("spellchecker was already closed");
-            }
-            catch (AlreadyClosedException e)
-            {
-                // expected
-            }
+            Assert.Throws<AlreadyClosedException>(() => spellChecker.Close(), "spellchecker was already closed");
 
-            try
-            {
-                spellChecker.IndexDictionary(new LuceneDictionary(r, field));
-                Assert.Fail("spellchecker was already closed");
-            }
-            catch (AlreadyClosedException e)
-            {
-                // expected
-            }
+            Assert.Throws<AlreadyClosedException>(() => CheckCommonSuggestions(r), "spellchecker was already closed");
+
+            Assert.Throws<AlreadyClosedException>(() => spellChecker.ClearIndex(), "spellchecker was already closed");
+
+            Assert.Throws<AlreadyClosedException>(() => spellChecker.IndexDictionary(new LuceneDictionary(r, field)),
+                                                  "spellchecker was already closed");
+
+            Assert.Throws<AlreadyClosedException>(() => spellChecker.SetSpellIndex(spellindex),
+                                                  "spellchecker was already closed");
 
-            try
-            {
-                spellChecker.SetSpellIndex(spellindex);
-                Assert.Fail("spellchecker was already closed");
-            }
-            catch (AlreadyClosedException e)
-            {
-                // expected
-            }
             Assert.AreEqual(4, searchers.Count);
             AssertSearchersClosed();
         }

Modified: incubator/lucene.net/trunk/test/core/Analysis/TestCharArraySet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Analysis/TestCharArraySet.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Analysis/TestCharArraySet.cs (original)
+++ incubator/lucene.net/trunk/test/core/Analysis/TestCharArraySet.cs Mon Apr 16 19:11:49 2012
@@ -75,127 +75,59 @@ namespace Lucene.Net.Analysis
         [Test]
 		public virtual void  TestClear()
 		{
-			CharArraySet set_Renamed = new CharArraySet(10, true);
-			for (int i = 0; i < TEST_STOP_WORDS.Length; i++) { set_Renamed.Add(TEST_STOP_WORDS[i]); }
-			Assert.AreEqual(TEST_STOP_WORDS.Length, set_Renamed.Count, "Not all words added");
-			try
-			{
-				set_Renamed.Clear();
-				Assert.Fail("remove is not supported");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.AreEqual(TEST_STOP_WORDS.Length, set_Renamed.Count, "Not all words added");
-			}
+			var set = new CharArraySet(10, true);
+			for (int i = 0; i < TEST_STOP_WORDS.Length; i++) { set.Add(TEST_STOP_WORDS[i]); }
+			Assert.AreEqual(TEST_STOP_WORDS.Length, set.Count, "Not all words added");
+
+            Assert.Throws<NotSupportedException>(set.Clear, "remove is not supported");
+			Assert.AreEqual(TEST_STOP_WORDS.Length, set.Count, "Not all words added");
 		}
 		
         [Test]
 		public virtual void  TestModifyOnUnmodifiable()
 		{
             //System.Diagnostics.Debugger.Break();
-            CharArraySet set_Renamed = new CharArraySet(10, true);
-			set_Renamed.AddAll(TEST_STOP_WORDS);
-			int size = set_Renamed.Count;
-			set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
-			Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
+            CharArraySet set = new CharArraySet(10, true);
+			set.AddAll(TEST_STOP_WORDS);
+			int size = set.Count;
+			set = CharArraySet.UnmodifiableSet(set);
+
+			Assert.AreEqual(size, set.Count, "Set size changed due to UnmodifiableSet call");
 			System.String NOT_IN_SET = "SirGallahad";
-			Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String already exists in set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String already exists in set");
 			
-			try
-			{
-				set_Renamed.Add(NOT_IN_SET.ToCharArray());
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
+            Assert.Throws<NotSupportedException>(() => set.Add(NOT_IN_SET.ToCharArray()), "Modified unmodifiable set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
+			
+            Assert.Throws<NotSupportedException>(() => set.Add(NOT_IN_SET), "Modified unmodifiable set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
+			
+            Assert.Throws<NotSupportedException>(() => set.Add(new System.Text.StringBuilder(NOT_IN_SET)), "Modified unmodifiable set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
+			
+            Assert.Throws<NotSupportedException>(() => set.Clear(), "Modified unmodifiable set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Changed unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
+
+            Assert.Throws<NotSupportedException>(() => set.Add((object)NOT_IN_SET), "Modified unmodifiable set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
+
+            Assert.Throws<NotSupportedException>(() => set.RemoveAll(new List<string>(TEST_STOP_WORDS)), "Modified unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
 			
-			try
-			{
-				set_Renamed.Add(NOT_IN_SET);
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
+            Assert.Throws<NotSupportedException>(() => set.RetainAll(new List<string>(new[] { NOT_IN_SET })), "Modified unmodifiable set");
+			Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
 			
-			try
-			{
-				set_Renamed.Add(new System.Text.StringBuilder(NOT_IN_SET));
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
-			
-			try
-			{
-				set_Renamed.Clear();
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Changed unmodifiable set");
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
-			try
-			{
-				set_Renamed.Add((System.Object) NOT_IN_SET);
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
-			try
-			{
-				set_Renamed.RemoveAll(new List<string>(TEST_STOP_WORDS));
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
-			
-			try
-			{
-                set_Renamed.RetainAll(new List<string>(new [] { NOT_IN_SET }));
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
-			}
-			
-			try
-			{
-                set_Renamed.AddAll(new List<string>(new [] { NOT_IN_SET }));
-				Assert.Fail("Modified unmodifiable set");
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected
-				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
-			}
+            Assert.Throws<NotSupportedException>(() => set.AddAll(new List<string>(new[] { NOT_IN_SET })), "Modified unmodifiable set");
+			Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
 			
 			for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
 			{
-				Assert.IsTrue(set_Renamed.Contains(TEST_STOP_WORDS[i]));
+				Assert.IsTrue(set.Contains(TEST_STOP_WORDS[i]));
 			}
 		}
 		
@@ -208,15 +140,7 @@ namespace Lucene.Net.Analysis
 			set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
 			Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
 			
-			try
-			{
-				CharArraySet.UnmodifiableSet(null);
-				Assert.Fail("can not make null unmodifiable");
-			}
-            catch (System.ArgumentNullException e)
-			{
-				// expected
-			}
+			Assert.Throws<ArgumentNullException>(() => CharArraySet.UnmodifiableSet(null), "can not make null unmodifiable");
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/test/core/Analysis/TestNumericTokenStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Analysis/TestNumericTokenStream.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Analysis/TestNumericTokenStream.cs (original)
+++ incubator/lucene.net/trunk/test/core/Analysis/TestNumericTokenStream.cs Mon Apr 16 19:11:49 2012
@@ -62,31 +62,14 @@ namespace Lucene.Net.Analysis
 			}
 			Assert.IsFalse(stream.IncrementToken(), "No more tokens available");
 		}
-		
+
         [Test]
-		public virtual void  TestNotInitialized()
-		{
-			NumericTokenStream stream = new NumericTokenStream();
-			
-			try
-			{
-				stream.Reset();
-				Assert.Fail("reset() should not succeed.");
-			}
-			catch (System.SystemException e)
-			{
-				// pass
-			}
-			
-			try
-			{
-				stream.IncrementToken();
-				Assert.Fail("incrementToken() should not succeed.");
-			}
-			catch (System.SystemException e)
-			{
-				// pass
-			}
-		}
+        public virtual void TestNotInitialized()
+        {
+            NumericTokenStream stream = new NumericTokenStream();
+
+            Assert.Throws<SystemException>(stream.Reset, "reset() should not succeed.");
+            Assert.Throws<SystemException>(() => stream.IncrementToken(), "incrementToken() should not succeed.");
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/test/core/Document/TestBinaryDocument.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Document/TestBinaryDocument.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Document/TestBinaryDocument.cs (original)
+++ incubator/lucene.net/trunk/test/core/Document/TestBinaryDocument.cs Mon Apr 16 19:11:49 2012
@@ -42,16 +42,9 @@ namespace Lucene.Net.Documents
 			IFieldable binaryFldStored = new Field("binaryStored", System.Text.UTF8Encoding.UTF8.GetBytes(binaryValStored), Field.Store.YES);
 			IFieldable stringFldStored = new Field("stringStored", binaryValStored, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
 			
-			try
-			{
-				// binary fields with store off are not allowed
-                new Field("fail", System.Text.UTF8Encoding.UTF8.GetBytes(binaryValStored), Field.Store.NO);
-				Assert.Fail();
-			}
-			catch (System.ArgumentException iae)
-			{
-				;
-			}
+			// binary fields with store off are not allowed
+            Assert.Throws<ArgumentException>(
+                () => new Field("fail", System.Text.Encoding.UTF8.GetBytes(binaryValStored), Field.Store.NO));
 			
 			Document doc = new Document();
 			

Modified: incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs (original)
+++ incubator/lucene.net/trunk/test/core/Document/TestDateTools.cs Mon Apr 16 19:11:49 2012
@@ -28,50 +28,26 @@ namespace Lucene.Net.Documents
     [TestFixture]
 	public class TestDateTools:LocalizedTestCase
 	{
-		
+
         [Test]
-		public virtual void  TestStringToDate()
-		{
-			
-			System.DateTime d;
-			d = DateTools.StringToDate("2004");
-			Assert.AreEqual("2004-01-01 00:00:00:000", IsoFormat(d));
-			d = DateTools.StringToDate("20040705");
-			Assert.AreEqual("2004-07-05 00:00:00:000", IsoFormat(d));
-			d = DateTools.StringToDate("200407050910");
-			Assert.AreEqual("2004-07-05 09:10:00:000", IsoFormat(d));
-			d = DateTools.StringToDate("20040705091055990");
-			Assert.AreEqual("2004-07-05 09:10:55:990", IsoFormat(d));
-			
-			try
-			{
-				d = DateTools.StringToDate("97"); // no date
-				Assert.Fail();
-			}
-			catch (System.FormatException e)
-			{
-				/* expected exception */
-			}
-			try
-			{
-				d = DateTools.StringToDate("200401011235009999"); // no date
-				Assert.Fail();
-			}
-			catch (System.FormatException e)
-			{
-				/* expected exception */
-			}
-			try
-			{
-				d = DateTools.StringToDate("aaaa"); // no date
-				Assert.Fail();
-			}
-			catch (System.FormatException e)
-			{
-				/* expected exception */
-			}
-		}
-		
+        public virtual void TestStringToDate()
+        {
+
+            System.DateTime d;
+            d = DateTools.StringToDate("2004");
+            Assert.AreEqual("2004-01-01 00:00:00:000", IsoFormat(d));
+            d = DateTools.StringToDate("20040705");
+            Assert.AreEqual("2004-07-05 00:00:00:000", IsoFormat(d));
+            d = DateTools.StringToDate("200407050910");
+            Assert.AreEqual("2004-07-05 09:10:00:000", IsoFormat(d));
+            d = DateTools.StringToDate("20040705091055990");
+            Assert.AreEqual("2004-07-05 09:10:55:990", IsoFormat(d));
+
+            Assert.Throws<FormatException>(() => DateTools.StringToDate("97")); // no date
+            Assert.Throws<FormatException>(() => DateTools.StringToDate("200401011235009999")); // no date
+            Assert.Throws<FormatException>(() => DateTools.StringToDate("aaaa")); // no date
+        }
+
         [Test]
 		public virtual void  TestStringtoTime()
 		{

Modified: incubator/lucene.net/trunk/test/core/Document/TestDocument.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Document/TestDocument.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Document/TestDocument.cs (original)
+++ incubator/lucene.net/trunk/test/core/Document/TestDocument.cs Mon Apr 16 19:11:49 2012
@@ -124,25 +124,12 @@ namespace Lucene.Net.Documents
 		{
 			new Field("name", "value", Field.Store.YES, Field.Index.NO); // okay
 			new Field("name", "value", Field.Store.NO, Field.Index.NOT_ANALYZED); // okay
-			try
-			{
-				new Field("name", "value", Field.Store.NO, Field.Index.NO);
-				Assert.Fail();
-			}
-			catch (System.ArgumentException e)
-			{
-				// expected exception
-			}
+
+            Assert.Throws<ArgumentException>(() => new Field("name", "value", Field.Store.NO, Field.Index.NO));
+
 			new Field("name", "value", Field.Store.YES, Field.Index.NO, Field.TermVector.NO); // okay
-			try
-			{
-				new Field("name", "value", Field.Store.YES, Field.Index.NO, Field.TermVector.YES);
-				Assert.Fail();
-			}
-			catch (System.ArgumentException e)
-			{
-				// expected exception
-			}
+
+            Assert.Throws<ArgumentException>(() => new Field("name", "value", Field.Store.YES, Field.Index.NO, Field.TermVector.YES));
 		}
 		
 		/// <summary> Tests {@link Document#GetValues(String)} method for a brand new Document
@@ -277,24 +264,9 @@ namespace Lucene.Net.Documents
 		{
 			Field field1 = new Field("field1", new byte[0], Field.Store.YES);
 			Field field2 = new Field("field2", "", Field.Store.YES, Field.Index.ANALYZED);
-			try
-			{
-				field1.SetValue("abc");
-				Assert.Fail("did not hit expected exception");
-			}
-			catch (System.ArgumentException iae)
-			{
-				// expected
-			}
-			try
-			{
-				field2.SetValue(new byte[0]);
-				Assert.Fail("did not hit expected exception");
-			}
-			catch (System.ArgumentException iae)
-			{
-				// expected
-			}
+
+            Assert.Throws<ArgumentException>(() => field1.SetValue("abc"), "did not hit expected exception");
+            Assert.Throws<ArgumentException>(() => field2.SetValue(new byte[0]), "did not hit expected exception");
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/test/core/Index/TestCompoundFile.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestCompoundFile.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestCompoundFile.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestCompoundFile.cs Mon Apr 16 19:11:49 2012
@@ -336,17 +336,9 @@ namespace Lucene.Net.Index
 			// ERROR: this call should fail, but succeeds for some reason as well
 			in_Renamed.Seek(1099);
 			
-			try
-			{
-				// OK: this call correctly fails. We are now past the 1024 internal
-				// buffer, so an actual IO is attempted, which fails
-				b = in_Renamed.ReadByte();
-				Assert.Fail("expected readByte() to throw exception");
-			}
-			catch (System.Exception e)
-			{
-				// expected exception
-			}
+			// OK: this call correctly fails. We are now past the 1024 internal
+			// buffer, so an actual IO is attempted, which fails
+            Assert.Throws<NullReferenceException>(() => in_Renamed.ReadByte(), "expected readByte() to throw exception");
 		}
 		
 		
@@ -594,19 +586,8 @@ namespace Lucene.Net.Index
 		{
 			SetUp_2();
 			CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
-			
 			// Open two files
-			try
-			{
-				IndexInput e1 = cr.OpenInput("bogus");
-				Assert.Fail("File not found");
-			}
-			catch (System.IO.IOException e)
-			{
-				/* success */
-				//System.out.println("SUCCESS: File Not Found: " + e);
-			}
-			
+		    Assert.Throws<System.IO.IOException>(() => cr.OpenInput("bogus"), "File not found");
 			cr.Close();
 		}
 		
@@ -621,28 +602,10 @@ namespace Lucene.Net.Index
 			byte[] b = new byte[100];
 			is_Renamed.ReadBytes(b, 0, 10);
 			
-			try
-			{
-				byte test = is_Renamed.ReadByte();
-				Assert.Fail("Single byte read past end of file");
-			}
-			catch (System.IO.IOException e)
-			{
-				/* success */
-				//System.out.println("SUCCESS: single byte read past end of file: " + e);
-			}
+            Assert.Throws<System.IO.IOException>(() => is_Renamed.ReadByte(), "Single byte read past end of file");
 			
 			is_Renamed.Seek(is_Renamed.Length() - 10);
-			try
-			{
-				is_Renamed.ReadBytes(b, 0, 50);
-				Assert.Fail("Block read past end of file");
-			}
-			catch (System.IO.IOException e)
-			{
-				/* success */
-				//System.out.println("SUCCESS: block read past end of file: " + e);
-			}
+		    Assert.Throws<System.IO.IOException>(() => is_Renamed.ReadBytes(b, 0, 50), "Block read past end of file");
 			
 			is_Renamed.Close();
 			cr.Close();

Modified: incubator/lucene.net/trunk/test/core/Index/TestDirectoryReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestDirectoryReader.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestDirectoryReader.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestDirectoryReader.cs Mon Apr 16 19:11:49 2012
@@ -158,15 +158,8 @@ namespace Lucene.Net.Index
 			Assert.IsFalse(mr.IsCurrent()); // has been modified, not current anymore
 			AddDoc(ramDir2, "even more text", false);
 			Assert.IsFalse(mr.IsCurrent()); // has been modified even more, not current anymore
-			try
-			{
-				var ver = mr.Version;
-				Assert.Fail();
-			}
-			catch (System.NotSupportedException e)
-			{
-				// expected exception
-			}
+
+			Assert.Throws<NotSupportedException>(() => { var ver = mr.Version; });
 			mr.Close();
 		}
 		

Modified: incubator/lucene.net/trunk/test/core/Index/TestFieldsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestFieldsReader.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestFieldsReader.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestFieldsReader.cs Mon Apr 16 19:11:49 2012
@@ -218,15 +218,9 @@ namespace Lucene.Net.Index
 			Assert.IsTrue(field != null, "field is null and it shouldn't be");
 			Assert.IsTrue(field.IsLazy, "field is not lazy and it should be");
             reader.Dispose();
-			try
-			{
-				var value = field.StringValue;
-				Assert.Fail("did not hit AlreadyClosedException as expected");
-			}
-			catch (AlreadyClosedException e)
-			{
-				// expected
-			}
+
+		    Assert.Throws<AlreadyClosedException>(() => { var value = field.StringValue; },
+		                                          "did not hit AlreadyClosedException as expected");
 		}
 		
 		[Test]

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexReader.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexReader.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexReader.cs Mon Apr 16 19:11:49 2012
@@ -445,35 +445,9 @@ namespace Lucene.Net.Index
 			reader.Close();
 			
 			// Then, try to make changes:
-			try
-			{
-				reader.DeleteDocument(4);
-				Assert.Fail("deleteDocument after close failed to throw IOException");
-			}
-			catch (AlreadyClosedException e)
-			{
-				// expected
-			}
-			
-			try
-			{
-				reader.SetNorm(5, "aaa", 2.0f);
-				Assert.Fail("setNorm after close failed to throw IOException");
-			}
-			catch (AlreadyClosedException e)
-			{
-				// expected
-			}
-			
-			try
-			{
-				reader.UndeleteAll();
-				Assert.Fail("undeleteAll after close failed to throw IOException");
-			}
-			catch (AlreadyClosedException e)
-			{
-				// expected
-			}
+            Assert.Throws<AlreadyClosedException>(() => reader.DeleteDocument(4), "deleteDocument after close failed to throw IOException");
+            Assert.Throws<AlreadyClosedException>(() => reader.SetNorm(5, "aaa", 2.0f), "setNorm after close failed to throw IOException");
+            Assert.Throws<AlreadyClosedException>(() => reader.UndeleteAll(), "undeleteAll after close failed to throw IOException");
 		}
 		
 		// Make sure we get lock obtain failed exception with 2 writers:
@@ -497,35 +471,10 @@ namespace Lucene.Net.Index
 			reader = IndexReader.Open(dir, false);
 			
 			// Try to make changes
-			try
-			{
-				reader.DeleteDocument(4);
-				Assert.Fail("deleteDocument should have hit LockObtainFailedException");
-			}
-			catch (LockObtainFailedException e)
-			{
-				// expected
-			}
-			
-			try
-			{
-				reader.SetNorm(5, "aaa", 2.0f);
-				Assert.Fail("setNorm should have hit LockObtainFailedException");
-			}
-			catch (LockObtainFailedException e)
-			{
-				// expected
-			}
-			
-			try
-			{
-				reader.UndeleteAll();
-				Assert.Fail("undeleteAll should have hit LockObtainFailedException");
-			}
-			catch (LockObtainFailedException e)
-			{
-				// expected
-			}
+            Assert.Throws<LockObtainFailedException>(() => reader.DeleteDocument(4), "deleteDocument should have hit LockObtainFailedException");
+            Assert.Throws<LockObtainFailedException>(() =>reader.SetNorm(5, "aaa", 2.0f), "setNorm should have hit LockObtainFailedException");
+            Assert.Throws<LockObtainFailedException>(() => reader.UndeleteAll(), "undeleteAll should have hit LockObtainFailedException");
+
 			writer.Close();
 			reader.Close();
 		}
@@ -701,15 +650,8 @@ namespace Lucene.Net.Index
 			// DELETE DOCUMENTS CONTAINING TERM: aaa
 			// NOTE: the reader was created when only "aaa" documents were in
 			int deleted = 0;
-			try
-			{
-				deleted = reader.DeleteDocuments(searchTerm);
-				Assert.Fail("Delete allowed on an index reader with stale segment information");
-			}
-			catch (StaleReaderException e)
-			{
-				/* success */
-			}
+		    Assert.Throws<StaleReaderException>(() => reader.DeleteDocuments(searchTerm),
+		                                        "Delete allowed on an index reader with stale segment information");
 			
 			// Re-open index reader and try again. This time it should see
 			// the new data.
@@ -856,15 +798,9 @@ namespace Lucene.Net.Index
 			writer.Close();
 			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
 			IndexReader reader = IndexReader.Open(dir, false);
-			try
-			{
-				reader.DeleteDocument(0);
-				Assert.Fail("expected lock");
-			}
-			catch (System.IO.IOException e)
-			{
-				// expected exception
-			}
+
+            Assert.Throws<LockObtainFailedException>(() => reader.DeleteDocument(0), "expected lock");
+
             IndexWriter.Unlock(dir); // this should not be done in the real world! 
 			reader.DeleteDocument(0);
 			reader.Close();
@@ -1237,36 +1173,19 @@ namespace Lucene.Net.Index
 			writer.Close();
 			
 			IndexReader reader = IndexReader.Open(dir, false);
-			try
-			{
-				reader.DeleteDocument(1);
-				Assert.Fail("did not hit exception when deleting an invalid doc number");
-			}
-			catch (System.IndexOutOfRangeException e)
-			{
-				// expected
-			}
+		    Assert.Throws<IndexOutOfRangeException>(() => reader.DeleteDocument(1),
+		                                            "did not hit exception when deleting an invalid doc number");
+
 			reader.Close();
-            if (IndexWriter.IsLocked(dir))
-			{
-				Assert.Fail("write lock is still held after close");
-			}
+            Assert.IsFalse(IndexWriter.IsLocked(dir), "write lock is still held after close");
 			
 			reader = IndexReader.Open(dir, false);
-			try
-			{
-				reader.SetNorm(1, "content", (float) 2.0);
-				Assert.Fail("did not hit exception when calling setNorm on an invalid doc number");
-			}
-			catch (System.IndexOutOfRangeException e)
-			{
-				// expected
-			}
-			reader.Close();
-            if (IndexWriter.IsLocked(dir))
-			{
-				Assert.Fail("write lock is still held after close");
-			}
+		    Assert.Throws<IndexOutOfRangeException>(() => reader.SetNorm(1, "content", (float) 2.0),
+		                                            "did not hit exception when calling setNorm on an invalid doc number");
+
+            reader.Close();
+            Assert.IsFalse(IndexWriter.IsLocked(dir), "write lock is still held after close");
+
 			dir.Close();
 		}
 		
@@ -1289,15 +1208,8 @@ namespace Lucene.Net.Index
 		{
 			System.IO.DirectoryInfo dirFile = new System.IO.DirectoryInfo(System.IO.Path.Combine(AppSettings.Get("tempDir", ""), "deletetest"));
 			Directory dir = FSDirectory.Open(dirFile);
-			try
-			{
-				IndexReader.Open(dir, false);
-				Assert.Fail("expected FileNotFoundException");
-			}
-			catch (System.IO.FileNotFoundException e)
-			{
-				// expected
-			}
+
+            Assert.Throws<NoSuchDirectoryException>(() => IndexReader.Open(dir, false), "expected FileNotFoundException");
 			
 			bool tmpBool;
 			if (System.IO.File.Exists(dirFile.FullName))
@@ -1315,15 +1227,7 @@ namespace Lucene.Net.Index
 			bool generatedAux = tmpBool;
 			
 			// Make sure we still get a CorruptIndexException (not NPE):
-			try
-			{
-				IndexReader.Open(dir, false);
-				Assert.Fail("expected FileNotFoundException");
-			}
-			catch (System.IO.FileNotFoundException e)
-			{
-				// expected
-			}
+            Assert.Throws<NoSuchDirectoryException>(() => IndexReader.Open(dir, false), "expected FileNotFoundException");
 			
 			dir.Close();
 		}
@@ -1392,15 +1296,8 @@ namespace Lucene.Net.Index
 			
 			// ATTEMPT TO DELETE FROM STALE READER
 			// delete documents containing term: bbb
-			try
-			{
-				reader1.DeleteDocuments(searchTerm2);
-				Assert.Fail("Delete allowed from a stale index reader");
-			}
-			catch (System.IO.IOException e)
-			{
-				/* success */
-			}
+		    Assert.Throws<StaleReaderException>(() => reader1.DeleteDocuments(searchTerm2),
+		                                         "Delete allowed from a stale index reader");
 			
 			// RECREATE READER AND TRY AGAIN
 			reader1.Close();
@@ -1660,15 +1557,7 @@ namespace Lucene.Net.Index
 			writer.Close();
 			
 			IndexReader r = IndexReader.Open(d, true);
-			try
-			{
-				r.DeleteDocument(0);
-				Assert.Fail();
-			}
-			catch (System.NotSupportedException uoe)
-			{
-				// expected
-			}
+            Assert.Throws<System.NotSupportedException>(() => r.DeleteDocument(0));
 			
 			writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
 			AddDocumentWithFields(writer);
@@ -1679,16 +1568,7 @@ namespace Lucene.Net.Index
 			r.Close();
 			
 			Assert.IsFalse(r == r2);
-			
-			try
-			{
-				r2.DeleteDocument(0);
-				Assert.Fail();
-			}
-			catch (System.NotSupportedException uoe)
-			{
-				// expected
-			}
+			Assert.Throws<System.NotSupportedException>(() => r2.DeleteDocument(0));
 
             writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
 			writer.Optimize();
@@ -1699,16 +1579,7 @@ namespace Lucene.Net.Index
 			r2.Close();
 			
 			Assert.IsFalse(r == r2);
-			
-			try
-			{
-				r3.DeleteDocument(0);
-				Assert.Fail();
-			}
-			catch (System.NotSupportedException uoe)
-			{
-				// expected
-			}
+            Assert.Throws<System.NotSupportedException>(() => r3.DeleteDocument(0));
 			
 			// Make sure write lock isn't held
             writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
@@ -1771,15 +1642,7 @@ namespace Lucene.Net.Index
 		public virtual void  TestNoDir()
 		{
 			Directory dir = FSDirectory.Open(_TestUtil.GetTempDir("doesnotexist"));
-			try
-			{
-				IndexReader.Open(dir, true);
-				Assert.Fail("did not hit expected exception");
-			}
-			catch (NoSuchDirectoryException nsde)
-			{
-				// expected
-			}
+            Assert.Throws<NoSuchDirectoryException>(() => IndexReader.Open(dir, true), "did not hit expected exception");
 			dir.Close();
 		}
 		
@@ -1948,15 +1811,9 @@ namespace Lucene.Net.Index
 			writer.Commit();
 			IndexReader r2 = r.Reopen();
 			r.Close();
-			try
-			{
-				var tc = r2.UniqueTermCount;
-				Assert.Fail("expected exception");
-			}
-			catch (System.NotSupportedException uoe)
-			{
-				// expected
-			}
+
+			Assert.Throws<NotSupportedException>(() => { var tc = r2.UniqueTermCount; }, "expected exception");
+
 			IndexReader[] subs = r2.GetSequentialSubReaders();
 			for (int i = 0; i < subs.Length; i++)
 			{
@@ -1981,15 +1838,9 @@ namespace Lucene.Net.Index
 			writer.Close();
 			
 			IndexReader r = IndexReader.Open(dir, null, true, - 1);
-			try
-			{
-				r.DocFreq(new Term("field", "f"));
-				Assert.Fail("did not hit expected exception");
-			}
-			catch (System.SystemException ise)
-			{
-				// expected
-			}
+
+            Assert.Throws<SystemException>(() => r.DocFreq(new Term("field", "f")), "did not hit expected exception");
+
 			Assert.IsFalse(((SegmentReader) r.GetSequentialSubReaders()[0]).TermsIndexLoaded());
 
             Assert.AreEqual(-1, (r.GetSequentialSubReaders()[0]).TermInfosIndexDivisor);

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexReaderClone.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexReaderClone.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexReaderClone.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexReaderClone.cs Mon Apr 16 19:11:49 2012
@@ -50,14 +50,10 @@ namespace Lucene.Net.Index
 			TestIndexReaderReopen.CreateIndex(dir1, false);
 			IndexReader reader = IndexReader.Open(dir1, false);
 			IndexReader readOnlyReader = reader.Clone(true);
-			if (!IsReadOnly(readOnlyReader))
-			{
-				Assert.Fail("reader isn't read only");
-			}
-			if (DeleteWorked(1, readOnlyReader))
-			{
-				Assert.Fail("deleting from the original should not have worked");
-			}
+
+            Assert.IsTrue(IsReadOnly(readOnlyReader), "reader isn't read only");
+            Assert.IsFalse(DeleteWorked(1, readOnlyReader), "deleting from the original should not have worked");
+
 			reader.Close();
 			readOnlyReader.Close();
 			dir1.Close();
@@ -73,10 +69,9 @@ namespace Lucene.Net.Index
 			TestIndexReaderReopen.CreateIndex(dir1, true);
 			IndexReader r1 = IndexReader.Open(dir1, false);
 			IndexReader r2 = r1.Clone(false);
-			if (!DeleteWorked(1, r2))
-			{
-				Assert.Fail("deleting from the cloned should have worked");
-			}
+
+            Assert.IsTrue(DeleteWorked(1, r2), "deleting from the cloned should have worked");
+
 			r1.Close();
 			r2.Close();
 			dir1.Close();
@@ -92,10 +87,9 @@ namespace Lucene.Net.Index
 			TestIndexReaderReopen.CreateIndex(dir1, true);
 			IndexReader r1 = IndexReader.Open(dir1, false);
 			IndexReader r2 = r1.Clone(false);
-			if (!DeleteWorked(1, r1))
-			{
-				Assert.Fail("deleting from the original should have worked");
-			}
+
+            Assert.IsTrue(DeleteWorked(1, r1), "deleting from the original should have worked");
+
 			r1.Close();
 			r2.Close();
 			dir1.Close();
@@ -111,10 +105,9 @@ namespace Lucene.Net.Index
 			TestIndexReaderReopen.CreateIndex(dir1, true);
 			IndexReader r1 = IndexReader.Open(dir1, false);
 			IndexReader r2 = r1.Clone(false);
-			if (!DeleteWorked(1, r2))
-			{
-				Assert.Fail("deleting from the original should have worked");
-			}
+
+            Assert.IsTrue(DeleteWorked(1, r2), "deleting from the original should have worked");
+
 			// should fail because reader1 holds the write lock
 			Assert.IsTrue(!DeleteWorked(1, r1), "first reader should not be able to delete");
 			r2.Close();
@@ -157,19 +150,13 @@ namespace Lucene.Net.Index
 			TestIndexReaderReopen.CreateIndex(dir1, true);
 			IndexReader reader = IndexReader.Open(dir1, false);
 			IndexReader readOnlyReader = reader.Clone(true);
-			if (!IsReadOnly(readOnlyReader))
-			{
-				Assert.Fail("reader isn't read only");
-			}
-			if (DeleteWorked(1, readOnlyReader))
-			{
-				Assert.Fail("deleting from the original should not have worked");
-			}
-			// this readonly reader shouldn't have a write lock
-			if (readOnlyReader.hasChanges)
-			{
-				Assert.Fail("readOnlyReader has a write lock");
-			}
+
+            Assert.IsTrue(IsReadOnly(readOnlyReader), "reader isn't read only");
+            Assert.IsFalse(DeleteWorked(1, readOnlyReader), "deleting from the original should not have worked");
+
+            // this readonly reader shouldn't have a write lock
+            Assert.IsFalse(readOnlyReader.hasChanges, "readOnlyReader has a write lock");
+
 			reader.Close();
 			readOnlyReader.Close();
 			dir1.Close();
@@ -188,10 +175,8 @@ namespace Lucene.Net.Index
 			Assert.AreEqual(docCount - 1, reader.NumDocs());
 			
 			IndexReader readOnlyReader = reader.Reopen(true);
-			if (!IsReadOnly(readOnlyReader))
-			{
-				Assert.Fail("reader isn't read only");
-			}
+            Assert.IsTrue(IsReadOnly(readOnlyReader), "reader isn't read only");
+
 			Assert.IsFalse(DeleteWorked(1, readOnlyReader));
 			Assert.AreEqual(docCount - 1, readOnlyReader.NumDocs());
 			reader.Close();
@@ -209,16 +194,13 @@ namespace Lucene.Net.Index
 			IndexReader reader1 = IndexReader.Open(dir1, true);
 			
 			IndexReader reader2 = reader1.Clone(false);
-			if (IsReadOnly(reader2))
-			{
-				Assert.Fail("reader should not be read only");
-			}
+
+            Assert.IsFalse(IsReadOnly(reader2), "reader should not be read only");
+
 			Assert.IsFalse(DeleteWorked(1, reader1), "deleting from the original reader should not have worked");
 			// this readonly reader shouldn't yet have a write lock
-			if (reader2.hasChanges)
-			{
-				Assert.Fail("cloned reader should not have write lock");
-			}
+            Assert.IsFalse(reader2.hasChanges, "cloned reader should not have write lock");
+
 			Assert.IsTrue(DeleteWorked(1, reader2), "deleting from the cloned reader should have worked");
 			reader1.Close();
 			reader2.Close();
@@ -267,10 +249,9 @@ namespace Lucene.Net.Index
 			TestIndexReaderReopen.CreateIndex(dir1, true);
 			IndexReader reader = IndexReader.Open(dir1, false);
 			IndexReader readOnlyReader = reader.Clone(true);
-			if (!IsReadOnly(readOnlyReader))
-			{
-				Assert.Fail("reader isn't read only");
-			}
+
+            Assert.IsTrue(IsReadOnly(readOnlyReader), "reader isn't read only");
+
 			reader.Close();
 			readOnlyReader.Close();
 			dir1.Close();
@@ -327,15 +308,8 @@ namespace Lucene.Net.Index
 			Assert.IsTrue(pr1Clone.IsDeleted(10));
 			
 			// try to update the original reader, which should throw an exception
-			try
-			{
-				r1.DeleteDocument(11);
-				Assert.Fail("Tried to delete doc 11 and an exception should have been thrown");
-			}
-			catch (System.Exception exception)
-			{
-				// expectted
-			}
+            Assert.Throws<LockObtainFailedException>(() => r1.DeleteDocument(11),
+		                             "Tried to delete doc 11 and an exception should have been thrown");
 			pr1Clone.Close();
 		}
 		
@@ -429,15 +403,7 @@ namespace Lucene.Net.Index
 			// cloned segmentreader
 			
 			// deleting a doc from the original segmentreader should throw an exception
-			try
-			{
-				origReader.DeleteDocument(4);
-				Assert.Fail("expected exception");
-			}
-			catch (LockObtainFailedException lbfe)
-			{
-				// expected
-			}
+            Assert.Throws<LockObtainFailedException>(() => origReader.DeleteDocument(4), "expected exception");
 			
 			origReader.Close();
 			// try closing the original segment reader to see if it affects the

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexReaderCloneNorms.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexReaderCloneNorms.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexReaderCloneNorms.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexReaderCloneNorms.cs Mon Apr 16 19:11:49 2012
@@ -16,7 +16,7 @@
  */
 
 using System;
-
+using Lucene.Net.Store;
 using NUnit.Framework;
 
 using Analyzer = Lucene.Net.Analysis.Analyzer;
@@ -239,15 +239,7 @@ namespace Lucene.Net.Index
 			reader4C.SetNorm(5, "field1", 0.33f);
 			
 			// generate a cannot update exception in reader1
-			try
-			{
-				reader3C.SetNorm(1, "field1", 0.99f);
-				Assert.Fail("did not hit expected exception");
-			}
-			catch (System.Exception ex)
-			{
-				// expected
-			}
+            Assert.Throws<LockObtainFailedException>(() => reader3C.SetNorm(1, "field1", 0.99f), "did not hit expected exception");
 			
 			// norm values should be different 
 			Assert.IsTrue(Similarity.DecodeNorm(segmentReader3C.Norms("field1")[5]) != Similarity.DecodeNorm(segmentReader4C.Norms("field1")[5]));

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexReaderReopen.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexReaderReopen.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexReaderReopen.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexReaderReopen.cs Mon Apr 16 19:11:49 2012
@@ -850,16 +850,8 @@ namespace Lucene.Net.Index
 			IndexReader index2 = test.OpenReader();
 			
 			TestIndexReader.AssertIndexEquals(index1, index2);
-			
-			try
-			{
-				RefreshReader(index1, test, 0, true);
-				Assert.Fail("Expected exception not thrown.");
-			}
-			catch (System.Exception e)
-			{
-				// expected exception
-			}
+		    
+            Assert.Throws(Is.InstanceOf<Exception>(), () => RefreshReader(index1, test, 0, true), "Expected exception not thrown.");
 			
 			// index2 should still be usable and unaffected by the failed reopen() call
 			TestIndexReader.AssertIndexEquals(index1, index2);
@@ -972,8 +964,7 @@ namespace Lucene.Net.Index
 					threads[i].Join();
 					if (threads[i].error != null)
 					{
-						System.String msg = "Error occurred in thread " + threads[i].Name + ":\n" + threads[i].error.Message;
-						Assert.Fail(msg);
+						Assert.Fail("Error occurred in thread " + threads[i].Name + ":\n" + threads[i].error.Message);
 					}
 				}
 			}
@@ -1300,15 +1291,7 @@ namespace Lucene.Net.Index
 			IndexReader r3 = r1.Reopen();
 			Assert.IsTrue(r1 != r3);
 			r1.Close();
-			try
-			{
-				r1.Document(2);
-				Assert.Fail("did not hit exception");
-			}
-			catch (AlreadyClosedException ace)
-			{
-				// expected
-			}
+            Assert.Throws<AlreadyClosedException>(() => r1.Document(2), "did not hit exception");
 			r3.Close();
 			dir.Close();
 		}
@@ -1424,15 +1407,7 @@ namespace Lucene.Net.Index
 				Assert.IsTrue(r2 != r);
 				
 				// Reader should be readOnly
-				try
-				{
-					r2.DeleteDocument(0);
-					Assert.Fail("no exception hit");
-				}
-				catch (System.NotSupportedException uoe)
-				{
-					// expected
-				}
+			    Assert.Throws<NotSupportedException>(() => r2.DeleteDocument(0), "no exception hit");
 
                 System.Collections.Generic.IDictionary<string, string> s = commit.UserData;
 				int v;

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexWriter.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexWriter.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexWriter.cs Mon Apr 16 19:11:49 2012
@@ -233,14 +233,8 @@ namespace Lucene.Net.Index
                         writer.AddDocument(doc);
                         doc.Add(new Field("crash", "this should crash after 4 terms", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                         doc.Add(new Field("other", "this will not get indexed", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
-                        try
-                        {
-                            writer.AddDocument(doc);
-                            Assert.Fail("did not hit expected exception");
-                        }
-                        catch (System.IO.IOException ioe)
-                        {
-                        }
+
+                        Assert.Throws<System.IO.IOException>(() => writer.AddDocument(doc), "did not hit expected exception");
 
                         if (0 == finalI)
                         {
@@ -1236,25 +1230,13 @@ namespace Lucene.Net.Index
             out_Renamed.Close();
 
             IndexReader reader = null;
-            try
-            {
-                reader = IndexReader.Open(dir, true);
-            }
-            catch (System.Exception e)
-            {
-                Assert.Fail("reader failed to open on a crashed index");
-            }
+            Assert.DoesNotThrow(() => reader = IndexReader.Open(dir, true), "reader failed to open on a crashed index");
             reader.Close();
 
-            try
-            {
-                writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-            }
-            catch (System.Exception e)
-            {
-                System.Console.WriteLine(e.StackTrace);
-                Assert.Fail("writer failed to open on a crashed index");
-            }
+            Assert.DoesNotThrow(() => writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
+                                                               IndexWriter.MaxFieldLength.LIMITED),
+                                "writer failed to open on a crashed index");
+
 
             // add 100 documents
             for (int i = 0; i < 100; i++)
@@ -1303,19 +1285,8 @@ namespace Lucene.Net.Index
             out_Renamed.Close();
             dir.DeleteFile(fileNameIn);
 
-            IndexReader reader = null;
-            try
-            {
-                reader = IndexReader.Open(dir, true);
-                Assert.Fail("reader did not hit IOException on opening a corrupt index");
-            }
-            catch (System.Exception e)
-            {
-            }
-            if (reader != null)
-            {
-                reader.Close();
-            }
+            IndexReader reader;
+            Assert.Throws<System.IO.IOException>(() => reader = IndexReader.Open(dir, true), "reader did not hit IOException on opening a corrupt index");
         }
 
         [Test]
@@ -1330,15 +1301,8 @@ namespace Lucene.Net.Index
 
             // close
             writer.Close();
-            try
-            {
-                AddDoc(writer);
-                Assert.Fail("did not hit AlreadyClosedException");
-            }
-            catch (AlreadyClosedException e)
-            {
-                // expected
-            }
+
+            Assert.Throws<AlreadyClosedException>(() => AddDoc(writer), "did not hit AlreadyClosedException");
         }
 
 
@@ -1376,19 +1340,8 @@ namespace Lucene.Net.Index
                 }
             }
 
-            IndexReader reader = null;
-            try
-            {
-                reader = IndexReader.Open(dir, true);
-                Assert.Fail("reader did not hit IOException on opening a corrupt index");
-            }
-            catch (System.Exception e)
-            {
-            }
-            if (reader != null)
-            {
-                reader.Close();
-            }
+            Assert.Throws<System.IO.FileNotFoundException>(() => IndexReader.Open(dir, true),
+                                                 "reader did not hit IOException on opening a corrupt index");
         }
 
         /*
@@ -2321,14 +2274,8 @@ namespace Lucene.Net.Index
             Document doc = new Document();
             System.String contents = "aa bb cc dd ee ff gg hh ii jj kk";
             doc.Add(new Field("content", contents, Field.Store.NO, Field.Index.ANALYZED));
-            try
-            {
-                writer.AddDocument(doc);
-                Assert.Fail("did not hit expected exception");
-            }
-            catch (System.Exception e)
-            {
-            }
+
+            Assert.Throws<System.IO.IOException>(() => writer.AddDocument(doc), "did not hit expected exception");
 
             // Make sure we can add another normal document
             doc = new Document();
@@ -2491,14 +2438,8 @@ namespace Lucene.Net.Index
                 writer.AddDocument(doc);
                 doc.Add(new Field("crash", "this should crash after 4 terms", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                 doc.Add(new Field("other", "this will not get indexed", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
-                try
-                {
-                    writer.AddDocument(doc);
-                    Assert.Fail("did not hit expected exception");
-                }
-                catch (System.IO.IOException ioe)
-                {
-                }
+
+                Assert.Throws<System.IO.IOException>(() => writer.AddDocument(doc), "did not hit expected exception");
 
                 if (0 == i)
                 {
@@ -2935,32 +2876,14 @@ namespace Lucene.Net.Index
             dir.SetMaxSizeInBytes(dir.GetRecomputedActualSizeInBytes());
             writer.SetMaxBufferedDocs(2);
             Document doc = new Document();
-            doc.Add(new Field("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
-            try
-            {
-                writer.AddDocument(doc);
-                Assert.Fail("did not hit disk full");
-            }
-            catch (System.IO.IOException ioe)
-            {
-            }
+            doc.Add(new Field("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", Field.Store.YES, Field.Index.ANALYZED,
+                              Field.TermVector.WITH_POSITIONS_OFFSETS));
+
+            Assert.Throws<System.IO.IOException>(() => writer.AddDocument(doc), "did not hit disk full");
+
             // Without fix for LUCENE-1130: this call will hang:
-            try
-            {
-                writer.AddDocument(doc);
-                Assert.Fail("did not hit disk full");
-            }
-            catch (System.IO.IOException ioe)
-            {
-            }
-            try
-            {
-                writer.Close(false);
-                Assert.Fail("did not hit disk full");
-            }
-            catch (System.IO.IOException ioe)
-            {
-            }
+            Assert.Throws<System.IO.IOException>(() => writer.AddDocument(doc), "did not hit disk full");
+            Assert.Throws<System.IO.IOException>(() => writer.Close(false), "did not hit disk full");
         }
 
         // LUCENE-1130: make sure immediate disk full on creating
@@ -3057,16 +2980,14 @@ namespace Lucene.Net.Index
 
             dir.FailOn(failure);
             failure.SetDoFail();
-            try
-            {
-                writer.AddDocument(doc);
-                writer.AddDocument(doc);
-                writer.Commit();
-                Assert.Fail("did not hit exception");
-            }
-            catch (System.IO.IOException ioe)
-            {
-            }
+
+            Assert.Throws<System.IO.IOException>(() =>
+                                                     {
+                                                         writer.AddDocument(doc);
+                                                         writer.AddDocument(doc);
+                                                         writer.Commit();
+                                                     }, "did not hit exception");
+
             failure.ClearDoFail();
             writer.AddDocument(doc);
             writer.Close(false);
@@ -3823,15 +3744,10 @@ namespace Lucene.Net.Index
 
             Document crashDoc = new Document();
             crashDoc.Add(new Field("crash", "do it on token 4", Field.Store.YES, Field.Index.ANALYZED));
-            try
-            {
-                w.AddDocument(crashDoc, analyzer);
-                Assert.Fail("did not hit expected exception");
-            }
-            catch (System.IO.IOException ioe)
-            {
-                // expected
-            }
+
+            Assert.Throws<System.IO.IOException>(() => w.AddDocument(crashDoc, analyzer),
+                                                 "did not hit expected exception");
+
             w.AddDocument(doc);
             w.Close();
             dir.Close();
@@ -4021,19 +3937,9 @@ namespace Lucene.Net.Index
             doc.Add(new Field("field", "a field", Field.Store.YES, Field.Index.ANALYZED));
             w.AddDocument(doc);
             dir.FailOn(failure);
-            try
-            {
-                w.Close();
-                Assert.Fail();
-            }
-            catch (System.IO.IOException ioe)
-            {
-                Assert.Fail("expected only RuntimeException");
-            }
-            catch (System.SystemException re)
-            {
-                // Expected
-            }
+
+            Assert.Throws<SystemException>(w.Close, "expected only RuntimeException");
+
             Assert.IsTrue(failure.fail1 && failure.fail2);
             w.Rollback();
             dir.Close();
@@ -4967,8 +4873,7 @@ namespace Lucene.Net.Index
                 }
                 catch (System.IO.IOException ioe)
                 {
-                    if (ioe.InnerException == null)
-                        Assert.Fail("optimize threw IOException without root cause");
+                    Assert.IsNotNull(ioe.InnerException, "optimize threw IOException without root cause");
                 }
                 w.Close();
                 dir.Close();
@@ -5744,16 +5649,9 @@ namespace Lucene.Net.Index
             ftdm.SetDoFail();
             dir.FailOn(ftdm);
 
-            try
-            {
-                w.Commit();
-                Assert.Fail("fake disk full IOExceptions not hit");
-            }
-            catch (System.IO.IOException ioe)
-            {
-                // expected
-                Assert.IsTrue(ftdm.didFail1 || ftdm.didFail2);
-            }
+            Assert.Throws<System.IO.IOException>(w.Commit, "fake disk full IOExceptions not hit");
+            Assert.IsTrue(ftdm.didFail1 || ftdm.didFail2);
+
             _TestUtil.CheckIndex(dir);
             ftdm.ClearDoFail();
             w.AddDocument(doc);

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexWriterDelete.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexWriterDelete.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexWriterDelete.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexWriterDelete.cs Mon Apr 16 19:11:49 2012
@@ -890,11 +890,9 @@ namespace Lucene.Net.Index
             new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null, null);
             System.String[] endFiles = dir.ListAll();
 
-            if (!CollectionsHelper.CompareStringArrays(startFiles, endFiles))
-            {
-                Assert.Fail("docswriter abort() failed to delete unreferenced files:\n  before delete:\n    " +
-                            ArrayToString(startFiles) + "\n  after delete:\n    " + ArrayToString(endFiles));
-            }
+            Assert.IsTrue(CollectionsHelper.CompareStringArrays(startFiles, endFiles),
+                          "docswriter abort() failed to delete unreferenced files:\n  before delete:\n    " +
+                          ArrayToString(startFiles) + "\n  after delete:\n    " + ArrayToString(endFiles));
 
             modifier.Close();
         }

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexWriterExceptions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexWriterExceptions.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexWriterExceptions.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexWriterExceptions.cs Mon Apr 16 19:11:49 2012
@@ -272,8 +272,7 @@ namespace Lucene.Net.Index
 				threads[i].Join();
 			
 			for (int i = 0; i < NUM_THREADS; i++)
-				if (threads[i].failure != null)
-					Assert.Fail("thread " + threads[i].Name + ": hit unexpected failure");
+                Assert.IsNull(threads[i].failure, "thread " + threads[i].Name + ": hit unexpected failure");
 			
 			writer.Commit();
 			

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexWriterMerging.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexWriterMerging.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexWriterMerging.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexWriterMerging.cs Mon Apr 16 19:11:49 2012
@@ -47,18 +47,10 @@ namespace Lucene.Net.Index
 			Directory indexB = new MockRAMDirectory();
 			
 			FillIndex(indexA, 0, num);
-			bool fail = VerifyIndex(indexA, 0);
-			if (fail)
-			{
-				Assert.Fail("Index a is invalid");
-			}
+            Assert.IsFalse(VerifyIndex(indexA, 0), "Index a is invalid");
 			
 			FillIndex(indexB, num, num);
-			fail = VerifyIndex(indexB, num);
-			if (fail)
-			{
-				Assert.Fail("Index b is invalid");
-			}
+            Assert.IsFalse(VerifyIndex(indexB, num), "Index b is invalid");
 			
 			Directory merged = new MockRAMDirectory();
 			
@@ -69,7 +61,7 @@ namespace Lucene.Net.Index
             writer.Optimize();
 			writer.Close();
 			
-			fail = VerifyIndex(merged, 0);
+			var fail = VerifyIndex(merged, 0);
 			merged.Close();
 			
 			Assert.IsFalse(fail, "The merged index is invalid");

Modified: incubator/lucene.net/trunk/test/core/Index/TestIndexWriterReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestIndexWriterReader.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestIndexWriterReader.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestIndexWriterReader.cs Mon Apr 16 19:11:49 2012
@@ -928,16 +928,9 @@ namespace Lucene.Net.Index
 			Assert.AreEqual(100, r.NumDocs());
 			Query q = new TermQuery(new Term("indexname", "test"));
 			Assert.AreEqual(100, new IndexSearcher(r).Search(q, 10).TotalHits);
-			
-			try
-			{
-				r.Reopen();
-				Assert.Fail("failed to hit AlreadyClosedException");
-			}
-			catch (AlreadyClosedException ace)
-			{
-				// expected
-			}
+
+		    Assert.Throws<AlreadyClosedException>(() => r.Reopen(), "failed to hit AlreadyClosedException");
+
 			r.Close();
 			dir1.Close();
 		}

Modified: incubator/lucene.net/trunk/test/core/Index/TestLazyBug.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestLazyBug.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestLazyBug.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestLazyBug.cs Mon Apr 16 19:11:49 2012
@@ -113,10 +113,7 @@ namespace Lucene.Net.Index
 						System.String fval = f.StringValue;
 						Assert.IsNotNull(docs[i] + " FIELD: " + fname, fval);
 						System.String[] vals = fval.Split('#');
-						if (!dataset.Contains(vals[0]) || !dataset.Contains(vals[1]))
-						{
-							Assert.Fail("FIELD:" + fname + ",VAL:" + fval);
-						}
+                        Assert.IsTrue(dataset.Contains(vals[0]) || dataset.Contains(vals[1]), "FIELD:" + fname + ",VAL:" + fval);
 					}
 					catch (System.Exception e)
 					{

Modified: incubator/lucene.net/trunk/test/core/Index/TestMultiLevelSkipList.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestMultiLevelSkipList.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestMultiLevelSkipList.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestMultiLevelSkipList.cs Mon Apr 16 19:11:49 2012
@@ -82,10 +82,7 @@ namespace Lucene.Net.Index
 		public virtual void  CheckSkipTo(TermPositions tp, int target, int maxCounter)
 		{
 			tp.SkipTo(target);
-			if (maxCounter < counter)
-			{
-				Assert.Fail("Too many bytes read: " + counter);
-			}
+		    Assert.Greater(maxCounter, counter, "Too many bytes read: " + counter);
 			
 			Assert.AreEqual(target, tp.Doc, "Wrong document " + tp.Doc + " after skipTo target " + target);
 			Assert.AreEqual(1, tp.Freq, "Frequency is not 1: " + tp.Freq);

Modified: incubator/lucene.net/trunk/test/core/Index/TestParallelReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestParallelReader.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestParallelReader.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestParallelReader.cs Mon Apr 16 19:11:49 2012
@@ -126,15 +126,9 @@ namespace Lucene.Net.Index
 			
 			ParallelReader pr = new ParallelReader();
             pr.Add(IndexReader.Open(dir1, false));
-			try
-			{
-                pr.Add(IndexReader.Open(dir2, false));
-				Assert.Fail("didn't get exptected exception: indexes don't have same number of documents");
-			}
-			catch (System.ArgumentException e)
-			{
-				// expected exception
-			}
+
+			Assert.Throws<ArgumentException>(() => pr.Add(IndexReader.Open(dir2, false)),
+			                                    "didn't get exptected exception: indexes don't have same number of documents");
 		}
 		
 		[Test]

Modified: incubator/lucene.net/trunk/test/core/Index/TestPayloads.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestPayloads.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestPayloads.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestPayloads.cs Mon Apr 16 19:11:49 2012
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.IO;
 using Lucene.Net.Analysis.Tokenattributes;
 using Lucene.Net.Support;
 using NUnit.Framework;
@@ -98,15 +99,8 @@ namespace Lucene.Net.Index
 			
 			// test copyTo()
 			byte[] target = new byte[testData.Length - 1];
-			try
-			{
-				payload.CopyTo(target, 0);
-				Assert.Fail("Expected exception not thrown");
-			}
-			catch (System.Exception expected)
-			{
-				// expected exception
-			}
+            
+            Assert.Throws<IndexOutOfRangeException>(() => payload.CopyTo(target, 0), "Expected exception not thrown");
 			
 			target = new byte[testData.Length + 3];
 			payload.CopyTo(target, 3);
@@ -127,15 +121,7 @@ namespace Lucene.Net.Index
 				Assert.AreEqual(payload.ByteAt(i), testData[i]);
 			}
 			
-			try
-			{
-				payload.ByteAt(testData.Length + 1);
-				Assert.Fail("Expected exception not thrown");
-			}
-			catch (System.Exception expected)
-			{
-				// expected exception
-			}
+            Assert.Throws<IndexOutOfRangeException>(() => payload.ByteAt(testData.Length + 1), "Expected exception not thrown");
 			
 			Payload clone = (Payload) payload.Clone();
 			Assert.AreEqual(payload.Length, clone.Length);
@@ -357,17 +343,10 @@ namespace Lucene.Net.Index
 			* Test multiple call of getPayload()
 			*/
 			tp.GetPayload(null, 0);
-			try
-			{
-				// it is forbidden to call getPayload() more than once
-				// without calling nextPosition()
-				tp.GetPayload(null, 0);
-				Assert.Fail("Expected exception not thrown");
-			}
-			catch (System.Exception expected)
-			{
-				// expected exception
-			}
+
+			// it is forbidden to call getPayload() more than once
+			// without calling nextPosition()
+            Assert.Throws<IOException>(() => tp.GetPayload(null, 0), "Expected exception not thrown");
 			
 			reader.Close();
 			
@@ -439,17 +418,11 @@ namespace Lucene.Net.Index
 		
 		internal virtual void  AssertByteArrayEquals(byte[] b1, byte[] b2)
 		{
-			if (b1.Length != b2.Length)
-			{
-				Assert.Fail("Byte arrays have different lengths: " + b1.Length + ", " + b2.Length);
-			}
+            Assert.AreEqual(b1.Length, b2.Length, "Byte arrays have different lengths: " + b1.Length + ", " + b2.Length);
 			
 			for (int i = 0; i < b1.Length; i++)
 			{
-				if (b1[i] != b2[i])
-				{
-					Assert.Fail("Byte arrays different at index " + i + ": " + b1[i] + ", " + b2[i]);
-				}
+                Assert.AreEqual(b1[i], b2[i], "Byte arrays different at index " + i + ": " + b1[i] + ", " + b2[i]);
 			}
 		}
 		

Modified: incubator/lucene.net/trunk/test/core/Index/TestSnapshotDeletionPolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestSnapshotDeletionPolicy.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestSnapshotDeletionPolicy.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestSnapshotDeletionPolicy.cs Mon Apr 16 19:11:49 2012
@@ -173,15 +173,8 @@ namespace Lucene.Net.Index
 			dp.Release();
             writer = new IndexWriter(dir, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);
 			writer.Close();
-			try
-			{
-				CopyFiles(dir, cp);
-				Assert.Fail("did not hit expected IOException");
-			}
-			catch (System.IO.IOException ioe)
-			{
-				// expected
-			}
+
+            Assert.Throws<System.IO.FileNotFoundException>(() => CopyFiles(dir, cp), "did not hit expected IOException");
 			dir.Close();
 		}
 		
@@ -304,15 +297,8 @@ namespace Lucene.Net.Index
             // Tests that if there were no commits when snapshot() is called, then
             // IllegalStateException is thrown rather than NPE.
             SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
-            try
-            {
-                sdp.Snapshot();
-                Assert.Fail("expected exception not hit");
-            }
-            catch (System.SystemException ise)
-            {
-                // expected
-            }
+
+            Assert.Throws<SystemException>(() => sdp.Snapshot(), "expected exception not hit");
         }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/test/core/Index/TestTermVectorsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/core/Index/TestTermVectorsReader.cs?rev=1326749&r1=1326748&r2=1326749&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/core/Index/TestTermVectorsReader.cs (original)
+++ incubator/lucene.net/trunk/test/core/Index/TestTermVectorsReader.cs Mon Apr 16 19:11:49 2012
@@ -479,42 +479,24 @@ namespace Lucene.Net.Index
 		[Test]
 		public virtual void  TestBadParams()
 		{
-			try
-			{
-				TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-				Assert.IsTrue(reader != null);
-				//Bad document number, good field number
-				reader.Get(50, testFields[0]);
-				Assert.Fail();
-			}
-			catch (System.IO.IOException e)
-			{
-				// expected exception
-			}
-			try
-			{
-				TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-				Assert.IsTrue(reader != null);
-				//Bad document number, no field
-				reader.Get(50);
-				Assert.Fail();
-			}
-			catch (System.IO.IOException e)
-			{
-				// expected exception
-			}
-			try
-			{
-				TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
-				Assert.IsTrue(reader != null);
-				//good document number, bad field number
-				ITermFreqVector vector = reader.Get(0, "f50");
-				Assert.IsTrue(vector == null);
-			}
-			catch (System.IO.IOException e)
-			{
-				Assert.Fail();
-			}
+			var reader = new TermVectorsReader(dir, seg, fieldInfos);
+			Assert.IsTrue(reader != null);
+			//Bad document number, good field number
+            Assert.Throws<System.IO.IOException>(() => reader.Get(50, testFields[0]));
+
+			reader = new TermVectorsReader(dir, seg, fieldInfos);
+			Assert.IsTrue(reader != null);
+			//Bad document number, no field
+			Assert.Throws<System.IO.IOException>(() => reader.Get(50));
+
+			reader = new TermVectorsReader(dir, seg, fieldInfos);
+			Assert.IsTrue(reader != null);
+		    Assert.DoesNotThrow(() =>
+		                            {
+		                                //good document number, bad field number
+		                                ITermFreqVector vector = reader.Get(0, "f50");
+		                                Assert.IsTrue(vector == null);
+		                            });
 		}
 		
 		



Mime
View raw message