ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject ant-ivy git commit: Fix transient test failures - Don't share/update the MockMessageLogger between test methods
Date Thu, 25 May 2017 15:00:13 GMT
Repository: ant-ivy
Updated Branches:
  refs/heads/master 239bc0b04 -> da69323b2


Fix transient test failures - Don't share/update the MockMessageLogger between test methods


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/da69323b
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/da69323b
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/da69323b

Branch: refs/heads/master
Commit: da69323b29fe8e373364b9399bc67523dcf2af62
Parents: 239bc0b
Author: Jaikiran Pai <jaikiran.pai@gmail.com>
Authored: Sat May 20 09:13:17 2017 +0530
Committer: Jaikiran Pai <jaikiran.pai@gmail.com>
Committed: Wed May 24 22:10:14 2017 +0530

----------------------------------------------------------------------
 .../IgnoreCircularDependencyStrategyTest.java   | 25 ++++++++-
 .../WarnCircularDependencyStrategyTest.java     | 54 ++++++++++++++------
 .../org/apache/ivy/util/MockMessageLogger.java  |  1 +
 3 files changed, 62 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da69323b/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
b/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
index 2c60c35..10bc5c4 100644
--- a/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
+++ b/test/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategyTest.java
@@ -18,7 +18,9 @@
 package org.apache.ivy.plugins.circular;
 
 import org.apache.ivy.TestHelper;
+import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.util.Message;
+import org.apache.ivy.util.MessageLoggerEngine;
 import org.apache.ivy.util.MockMessageLogger;
 
 import junit.framework.TestCase;
@@ -27,12 +29,17 @@ public class IgnoreCircularDependencyStrategyTest extends TestCase {
     private CircularDependencyStrategy strategy;
 
     private MockMessageLogger mockMessageImpl;
+    private MessageLoggerEngine messageLoggerEngine;
 
     protected void setUp() throws Exception {
         strategy = IgnoreCircularDependencyStrategy.getInstance();
 
         mockMessageImpl = new MockMessageLogger();
-        Message.setDefaultLogger(mockMessageImpl);
+        messageLoggerEngine = setupMockLogger(mockMessageImpl);
+    }
+
+    protected void tearDown() throws Exception {
+        resetMockLogger(messageLoggerEngine);
     }
 
     public void testLog() throws Exception {
@@ -48,4 +55,20 @@ public class IgnoreCircularDependencyStrategyTest extends TestCase {
         // should only log the circular dependency once
         assertEquals(1, mockMessageImpl.getLogs().size());
     }
+
+    private MessageLoggerEngine setupMockLogger(final MockMessageLogger mockLogger) {
+        if (mockLogger == null) {
+            return null;
+        }
+        final MessageLoggerEngine loggerEngine = IvyContext.getContext().getIvy().getLoggerEngine();
+        loggerEngine.pushLogger(mockLogger);
+        return loggerEngine;
+    }
+
+    private void resetMockLogger(final MessageLoggerEngine loggerEngine) {
+        if (loggerEngine == null) {
+            return;
+        }
+        loggerEngine.popLogger();
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da69323b/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
b/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
index 3901ce3..b37f1b4 100644
--- a/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
+++ b/test/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategyTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ivy.plugins.circular;
 
+import junit.framework.TestCase;
 import org.apache.ivy.TestHelper;
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.event.EventManager;
@@ -25,31 +26,33 @@ import org.apache.ivy.core.resolve.ResolveEngine;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.core.sort.SortEngine;
-import org.apache.ivy.util.Message;
+import org.apache.ivy.util.MessageLoggerEngine;
 import org.apache.ivy.util.MockMessageLogger;
 
-import junit.framework.TestCase;
-
 public class WarnCircularDependencyStrategyTest extends TestCase {
     private CircularDependencyStrategy strategy;
 
-    private MockMessageLogger mockMessageImpl;
+    private MessageLoggerEngine loggerEngine;
+    private MockMessageLogger mockMessageLogger;
 
     protected void setUp() throws Exception {
+        // setup a new IvyContext for each test
+        IvyContext.pushNewContext();
         strategy = WarnCircularDependencyStrategy.getInstance();
-
-        resetLogger();
+        mockMessageLogger = new MockMessageLogger();
+        loggerEngine = setupMockLogger(mockMessageLogger);
     }
 
-    private void resetLogger() {
-        mockMessageImpl = new MockMessageLogger();
-        Message.setDefaultLogger(mockMessageImpl);
+    protected void tearDown() throws Exception {
+        resetMockLogger(loggerEngine);
+        // pop the context we setup before
+        IvyContext.popContext();
     }
 
+
     public void testLog() throws Exception {
         strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.0, #B;1.0"));
-
-        mockMessageImpl.assertLogWarningContains("circular dependency found: #A;1.0->#B;1.0");
+        mockMessageLogger.assertLogWarningContains("circular dependency found: #A;1.0->#B;1.0");
     }
 
     public void testRemoveDuplicates() throws Exception {
@@ -57,28 +60,29 @@ public class WarnCircularDependencyStrategyTest extends TestCase {
         strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1, #B;1.0"));
 
         // should only log the circular dependency once
-        assertEquals(1, mockMessageImpl.getLogs().size());
+        assertEquals(1, mockMessageLogger.getWarns().size());
     }
 
     public void testRemoveDuplicates2() throws Exception {
         setResolveContext("1");
-        resetLogger();
         strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1, #B;1.0"));
         strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1, #B;1.0"));
 
         // should only log the circular dependency once
-        assertEquals(1, mockMessageImpl.getLogs().size());
+        assertEquals(1, mockMessageLogger.getWarns().size());
 
         setResolveContext("2");
-        resetLogger();
+        // clear previous logs
+        mockMessageLogger.clear();
+
         strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1, #B;1.0"));
         // should log the message
-        assertEquals(1, mockMessageImpl.getLogs().size());
+        assertEquals(1, mockMessageLogger.getWarns().size());
 
         strategy.handleCircularDependency(TestHelper.parseMridsToArray("#A;1.1, #B;1.0"));
 
         // should not log the message again
-        assertEquals(1, mockMessageImpl.getLogs().size());
+        assertEquals(1, mockMessageLogger.getWarns().size());
     }
 
     private void setResolveContext(String resolveId) {
@@ -87,4 +91,20 @@ public class WarnCircularDependencyStrategyTest extends TestCase {
             new ResolveData(new ResolveEngine(settings, new EventManager(),
                     new SortEngine(settings)), new ResolveOptions().setResolveId(resolveId)));
     }
+
+    private MessageLoggerEngine setupMockLogger(final MockMessageLogger mockLogger) {
+        if (mockLogger == null) {
+            return null;
+        }
+        final MessageLoggerEngine loggerEngine = IvyContext.getContext().getIvy().getLoggerEngine();
+        loggerEngine.pushLogger(mockLogger);
+        return loggerEngine;
+    }
+
+    private void resetMockLogger(final MessageLoggerEngine loggerEngine) {
+        if (loggerEngine == null) {
+            return;
+        }
+        loggerEngine.popLogger();
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/da69323b/test/java/org/apache/ivy/util/MockMessageLogger.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/util/MockMessageLogger.java b/test/java/org/apache/ivy/util/MockMessageLogger.java
index c38d0ef..abaf47f 100644
--- a/test/java/org/apache/ivy/util/MockMessageLogger.java
+++ b/test/java/org/apache/ivy/util/MockMessageLogger.java
@@ -66,6 +66,7 @@ public class MockMessageLogger extends AbstractMessageLogger {
     }
 
     public void clear() {
+        super.clearProblems();
         _logs.clear();
         _rawLogs.clear();
         _endProgress.clear();


Mime
View raw message