[slf4j-dev] svn commit: r934 - in slf4j/trunk/slf4j-converter/src: main/java/org/slf4j/converter test/java/org/slf4j/converter

jncharpin at slf4j.org jncharpin at slf4j.org
Fri Nov 9 19:40:35 CET 2007


Author: jncharpin
Date: Fri Nov  9 19:40:34 2007
New Revision: 934

Added:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionException.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/Log4jMatcherTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java
Modified:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Log4jMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java

Log:
On going work on graphical user interface
Introducing Log4J to SLF4J conversion 
Testing that running a particuliar conversion has no unexpected impact on other log implementation

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionException.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionException.java	Fri Nov  9 19:40:34 2007
@@ -0,0 +1,39 @@
+package org.slf4j.converter;
+
+public class ConversionException extends Exception {
+
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 498961799888576668L;
+
+  private String detail;
+
+  public static final String NOT_IMPLEMENTED = "Conversion mode not implemented yet";
+  public static final String INVALID_DIRECTORY = "Invalid source directory";
+  public static final String FILE_COPY = "Error during file copy";
+
+  public ConversionException(String message) {
+    super(message);
+  }
+
+  public ConversionException(String message, String detail) {
+    super(message);
+    this.detail = detail;
+  }
+
+  public String getDetail() {
+    return detail;
+  }
+
+  public void setDetail(String detail) {
+    this.detail = detail;
+  }
+
+  public void print() {
+    if (getMessage() != null) {
+      System.out.println(getMessage());
+    }
+  }
+
+}

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java	Fri Nov  9 19:40:34 2007
@@ -19,9 +19,11 @@
   private AbstractMatcher matcher;
 
   private Writer writer;
-  
+
   private File fileSource;
 
+  private List<ConversionException> exception;
+
   /**
    * Run JCL to SLF4J conversion
    * 
@@ -34,8 +36,8 @@
 
     Converter converter = new Converter();
 
-    new ConverterFrame(converter);
-
+    ConverterFrame frame = new ConverterFrame(converter);
+    frame.setVisible(true);
   }
 
   /**
@@ -49,13 +51,16 @@
   public boolean init(String source, int conversionType) {
     matcher = AbstractMatcher.getMatcherImpl(conversionType);
     if (matcher == null) {
+      addException(new ConversionException(ConversionException.NOT_IMPLEMENTED));
       return false;
     }
 
-    writer = new Writer();
+    writer = new Writer(this);
 
     fileSource = new File(source);
     if (!fileSource.isDirectory()) {
+      addException(new ConversionException(
+          ConversionException.INVALID_DIRECTORY));
       return false;
     } else {
       return true;
@@ -98,13 +103,14 @@
         channelSource.close();
         channelDest.close();
       } else {
-        System.out.println("error copying file " + fsource.getAbsolutePath());
+        addException(new ConversionException(ConversionException.FILE_COPY,
+            fsource.getAbsolutePath()));
       }
 
     } catch (FileNotFoundException exc) {
-      System.out.println(exc.toString());
+      addException(new ConversionException(exc.toString()));
     } catch (IOException e) {
-      System.out.println(e.toString());
+      addException(new ConversionException(e.toString()));
     }
   }
 
@@ -136,8 +142,8 @@
   public void convert() {
     convert(javaFiles);
   }
-  
-  public int selectFiles(){
+
+  public int selectFiles() {
     return selectFiles(fileSource).size();
   }
 
@@ -182,7 +188,25 @@
         }
       }
     } catch (IOException exc) {
-      System.out.println("error reading file " + exc);
+      addException(new ConversionException(exc.toString()));
+    }
+  }
+
+  public void addException(ConversionException exc) {
+    if (exception == null) {
+      exception = new ArrayList<ConversionException>();
+    }
+    exception.add(exc);
+  }
+
+  public void printException() {
+    if (exception != null) {
+      Iterator iterator = exception.iterator();
+      while (iterator.hasNext()) {
+        ConversionException exc = (ConversionException) iterator.next();
+        exc.print();
+      }
+      exception = null;
     }
   }
 }
\ No newline at end of file

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java	Fri Nov  9 19:40:34 2007
@@ -1,64 +1,92 @@
 package org.slf4j.converter;
 
+import java.awt.BorderLayout;
 import java.awt.Dimension;
-import java.awt.FlowLayout;
 import java.awt.GridLayout;
+import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.File;
+import java.io.OutputStream;
+import java.io.PrintStream;
 
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
 
 public class ConverterFrame extends JFrame implements ActionListener {
 
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 1L;
   private Converter converter;
   private JButton butCancel;
   private JButton butNext;
   private JComboBox combo;
   private JPanel principalPan;
-  private JPanel confirmationPan;
-  private JButton butYes;
-  private JButton butNo;
+  private JPanel conversionPan;
+  private JTextArea console;
+  private JScrollPane consolePan;
+
+  private String conversionMode[] = { "JCL to SLF4J", "Log4J to SLF4J" };
 
   public ConverterFrame(Converter parent) {
     this.converter = parent;
+    buildFrame();
+    
+    ConverterStream printStream = new ConverterStream(System.out);
+    printStream.setOut(console);
+    System.setOut(printStream);
+  }
 
+  private void buildFrame() {
     setTitle("SLF4J CONVERTER");
-    // setIconImage();
-
+    // setIconImage()
+    setLocationRelativeTo(null);
+    this.setPreferredSize(new Dimension(512,384));
+    setResizable(false);
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
-    setPreferredSize(new Dimension(300, 200));
-    setLocation(100, 100);
+    buildComponents();
+  }
 
+  private void buildComponents() {
     principalPan = new JPanel();
-    FlowLayout fl = new FlowLayout();
-    principalPan.setLayout(fl);
-
-    confirmationPan = new JPanel();
-    confirmationPan.setLayout(fl);
-
+    principalPan.setLayout(new BorderLayout());
+    
+    conversionPan = new JPanel(new GridLayout(2,2,10,10));
     JLabel lab = new JLabel("Conversion Mode");
-    principalPan.add(lab);
-    String choice[] = { "JCL to SLF4J", "Log4J to SLF4J" };
-    combo = new JComboBox(choice);
-    principalPan.add(combo);
+    conversionPan.add(lab);
+
+    combo = new JComboBox(conversionMode);
+    conversionPan.add(combo);
 
     butCancel = new JButton("Cancel");
     butCancel.addActionListener(this);
-    principalPan.add(butCancel);
+    conversionPan.add(butCancel);
+    
     butNext = new JButton("Next");
     butNext.addActionListener(this);
-    principalPan.add(butNext);
-
+    conversionPan.add(butNext);
+ 
+    consolePan = new JScrollPane(); 
+    console  = new JTextArea();
+    console.setEditable(false);
+    console.setLineWrap(true);
+    console.setMargin(new Insets(5, 5, 5, 5));
+    consolePan.setViewportView(console);
+    
+    principalPan.add(conversionPan,BorderLayout.NORTH);
+    principalPan.add(consolePan, BorderLayout.CENTER);
     setContentPane(principalPan);
     pack();
-    setVisible(true);
   }
 
   public void actionPerformed(ActionEvent e) {
@@ -66,16 +94,11 @@
       dispose();
     } else if (e.getSource() == butNext) {
       showFolderSelector();
-    } else if (e.getSource() == butYes) {
-      converter.convert();
-      dispose();
-    } else if (e.getSource() == butNo) {
-      dispose();
     }
   }
 
-
-  public void showFolderSelector() {
+  
+  private void showFolderSelector() {
     JFileChooser selector = new JFileChooser();
     selector.setDialogTitle("Source folder selector");
     selector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
@@ -83,26 +106,47 @@
     if (res == JFileChooser.APPROVE_OPTION) {
       File folder = selector.getSelectedFile();
       if (!converter.init(folder.getAbsolutePath(), combo.getSelectedIndex())) {
-        return;
+        showException();
       } else {
-        showFileConversionConfirmationPan(converter.selectFiles());
+        showConfirmDialog(converter.selectFiles(), folder.getAbsolutePath());
       }
     }
   }
 
-  public void showFileConversionConfirmationPan(int nbFiles) {
-    JLabel lab;
-    lab = new JLabel("RUNNING CONVERTER WILL REPLACE " + nbFiles
-        + " JAVA FILES CONTAINED IN SELECTED FOLDER, DO YOU WANT TO CONTINUE ?");
-    confirmationPan.add(lab);
-    butNo = new JButton("No");
-    butNo.addActionListener(this);
-    confirmationPan.add(butNo);
-    butYes = new JButton("Yes");
-    butYes.addActionListener(this);
-    confirmationPan.add(butYes);
-    principalPan.add(confirmationPan);
-    setSize(900, 200);
+  
+  private void showConfirmDialog(int nbFiles, String folder) {
+    int reponse = JOptionPane.showConfirmDialog(null,
+        "RUNNING CONVERTER WILL REPLACE "+nbFiles+" JAVA FILES INTO "+folder, "CONVERSION CONFIRMATION",
+        JOptionPane.YES_NO_OPTION);
+    if (reponse == JOptionPane.YES_OPTION) {
+      converter.convert();
+      showException();
+    } else {
+      dispose();
+    }
+  }
+  
+  
+  private void showException(){
+    converter.printException();
+  }
+  
+  private class ConverterStream extends PrintStream{
+
+    JTextArea console;
+    
+    public ConverterStream(OutputStream out) {
+      super(out);
+    }
+    
+    public void setOut(JTextArea console){
+      this.console = console;
+    }
+    
+    public void println(String string){
+      console.setText(console.getText() + string + "\n");
+    }
   }
+  
 
 }
\ No newline at end of file

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Log4jMatcher.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Log4jMatcher.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Log4jMatcher.java	Fri Nov  9 19:40:34 2007
@@ -1,11 +1,36 @@
 package org.slf4j.converter;
 
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+
 public class Log4jMatcher extends AbstractMatcher {
 
+  public Log4jMatcher(){
+    super();
+    initRules();
+  }
+  
   @Override
   protected void initRules() {
-    // TODO Auto-generated method stub
+    SingleConversionRule cr0 = new SingleConversionRule(Pattern
+        .compile("import\\s*+org.apache.log4j.LogManager;"),
+        "import org.slf4j.LoggerFactory;");
+
+    SingleConversionRule cr1 = new SingleConversionRule(Pattern
+        .compile("import\\s*+org.apache.log4j.Logger;"),
+        "import org.slf4j.Logger;");
+
+    SingleConversionRule cr2 = new SingleConversionRule(Pattern
+        .compile("Logger.getLogger\\("), "LoggerFactory.getLogger(");
+
+    SingleConversionRule cr3 = new SingleConversionRule(Pattern
+        .compile("LogManager.getLogger\\("), "LoggerFactory.getLogger(");
 
+    rules = new ArrayList<ConversionRule>();
+    rules.add(cr0);
+    rules.add(cr1);
+    rules.add(cr2);
+    rules.add(cr3);
   }
 
 }

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java	Fri Nov  9 19:40:34 2007
@@ -8,11 +8,14 @@
 
 public class Writer {
 
+  Converter converter;
+  
   BufferedWriter bwriter;
 
   boolean isFirstLine;
 
-  public Writer() {
+  public Writer(Converter converter) {
+    this.converter = converter;
   }
 
   public void initFileWriter(File file) {
@@ -20,8 +23,8 @@
       FileWriter fileWriter = new FileWriter(file);
       bwriter = new BufferedWriter(fileWriter);
       isFirstLine = true;
-    } catch (IOException exc) {
-      System.out.println("error creating filewriter " + file.getAbsolutePath());
+    } catch (Exception exc) {
+      converter.addException(new ConversionException(exc.toString(),file.getAbsolutePath()));
     }
   }
 
@@ -31,7 +34,7 @@
         bwriter.flush();
         bwriter.close();
       } catch (IOException e) {
-        System.out.println("error closing filewriter " + bwriter.toString());
+        converter.addException(new ConversionException(e.toString()));
       }
     }
   }
@@ -46,9 +49,8 @@
           isFirstLine = false;
         }
         bwriter.write(text);
-        // System.out.println("new entry " + text);
       } catch (IOException exc) {
-        System.out.println("error writing file " + bwriter.toString());
+        converter.addException(new ConversionException(exc.toString()));
       }
     }
   }
@@ -62,9 +64,8 @@
           isFirstLine = false;
         }
         bwriter.write(text);
-        // System.out.println("new entry " + text);
       } catch (IOException exc) {
-        System.out.println("error writing file " + bwriter.toString());
+        converter.addException(new ConversionException(exc.toString()));
       }
     }
   }

Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java	Fri Nov  9 19:40:34 2007
@@ -1,7 +1,5 @@
 package org.slf4j.converter;
 
-import java.io.IOException;
-
 import junit.framework.TestCase;
 
 public class JCLMatcherTest extends TestCase {
@@ -20,7 +18,8 @@
     JCLMatcher jclMatcher = new JCLMatcher();
     // Logger declaration and instanciation without modifier
     assertEquals("  Logger   l = LoggerFactory.getLogger(MyClass.class);",
-        jclMatcher.getReplacement("  Log   l = LogFactory.getLog(MyClass.class);"));
+        jclMatcher
+            .getReplacement("  Log   l = LogFactory.getLog(MyClass.class);"));
     // Logger declaration and instanciation with one modifier
     assertEquals(
         "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
@@ -94,7 +93,7 @@
             .getReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
   }
 
-  public void testLogDeclarationReplacement() throws IOException {
+  public void testLogDeclarationReplacement() {
     JCLMatcher jclMatcher = new JCLMatcher();
     // simple Logger declaration
     assertEquals("Logger mylog;", jclMatcher.getReplacement("Log mylog;"));
@@ -113,7 +112,7 @@
         .getReplacement("//private Log myLog;"));
   }
 
-  public void testMultiLineReplacement() throws IOException {
+  public void testMultiLineReplacement() {
     JCLMatcher jclMatcher = new JCLMatcher();
     // Logger declaration on a line
     assertEquals("protected Logger log =", jclMatcher

Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/Log4jMatcherTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/Log4jMatcherTest.java	Fri Nov  9 19:40:34 2007
@@ -0,0 +1,132 @@
+package org.slf4j.converter;
+
+import junit.framework.TestCase;
+
+public class Log4jMatcherTest extends TestCase {
+
+  public void testImportReplacement() {
+    Log4jMatcher log4jMatcher = new Log4jMatcher();
+    // LogFactory import replacement
+    assertEquals("import org.slf4j.LoggerFactory;", log4jMatcher
+        .getReplacement("import org.apache.log4j.LogManager;"));
+    // Log import replacement
+    assertEquals("import org.slf4j.Logger;", log4jMatcher
+        .getReplacement("import org.apache.log4j.Logger;"));
+  }
+
+  public void testLogManagerGetLoggerReplacement() {
+    Log4jMatcher log4jMatcher = new Log4jMatcher();
+    // Logger declaration and instanciation without modifier
+    assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement(" Logger l = LogManager.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with one modifier
+    assertEquals(
+        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("public Logger mylog=LogManager.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("public static Logger mylog1 = LogManager.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier and comment at the
+    // end of line
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);//logger instanciation and declaration",
+        log4jMatcher
+            .getReplacement("public static Logger mylog1 = LogManager.getLogger(MyClass.class);//logger instanciation and declaration"));
+    // Logger instanciation without declaration and comment at the end of line
+    assertEquals(
+        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jMatcher
+            .getReplacement(" myLog = LogManager.getLogger(MyClass.class);//logger instanciation"));
+    // commented Logger declaration and instanciation with two modifier
+    assertEquals(
+        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("//public static Logger mylog1 = LogManager.getLogger(MyClass.class);"));
+    // commented Logger instanciation without declaration
+    assertEquals(
+        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jMatcher
+            .getReplacement("// myLog = LogManager.getLogger(MyClass.class);//logger instanciation"));
+  }
+
+  public void testLoggerGetLoggerReplacement() {
+    Log4jMatcher log4jMatcher = new Log4jMatcher();
+    // Logger declaration and instanciation without modifier
+    assertEquals("Logger l = LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("Logger l = Logger.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with one modifier
+    assertEquals(
+        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("public Logger mylog=Logger.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with modifiers
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier and comment at the
+    // end of line
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); // logger instanciation and declaration",
+        log4jMatcher
+            .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class); // logger instanciation and declaration"));
+    // Logger instanciation without declaration and comment at the end of line
+    assertEquals(
+        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jMatcher
+            .getReplacement(" myLog = Logger.getLogger(MyClass.class);//logger instanciation"));
+    // commented Logger declaration and instanciation with two modifier
+    assertEquals(
+        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jMatcher
+            .getReplacement("//public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
+    // commented Logger instanciation without declaration
+    assertEquals(
+        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jMatcher
+            .getReplacement("// myLog = Logger.getLogger(MyClass.class);//logger instanciation"));
+  }
+
+  public void testLogDeclarationReplacement() {
+    Log4jMatcher log4jMatcher = new Log4jMatcher();
+    // simple Logger declaration
+    assertEquals("Logger mylog;", log4jMatcher.getReplacement("Logger mylog;"));
+    // Logger declaration with a modifier
+    assertEquals("private Logger mylog;", log4jMatcher
+        .getReplacement("private Logger mylog;"));
+
+    // Logger declaration with modifiers
+    assertEquals("public static final Logger myLog;", log4jMatcher
+        .getReplacement("public static final Logger myLog;"));
+    // Logger declaration with modifiers and comment at the end of line
+    assertEquals("public Logger myLog;//logger declaration", log4jMatcher
+        .getReplacement("public Logger myLog;//logger declaration"));
+    // commented Logger declaration
+    assertEquals("//private Logger myLog;", log4jMatcher
+        .getReplacement("//private Logger myLog;"));
+  }
+
+  public void testMultiLineReplacement()  {
+    Log4jMatcher log4jMatcher = new Log4jMatcher();
+   // Logger declaration on a line
+   assertEquals("protected Logger log =", log4jMatcher
+   .getReplacement("protected Logger log ="));
+    
+   // Logger instanciation on the next line
+   assertEquals(" LoggerFactory.getLogger(MyComponent.class);", log4jMatcher
+   .getReplacement(" LogManager.getLogger(MyComponent.class);"));
+   // Logger declaration on a line
+   assertEquals("protected Logger log ", log4jMatcher
+   .getReplacement("protected Logger log "));
+   // Logger instanciation on the next line
+   assertEquals(
+   " = LoggerFactory.getLogger(MyComponent.class);",
+   log4jMatcher
+   .getReplacement(" = LogManager.getLogger(MyComponent.class);"));
+   }
+}

Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java	Fri Nov  9 19:40:34 2007
@@ -0,0 +1,57 @@
+package org.slf4j.converter;
+
+import junit.framework.TestCase;
+
+public class NoConversionTest extends TestCase {
+
+  /**
+   * This test shows that performing JCL to SLF4J conversion has no impact on
+   * Log4j implementation
+   */
+  public void testJclOverLog4jConversion() {
+    // running jcl to slf4j conversion
+    JCLMatcher jclMatcher = new JCLMatcher();
+    // no changes on log4j.LogManager import
+    assertEquals("import org.apache.log4j.LogManager;", jclMatcher
+        .getReplacement("import org.apache.log4j.LogManager;"));
+    // no changes on log4j.Logger import
+    assertEquals("import org.apache.log4j.Logger;", jclMatcher
+        .getReplacement("import org.apache.log4j.Logger;"));
+    // no changes on Logger instanciation using LogManager
+    assertEquals(
+        "Logger log = LogManager.getLogger(MyClass.class);",
+        jclMatcher
+            .getReplacement("Logger log = LogManager.getLogger(MyClass.class);"));
+    // no changes on Logger instanciation using Logger.getLogger
+    assertEquals(
+        "public static Logger mylog1 = Logger.getLogger(MyClass.class);",
+        jclMatcher
+            .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
+  }
+
+  /**
+   * This test shows that performing Log4j to SLF4J conversion has no impact on
+   * JCL implementation
+   */
+  public void testLog4jOverJclConversion() {
+    // running log4j to slf4j conversion
+    Log4jMatcher log4jMatcher = new Log4jMatcher();
+    // no changes on LogFactory import
+    assertEquals("import org.apache.commons.logging.LogFactory;", log4jMatcher
+        .getReplacement("import org.apache.commons.logging.LogFactory;"));
+    // no changes on Log import
+    assertEquals("import org.apache.commons.logging.Log;", log4jMatcher
+        .getReplacement("import org.apache.commons.logging.Log;"));
+    // no changes on Log instanciation using Logfactory.getLog
+    assertEquals(
+        "public static Log mylog1 = LogFactory.getLog(MyClass.class);",
+        log4jMatcher
+            .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
+    // no changes on log instanciation using LogFactory.getFactory().getInstance
+    assertEquals(
+        "public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);",
+        log4jMatcher
+            .getReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
+
+  }
+}

Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java	Fri Nov  9 19:40:34 2007
@@ -35,6 +35,8 @@
     suite.addTestSuite(TrivialMatcherTest.class);
     suite.addTestSuite(JCLMatcherTest.class);
     suite.addTestSuite(AternativeApproach.class);
+    suite.addTestSuite(Log4jMatcherTest.class);
+    suite.addTestSuite(NoConversionTest.class);
     return suite;
   }
 }
\ No newline at end of file

Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java	Fri Nov  9 19:40:34 2007
@@ -1,24 +1,21 @@
 package org.slf4j.converter;
 
-
 import junit.framework.TestCase;
 
-public class TrivialMatcherTest  extends TestCase {
+public class TrivialMatcherTest extends TestCase {
 
-  
-  
   public void testSimpleReplacement() {
     TrivialMatcher trivialMatcher = new TrivialMatcher();
     trivialMatcher.initRules();
-    
-    // "import org.slf4j.converter" -- > simple replacement with an unique capturing group
-    assertEquals("simple replacement with an unique capturing group", 
+
+    // "import org.slf4j.converter" -- > simple replacement with an unique
+    // capturing group
+    assertEquals("simple replacement with an unique capturing group",
         trivialMatcher.getReplacement("import org.slf4j.converter"));
-    
-    assertEquals("1st group second group 4th group", 
-        trivialMatcher.getReplacement("first group second group third group 4th group"));
-    
+
+    assertEquals("1st group second group 4th group", trivialMatcher
+        .getReplacement("first group second group third group 4th group"));
+
   }
-  
-  
+
 }



More information about the slf4j-dev mailing list