[logback-dev] svn commit: r1155 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Jan 4 14:48:32 CET 2007


Author: seb
Date: Thu Jan  4 14:48:32 2007
New Revision: 1155

Added:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java
Modified:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java

Log:
Added unit testing for OptionHelper's substVars method

Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java	Thu Jan  4 14:48:32 2007
@@ -0,0 +1,96 @@
+package ch.qos.logback.core.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class OptionHelperTest extends TestCase {
+
+  String text = "Testing ${v1} variable substitution ${v2}";
+  String expected = "Testing if variable substitution works";
+  Map<String, String> primaryMap;
+  Map<String, String> secondaryMap;
+  
+  
+  
+  @Override
+  protected void setUp() throws Exception {
+    primaryMap = new HashMap<String, String>();
+    secondaryMap = new HashMap<String, String>();
+    super.setUp();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    primaryMap = null;
+    primaryMap = null;
+    super.tearDown();
+  }
+
+  public void testSubstVarsNoSubstitution() {
+    String noSubst = "testing if it works";
+    
+    String result = OptionHelper.substVars(noSubst, null, null);
+    assertEquals(noSubst, result);
+  }
+ 
+  public void testSubstVarsVariableNotClosed() {
+    String noSubst = "testing if ${v1 works";
+    
+    try {
+      @SuppressWarnings("unused")
+      String result = OptionHelper.substVars(noSubst, null, null);
+      fail();
+    } catch (IllegalArgumentException e) {
+      //ok
+    }
+  }
+  
+  public void testSubstVarsPrimaryOnly() {
+    primaryMap.put("v1", "if");
+    primaryMap.put("v2", "works");
+    
+    String result = OptionHelper.substVars(text, primaryMap, null);
+    assertEquals(expected, result); 
+  }
+  
+  public void testSubstVarsPrimaryAndSecondary() { 
+    primaryMap.put("v1", "if");
+    secondaryMap.put("v2", "works");
+    
+    String result = OptionHelper.substVars(text, primaryMap, secondaryMap);
+    assertEquals(expected, result); 
+  }
+  
+  
+  public void testSubstVarsSystemProperties() { 
+    System.setProperty("v1", "if");
+    System.setProperty("v2", "works");
+    
+    String result = OptionHelper.substVars(text, null, null);
+    assertEquals(expected, result); 
+    
+    System.clearProperty("v1");
+    System.clearProperty("v2");
+  }
+  
+  public void testSubstVarsWithDefault() {   
+    primaryMap.put("v1", "if");
+    String textWithDefault = "Testing ${v1} variable substitution ${v2:-toto}";
+    String resultWithDefault = "Testing if variable substitution toto";
+    
+    String result = OptionHelper.substVars(textWithDefault, primaryMap, null);
+    assertEquals(resultWithDefault, result); 
+  }
+  
+  public void testSubstVarsRecursive() {
+    primaryMap.put("v1", "if");
+    primaryMap.put("v2", "${v3}");
+    primaryMap.put("v3", "works");
+    
+    String result = OptionHelper.substVars(text, primaryMap, null);
+    assertEquals(expected, result); 
+  }
+  
+}

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java	Thu Jan  4 14:48:32 2007
@@ -20,7 +20,9 @@
     TestSuite suite = new TestSuite();
     suite.addTestSuite(DurationTest.class);
     suite.addTestSuite(FileSizeTest.class);
+    suite.addTestSuite(OptionHelperTest.class);
     suite.addTestSuite(PropertySetterTest.class);
+    suite.addTestSuite(StatusPrinterTest.class);
     suite.addTestSuite(TimeUtilTest.class);
     return suite;
   }



More information about the logback-dev mailing list