lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [04/21] git commit: Fixed TestIOUtils.TestSuppressedExceptions
Date Fri, 19 Sep 2014 14:19:37 GMT
Fixed TestIOUtils.TestSuppressedExceptions

Rewrote the tests and some of the tested code to work around C# not
having Java's Exception.addSuppressed.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/021236d6
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/021236d6
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/021236d6

Branch: refs/heads/master
Commit: 021236d6614c55ca2acac7a6c993b060ca2c5ee6
Parents: 9b9b4a2
Author: Prad Nelluru <prnell@microsoft.com>
Authored: Tue Sep 16 14:25:20 2014 -0700
Committer: Prad Nelluru <prnell@microsoft.com>
Committed: Tue Sep 16 14:25:20 2014 -0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/IOUtils.cs           | 20 ++++++++---
 src/Lucene.Net.Tests/core/Util/TestIOUtils.cs | 42 ++++++----------------
 2 files changed, 25 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021236d6/src/Lucene.Net.Core/Util/IOUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/IOUtils.cs b/src/Lucene.Net.Core/Util/IOUtils.cs
index 9f1d1fb..78236e4 100644
--- a/src/Lucene.Net.Core/Util/IOUtils.cs
+++ b/src/Lucene.Net.Core/Util/IOUtils.cs
@@ -252,16 +252,26 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// adds a Throwable to the list of suppressed Exceptions of the first Throwable
</summary>
+        /// Since there's no C# equivalent of Java's Exception.AddSuppressed, we add the
+        /// suppressed exceptions to a data field. </summary>
         /// <param name="exception"> this exception should get the suppressed one added
</param>
         /// <param name="suppressed"> the suppressed exception </param>
         private static void AddSuppressed(Exception exception, Exception suppressed)
         {
-            //LUCENE TO-DO I don't think there is a .NET equivalent
-            /*if (exception != null && suppressed != null)
+            if (exception != null && suppressed != null)
             {
-              exception.AddSuppressed(suppressed);
-            }*/
+                List<Exception> suppressedExceptions;
+                if (!exception.Data.Contains("SuppressedExceptions"))
+                {
+                    suppressedExceptions = new List<Exception>();
+                    exception.Data.Add("SuppressedExceptions", suppressedExceptions);
+                }
+                else
+                {
+                    suppressedExceptions = (List<Exception>) exception.Data["SuppressedExceptions"];
+                }
+                suppressedExceptions.Add(suppressed);
+            }
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/021236d6/src/Lucene.Net.Tests/core/Util/TestIOUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestIOUtils.cs b/src/Lucene.Net.Tests/core/Util/TestIOUtils.cs
index 3665c31..2682431 100644
--- a/src/Lucene.Net.Tests/core/Util/TestIOUtils.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestIOUtils.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
 using NUnit.Framework;
 using System;
 using System.IO;
@@ -59,24 +60,12 @@ namespace Lucene.Net.Util
             }
             catch (TestException e1)
             {
-                Assert.AreEqual("BASE-EXCEPTION", e1.Message);
-                StringBuilder sb = new StringBuilder();
-                //StreamWriter pw = new StreamWriter(sw);
-                //e1.printStackTrace(pw);
-                sb.Append(e1.StackTrace);
-                //pw.Flush();
-                string trace = sb.ToString();
-                if (VERBOSE)
-                {
-                    Console.WriteLine("TestIOUtils.testSuppressedExceptions: Thrown Exception
stack trace:");
-                    Console.WriteLine(trace);
-                }
-                Assert.IsTrue(trace.Contains("IOException: TEST-IO-EXCEPTION-1"), "Stack
trace does not contain first suppressed Exception: " + trace);
-                Assert.IsTrue(trace.Contains("IOException: TEST-IO-EXCEPTION-2"), "Stack
trace does not contain second suppressed Exception: " + trace);
+                Assert.IsTrue(e1.Data.Contains("SuppressedExceptions"));
+                Assert.IsTrue(((List<Exception>) e1.Data["SuppressedExceptions"]).Count
== 2);
             }
-            catch (IOException e2)
+            catch (Exception e2)
             {
-                Assert.Fail("IOException should not be thrown here");
+                Assert.Fail("Exception should not be thrown here");
             }
 
             // test without prior exception
@@ -84,25 +73,14 @@ namespace Lucene.Net.Util
             {
                 IOUtils.CloseWhileHandlingException((TestException)null, new BrokenIDisposable(1),
new BrokenIDisposable(2));
             }
-            catch (TestException e1)
+            catch (IOException e1)
             {
-                Assert.Fail("TestException should not be thrown here");
+                Assert.IsTrue(e1.Data.Contains("SuppressedExceptions"));
+                Assert.IsTrue(((List<Exception>)e1.Data["SuppressedExceptions"]).Count
== 1);
             }
-            catch (IOException e2)
+            catch (Exception e2)
             {
-                Assert.AreEqual("TEST-IO-EXCEPTION-1", e2.Message);
-                StringBuilder sb = new StringBuilder();
-                sb.Append(e2.StackTrace);
-                //StreamWriter pw = new StreamWriter(sw);
-                //e2.printStackTrace(pw);
-                //pw.Flush();
-                string trace = sb.ToString();
-                if (VERBOSE)
-                {
-                    Console.WriteLine("TestIOUtils.TestSuppressedExceptions: Thrown Exception
stack trace:");
-                    Console.WriteLine(trace);
-                }
-                Assert.IsTrue(trace.Contains("IOException: TEST-IO-EXCEPTION-2"), "Stack
trace does not contain suppressed Exception: " + trace);
+                Assert.Fail("Exception should not be thrown here");
             }
         }
     }


Mime
View raw message