diff options
Diffstat (limited to 'slf4j-migrator')
23 files changed, 120 insertions, 138 deletions
diff --git a/slf4j-migrator/LICENSE.txt b/slf4j-migrator/LICENSE.txt new file mode 100644 index 00000000..1a3d0532 --- /dev/null +++ b/slf4j-migrator/LICENSE.txt @@ -0,0 +1,24 @@ +Copyright (c) 2004-2022 QOS.ch Sarl (Switzerland) +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + diff --git a/slf4j-migrator/pom.xml b/slf4j-migrator/pom.xml index 33ad8e98..98ef9ddb 100755 --- a/slf4j-migrator/pom.xml +++ b/slf4j-migrator/pom.xml @@ -1,14 +1,14 @@ -<project - xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.slf4j</groupId> <artifactId>slf4j-parent</artifactId> - <version>1.7.13-SNAPSHOT</version> + <version>2.0.12</version> + <relativePath>../parent/pom.xml</relativePath> </parent> <artifactId>slf4j-migrator</artifactId> @@ -17,30 +17,23 @@ <name>SLF4J Migrator</name> <description>SLF4J Migrator</description> - <build> <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>${required.jdk.version}</source> - <target>${required.jdk.version}</target> - </configuration> - </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> + <version>${maven-jar-plugin.version}</version> <configuration> <archive> - <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + <manifest> + <mainClass>org.slf4j.migrator.Main</mainClass> + </manifest> </archive> </configuration> </plugin> </plugins> - </build> -</project>
\ No newline at end of file +</project> diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/FileSelector.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/FileSelector.java index 71af29bd..0e8d13c8 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/FileSelector.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/FileSelector.java @@ -32,7 +32,7 @@ import org.slf4j.migrator.internal.ProgressListener; public class FileSelector { - private List<File> javaFileList = new ArrayList<File>(); + private final List<File> javaFileList = new ArrayList<>(); ProgressListener pl; @@ -54,8 +54,8 @@ public class FileSelector { pl.onDirectory(file); File[] files = file.listFiles(); if (files != null) { - for (int i = 0; i < files.length; i++) { - selectFiles(files[i]); + for (File value : files) { + selectFiles(value); } } } else { diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/InplaceFileConverter.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/InplaceFileConverter.java index d4bf3e63..cecb1be8 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/InplaceFileConverter.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/InplaceFileConverter.java @@ -102,8 +102,8 @@ public class InplaceFileConverter { } private void writeReplacement(OutputStream os, String[] replacement) throws IOException { - for (int i = 0; i < replacement.length; i++) { - os.write(replacement[i].getBytes()); + for (String s : replacement) { + os.write(s.getBytes()); os.write(lineTerminator.getBytes()); } } diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/Main.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/Main.java index 5a94a41d..bbb1b9cc 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/Main.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/Main.java @@ -38,12 +38,10 @@ public class Main { public static void main(String[] args) { System.out.println("Starting SLF4J Migrator"); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - MigratorFrame inst = new MigratorFrame(); - inst.setLocationRelativeTo(null); - inst.setVisible(true); - } + SwingUtilities.invokeLater(() -> { + MigratorFrame inst = new MigratorFrame(); + inst.setLocationRelativeTo(null); + inst.setVisible(true); }); } diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/ProjectConverter.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/ProjectConverter.java index 99f1a194..f7947577 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/ProjectConverter.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/ProjectConverter.java @@ -27,7 +27,6 @@ package org.slf4j.migrator; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.swing.SwingUtilities; @@ -38,25 +37,23 @@ import org.slf4j.migrator.line.RuleSet; public class ProjectConverter { - private RuleSet ruleSet; + private final RuleSet ruleSet; private List<ConversionException> exception; ProgressListener progressListener; - public static void main(String[] args) throws IOException { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - MigratorFrame inst = new MigratorFrame(); - inst.setLocationRelativeTo(null); - inst.setVisible(true); - } + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + MigratorFrame inst = new MigratorFrame(); + inst.setLocationRelativeTo(null); + inst.setVisible(true); }); } /** * Ask for concrete matcher implementation depending on the conversion mode * Ask for user confirmation to convert the selected source directory if valid - * Ask for user confirmation in case of number of files to convert > 1000 + * Ask for user confirmation in case of number of files to convert > 1000 * * @param conversionType * @param progressListener @@ -83,9 +80,7 @@ public class ProjectConverter { */ private void scanFileList(List<File> lstFiles) { progressListener.onFileScanBegin(); - Iterator<File> itFile = lstFiles.iterator(); - while (itFile.hasNext()) { - File currentFile = itFile.next(); + for (File currentFile : lstFiles) { progressListener.onFileScan(currentFile); scanFile(currentFile); } @@ -108,16 +103,14 @@ public class ProjectConverter { public void addException(ConversionException exc) { if (exception == null) { - exception = new ArrayList<ConversionException>(); + exception = new ArrayList<>(); } exception.add(exc); } public void printException() { if (exception != null) { - Iterator<ConversionException> iterator = exception.iterator(); - while (iterator.hasNext()) { - ConversionException exc = (ConversionException) iterator.next(); + for (ConversionException exc : exception) { exc.print(); } exception = null; diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java index f2f9b35d..519a3f04 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/helper/Abbreviator.java @@ -44,11 +44,11 @@ public class Abbreviator { int firstIndex = filename.indexOf(folderSeparator, invariantPrefixLength); if (firstIndex == -1) { - // we cant't process this string + // we can't process this string return filename; } StringBuilder buf = new StringBuilder(desiredLength); - buf.append(filename.substring(0, firstIndex + 1)); + buf.append(filename, 0, firstIndex + 1); buf.append(FILLER); int nextIndex = computeNextIndex(filename, firstIndex); if (nextIndex != -1) { diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/internal/MigratorFrame.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/internal/MigratorFrame.java index 377ac6e5..3ab15c60 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/internal/MigratorFrame.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/internal/MigratorFrame.java @@ -46,16 +46,6 @@ import javax.swing.WindowConstants; import org.slf4j.migrator.Constant; import org.slf4j.migrator.helper.SpringLayoutHelper; -/** - * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI - * Builder, which is free for non-commercial use. If Jigloo is being used - * commercially (ie, by a corporation, company or business for any purpose - * whatever) then you should purchase a license for each developer using Jigloo. - * Please visit www.cloudgarden.com for details. Use of Jigloo implies - * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN - * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR - * ANY CORPORATE OR COMMERCIAL PURPOSE. - */ public class MigratorFrame extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; @@ -68,8 +58,8 @@ public class MigratorFrame extends JFrame implements ActionListener { static final int X_SIZE = 700; static final int Y_SIZE = 400; - private SpringLayout layoutManager = new SpringLayout(); - private SpringLayoutHelper slh = new SpringLayoutHelper(layoutManager, BASIC_PADDING); + private final SpringLayout layoutManager = new SpringLayout(); + private final SpringLayoutHelper slh = new SpringLayoutHelper(layoutManager, BASIC_PADDING); private JLabel migrationLabel; @@ -138,7 +128,7 @@ public class MigratorFrame extends JFrame implements ActionListener { */ private void constrainAll() { - // contrain migration label + // constraints migration label layoutManager.putConstraint(SpringLayout.WEST, migrationLabel, BASIC_PADDING, SpringLayout.EAST, this); layoutManager.putConstraint(SpringLayout.NORTH, migrationLabel, BASIC_PADDING, SpringLayout.NORTH, this); @@ -239,14 +229,14 @@ public class MigratorFrame extends JFrame implements ActionListener { private void createAwareLabel() { awareLabel = new JLabel(); - awareLabel.setText("<html>" + "<p>I am aware that this tool will directly modify all Java source files</p>" - + "<p>in the selected folder without creating backup files.</p>" + "</html>"); + awareLabel.setText("<html>" + "<p>I am aware that this tool will directly modify all Java source files" + + "<p>in the selected folder without creating backup files." + "</html>"); } private void createWarningLabel() { warningLabel = new JLabel(); - warningLabel.setText("<html>" + "<p><span color=\"red\">WARNING:</span> This SLF4J migration tool will directly modify all Java source files</p>" - + "<p>in the selected project folder without creating a backup of the original files.</p>" + "</html>"); + warningLabel.setText("<html>" + "<p><span color=\"red\">WARNING:</span> This SLF4J migration tool will directly modify all Java source files" + + "<p>in the selected project folder without creating a backup of the original files." + "</html>"); } private void createMigrateButton() { @@ -323,7 +313,7 @@ public class MigratorFrame extends JFrame implements ActionListener { List<String> doSanityAnalysis() { - List<String> errorList = new ArrayList<String>(); + List<String> errorList = new ArrayList<>(); if (!radioJCL.isSelected() && !radioLog4j.isSelected() && !radioJUL.isSelected()) { errorList.add("Please select the migration type: JCL, log4j, or JUL to SLF4J."); } @@ -351,7 +341,7 @@ public class MigratorFrame extends JFrame implements ActionListener { buf.append(i); buf.append(". "); buf.append(msg); - buf.append("</p>"); + buf.append(""); i++; } buf.append("</html>"); diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/EmptyRuleSet.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/EmptyRuleSet.java index a0393265..3533d0e3 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/EmptyRuleSet.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/EmptyRuleSet.java @@ -30,7 +30,7 @@ import java.util.List; public class EmptyRuleSet implements RuleSet { - List<ConversionRule> list = new ArrayList<ConversionRule>(); + List<ConversionRule> list = new ArrayList<>(); public Iterator<ConversionRule> iterator() { return list.iterator(); diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JCLRuleSet.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JCLRuleSet.java index f463e46d..8367d508 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JCLRuleSet.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JCLRuleSet.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; */ public class JCLRuleSet implements RuleSet { - private ArrayList<ConversionRule> conversionRuleList; + private final ArrayList<ConversionRule> conversionRuleList; public JCLRuleSet() { // matching : import org.apache.commons.logging.LogFactory; @@ -54,7 +54,7 @@ public class JCLRuleSet implements RuleSet { SingleConversionRule cr5 = new SingleConversionRule(Pattern.compile("LogFactory.getLog\\("), "LoggerFactory.getLogger("); - conversionRuleList = new ArrayList<ConversionRule>(); + conversionRuleList = new ArrayList<>(); conversionRuleList.add(cr0); conversionRuleList.add(cr1); conversionRuleList.add(cr2); diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JULRuleSet.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JULRuleSet.java index b296b70a..da5f3378 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JULRuleSet.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/JULRuleSet.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; */ public class JULRuleSet implements RuleSet { - private ArrayList<ConversionRule> conversionRuleList; + private final ArrayList<ConversionRule> conversionRuleList; public JULRuleSet() { @@ -55,7 +55,7 @@ public class JULRuleSet implements RuleSet { SingleConversionRule crWarning = new SingleConversionRule(Pattern.compile("\\.warning\\("), ".warn("); SingleConversionRule crSevere = new SingleConversionRule(Pattern.compile("\\.severe\\("), ".error("); - conversionRuleList = new ArrayList<ConversionRule>(); + conversionRuleList = new ArrayList<>(); conversionRuleList.add(crImport0); conversionRuleList.add(crImport1); conversionRuleList.add(crImport2); diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/Log4jRuleSet.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/Log4jRuleSet.java index c760496c..e07aa73a 100755 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/Log4jRuleSet.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/Log4jRuleSet.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; public class Log4jRuleSet implements RuleSet { - private ArrayList<ConversionRule> conversionRuleList; + private final ArrayList<ConversionRule> conversionRuleList; public Log4jRuleSet() { @@ -57,7 +57,7 @@ public class Log4jRuleSet implements RuleSet { SingleConversionRule variable1 = new SingleConversionRule(Pattern.compile("(^Category\\b)"), "Logger"); - conversionRuleList = new ArrayList<ConversionRule>(); + conversionRuleList = new ArrayList<>(); conversionRuleList.add(crImport0); conversionRuleList.add(catImport); conversionRuleList.add(crImport1); diff --git a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/MultiGroupConversionRule.java b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/MultiGroupConversionRule.java index ce1ee520..f0769406 100644 --- a/slf4j-migrator/src/main/java/org/slf4j/migrator/line/MultiGroupConversionRule.java +++ b/slf4j-migrator/src/main/java/org/slf4j/migrator/line/MultiGroupConversionRule.java @@ -40,8 +40,8 @@ public class MultiGroupConversionRule implements ConversionRule { // our conversion reg-expressions final private static int MAX_GROUPS = 10; - private Pattern pattern; - private String[] replacementTable = new String[MAX_GROUPS]; + private final Pattern pattern; + private final String[] replacementTable = new String[MAX_GROUPS]; public MultiGroupConversionRule(Pattern pattern) { this.pattern = pattern; diff --git a/slf4j-migrator/src/main/resources/META-INF/MANIFEST.MF b/slf4j-migrator/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 10f5bdf3..00000000 --- a/slf4j-migrator/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1 +0,0 @@ -Main-Class: org.slf4j.migrator.Main
\ No newline at end of file diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/AternativeApproach.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/AternativeApproach.java index d4b090a2..0626b871 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/AternativeApproach.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/AternativeApproach.java @@ -34,7 +34,7 @@ import junit.framework.TestCase; public class AternativeApproach extends TestCase { /** - * In this test we see that we cans use more simple Pattern to do the + * In this test we see that we can use more simple Pattern to do the * conversion * */ @@ -55,7 +55,7 @@ public class AternativeApproach extends TestCase { /** * In this test we replace, using the simple Pattern (Log), the full Log - * declaration and instanciation. This is not convenient because we will also + * declaration and instantiation. This is not convenient because we will also * replace all String containing "Log". */ public void test2() { @@ -82,7 +82,7 @@ public class AternativeApproach extends TestCase { } /** - * In this test we use a simple Pattern to replace the log instanciation + * In this test we use a simple Pattern to replace the log instantiation * without influence on Log declaration. * */ @@ -101,7 +101,7 @@ public class AternativeApproach extends TestCase { /** * In this test we try to replace keyword Log without influence on String - * containg Log We see that we have to use two differents Patterns + * containing Log We see that we have to use two different Patterns */ public void test4() { Pattern pat = Pattern.compile("(\\sLog\\b)"); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java index 9f3eb461..4e1b1382 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/FileConverterTest.java @@ -27,29 +27,15 @@ package org.slf4j.migrator; import java.io.File; import java.io.IOException; -import junit.framework.TestCase; - -import org.slf4j.migrator.InplaceFileConverter; +import org.junit.Ignore; +import org.junit.Test; import org.slf4j.migrator.internal.NopProgressListener; import org.slf4j.migrator.line.EmptyRuleSet; -public class FileConverterTest extends TestCase { - - public FileConverterTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void test() { - } +public class FileConverterTest { + @Test + @Ignore public void XtestNOP() throws IOException { InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet(), new NopProgressListener()); fc.convert(new File("c:/varargs.txt")); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java index a8cee0bf..537ba3f4 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/ProjectConverterTest.java @@ -26,17 +26,17 @@ package org.slf4j.migrator; import java.io.File; -import org.slf4j.migrator.Constant; -import org.slf4j.migrator.ProjectConverter; +import org.junit.Ignore; +import org.junit.Test; import org.slf4j.migrator.internal.NopProgressListener; -import junit.framework.TestCase; - -public class ProjectConverterTest extends TestCase { +public class ProjectConverterTest { public void test() { } + @Test + @Ignore public void XtestBarracuda() { ProjectConverter pc = new ProjectConverter(Constant.LOG4J_TO_SLF4J, new NopProgressListener()); File projectFolder = new File("c:/home/ceki//Varia/Barracuda"); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java index ab8c8cbb..ac470b88 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/AbbreviatorTest.java @@ -24,11 +24,12 @@ */ package org.slf4j.migrator.helper; -import org.slf4j.migrator.helper.Abbreviator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.junit.Test; -public class AbbreviatorTest extends TestCase { +public class AbbreviatorTest { static final char FS = '/'; static final String INPUT_0 = "/abc/123456/ABC"; @@ -36,18 +37,7 @@ public class AbbreviatorTest extends TestCase { RandomHelper rh = new RandomHelper(FS); - public AbbreviatorTest(String arg0) { - super(arg0); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testSmoke() { { Abbreviator abb = new Abbreviator(2, 100, FS); @@ -67,6 +57,7 @@ public class AbbreviatorTest extends TestCase { } } + @Test public void testImpossibleToAbbreviate() { Abbreviator abb = new Abbreviator(2, 20, FS); String in = "iczldqwivpgm/mgrmvbjdxrwmqgprdjusth"; @@ -74,6 +65,7 @@ public class AbbreviatorTest extends TestCase { assertEquals(in, r); } + @Test public void testNoFS() { Abbreviator abb = new Abbreviator(2, 100, FS); String r = abb.abbreviate("hello"); @@ -81,6 +73,7 @@ public class AbbreviatorTest extends TestCase { } + @Test public void testZeroPrefix() { { Abbreviator abb = new Abbreviator(0, 100, FS); @@ -89,6 +82,7 @@ public class AbbreviatorTest extends TestCase { } } + @Test public void testTheories() { int MAX_RANDOM_FIXED_LEN = 20; int MAX_RANDOM_AVG_LEN = 20; diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/RandomHelper.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/RandomHelper.java index 1928daaa..f0e304ca 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/RandomHelper.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/helper/RandomHelper.java @@ -28,7 +28,7 @@ import java.util.Random; public class RandomHelper { - private Random random = new Random(100); + private final Random random = new Random(100); final char folderSeparator; RandomHelper(char folderSeparator) { diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java index 442b0cf6..f480229a 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/JCLRuleSetTest.java @@ -24,15 +24,15 @@ */ package org.slf4j.migrator.line; -import org.slf4j.migrator.line.JCLRuleSet; -import org.slf4j.migrator.line.LineConverter; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; -public class JCLRuleSetTest extends TestCase { +public class JCLRuleSetTest { LineConverter jclConverter = new LineConverter(new JCLRuleSet()); + @Test public void testImportReplacement() { // LogFactory import replacement assertEquals("import org.slf4j.LoggerFactory;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.LogFactory;")); @@ -40,6 +40,7 @@ public class JCLRuleSetTest extends TestCase { assertEquals("import org.slf4j.Logger;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.Log;")); } + @Test public void testLogFactoryGetLogReplacement() { // Logger declaration and instanciation without modifier assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);", @@ -65,6 +66,7 @@ public class JCLRuleSetTest extends TestCase { jclConverter.getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation")); } + @Test public void testLogFactoryGetFactoryReplacement() { // Logger declaration and instanciation without modifier @@ -91,6 +93,7 @@ public class JCLRuleSetTest extends TestCase { jclConverter.getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation")); } + @Test public void testLogDeclarationReplacement() { // simple Logger declaration @@ -106,6 +109,7 @@ public class JCLRuleSetTest extends TestCase { assertEquals("//private Logger myLog;", jclConverter.getOneLineReplacement("//private Log myLog;")); } + @Test public void testMultiLineReplacement() { // Logger declaration on a line assertEquals("protected Logger log =", jclConverter.getOneLineReplacement("protected Log log =")); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java index 7160193b..60b1fdbf 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/NoConversionTest.java @@ -24,18 +24,17 @@ */ package org.slf4j.migrator.line; -import org.slf4j.migrator.line.JCLRuleSet; -import org.slf4j.migrator.line.LineConverter; -import org.slf4j.migrator.line.Log4jRuleSet; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; -public class NoConversionTest extends TestCase { +public class NoConversionTest { /** * This test shows that performing JCL to SLF4J conversion has no impact on * Log4j implementation */ + @Test public void testJclOverLog4jConversion() { // running jcl to slf4j conversion // JCLMatcher jclMatcher = @@ -56,6 +55,7 @@ public class NoConversionTest extends TestCase { * This test shows that performing Log4j to SLF4J conversion has no impact on * JCL implementation */ + @Test public void testLog4jOverJclConversion() { // running log4j to slf4j conversion LineConverter log4jConverter = new LineConverter(new Log4jRuleSet()); diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcher.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcher.java index d392769b..032bddca 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcher.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcher.java @@ -35,23 +35,23 @@ import org.slf4j.migrator.line.SingleConversionRule; class TrivialMatcher implements RuleSet { - private ArrayList<ConversionRule> conversionRuleList; + private final ArrayList<ConversionRule> conversionRuleList; public TrivialMatcher() { // simple rule no capturing group is defined, we use default capturing group which is group zero SingleConversionRule cr = new SingleConversionRule(Pattern.compile("import org.slf4j.converter"), "simple replacement with an unique capturing group"); - // we define 4 differents capturing groups + // we define 4 different capturing groups MultiGroupConversionRule cr1 = new MultiGroupConversionRule(Pattern.compile("(first group)( second group)( third group)( 4th group)")); // group zero is ignored during treatment // replacement for the first cr1.addReplacement(1, "1st group"); - // no replacement for the second group it will remains the same + // no replacement for the second group it will remain the same // empty string for the third group it will be deleted cr1.addReplacement(3, ""); - // no replacement for the third group it will remains the same + // no replacement for the third group it will remain the same - conversionRuleList = new ArrayList<ConversionRule>(); + conversionRuleList = new ArrayList<>(); conversionRuleList.add(cr); conversionRuleList.add(cr1); } @@ -60,4 +60,4 @@ class TrivialMatcher implements RuleSet { return conversionRuleList.iterator(); } -}
\ No newline at end of file +} diff --git a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java index b5b3c6d4..0a9194df 100644 --- a/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java +++ b/slf4j-migrator/src/test/java/org/slf4j/migrator/line/TrivialMatcherTest.java @@ -24,12 +24,13 @@ */ package org.slf4j.migrator.line; -import org.slf4j.migrator.line.LineConverter; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import org.junit.Test; -public class TrivialMatcherTest extends TestCase { +public class TrivialMatcherTest { + @Test public void testSimpleReplacement() { LineConverter trivialLC = new LineConverter(new TrivialMatcher()); |