creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pottlin...@apache.org
Subject svn commit: r1681876 - in /creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat: analysis/AnalyserFactoryTest.java test/utils/Resources.java
Date Tue, 26 May 2015 22:04:21 GMT
Author: pottlinger
Date: Tue May 26 22:04:20 2015
New Revision: 1681876

URL: http://svn.apache.org/r1681876
Log:
RAT-202: Reverting IntelliJ induced changes in resource handling.

* Solved the local problem to run tests in apache-rat-core in IntelliJ by
  changing the folder structure locally.
* Now only ant tasks fail (separate mail to dev@).


Modified:
    creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java
    creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java

Modified: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java?rev=1681876&r1=1681875&r2=1681876&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java
Tue May 26 22:04:20 2015
@@ -33,9 +33,6 @@ import static org.junit.Assert.assertEqu
 
 public class AnalyserFactoryTest {
 
-    // Marks where to insert a path prefix to make tests run from within IntelliJ due to
different path settings
-    private static String INFIX_MARKER = "UNDER_INTELLIJ_THERE_IS_A_SUBDIRECTORY_HERE";
-
     private static final IHeaderMatcher MATCHES_NOTHING_MATCHER = new IHeaderMatcher() {
         public boolean match(Document subject, String line) throws RatHeaderAnalysisException
{
             return false;
@@ -52,18 +49,18 @@ public class AnalyserFactoryTest {
     @Before
     public void setUp() throws Exception {
         out = new StringWriter();
-        XmlWriter writer = new XmlWriter(out);
+        final XmlWriter writer = new XmlWriter(out);
         reporter = new SimpleXmlClaimReporter(writer);
         analyser = DefaultAnalyserFactory.createDefaultAnalyser(MATCHES_NOTHING_MATCHER);
     }
 
     @Test
     public void standardTypeAnalyser() throws Exception {
-        MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/Text.txt"));
+        final MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/Text.txt"));
         analyser.analyse(document);
         reporter.report(document);
-        assertEqualsWithPathInfix("Open standard element", //
-                "<resource name='" + INFIX_MARKER + "src/test/resources/elements/Text.txt'><header-sample>/*\n"
+
+        assertEquals("Open standard element", //
+                "<resource name='src/test/resources/elements/Text.txt'><header-sample>/*\n"
+
                         " * Licensed to the Apache Software Foundation (ASF) under one\n"
+
                         " * or more contributor license agreements.  See the NOTICE file\n"
+
                         " * distributed with this work for additional information\n" +
@@ -84,56 +81,37 @@ public class AnalyserFactoryTest {
                         "\n" +
                         "            \n" +
                         "</header-sample><header-type name='?????'/><license-family
name='?????'/><type name='standard'/>", out.toString());
-
     }
 
     @Test
     public void noteTypeAnalyser() throws Exception {
-        MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/LICENSE"));
+        final MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/LICENSE"));
         analyser.analyse(document);
         reporter.report(document);
-        assertEqualsWithPathInfix("Open note element", "<resource name='" + INFIX_MARKER
+ "src/test/resources/elements/LICENSE'><type name='notice'/>", out.toString());
+        assertEquals("Open note element", "<resource name='src/test/resources/elements/LICENSE'><type
name='notice'/>", out.toString());
     }
 
     @Test
     public void binaryTypeAnalyser() throws Exception {
-        MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/Image.png"));
+        final MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/Image.png"));
         analyser.analyse(document);
         reporter.report(document);
-        assertEqualsWithPathInfix("Open binary element", "<resource name='" + INFIX_MARKER
+ "src/test/resources/elements/Image.png'><type name='binary'/>", out.toString());
+        assertEquals("Open binary element", "<resource name='src/test/resources/elements/Image.png'><type
name='binary'/>", out.toString());
     }
 
     @Test
     public void archiveTypeAnalyser() throws Exception {
-        MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/dummy.jar"));
+        final MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/dummy.jar"));
         analyser.analyse(document);
         reporter.report(document);
-        assertEqualsWithPathInfix("Open archive element", "<resource name='" + INFIX_MARKER
+ "src/test/resources/elements/dummy.jar'><type name='archive'/>", out.toString());
+        assertEquals("Open archive element", "<resource name='src/test/resources/elements/dummy.jar'><type
name='archive'/>", out.toString());
     }
 
     @Test
     public void archiveTypeAnalyserIntelliJ() throws Exception {
-        MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/dummy.jar"));
+        final MonolithicFileDocument document = new MonolithicFileDocument(Resources.getResourceFile("/elements/dummy.jar"));
         analyser.analyse(document);
         reporter.report(document);
-        assertEqualsWithPathInfix("Open archive element", "<resource name='" + INFIX_MARKER
+ "src/test/resources/elements/dummy.jar'><type name='archive'/>", out.toString());
-    }
-
-    private static void assertEqualsWithPathInfix(final String messagePrefix, final String
expectedWithMarker, final String actual) {
-        // if the given string is parameter expectedWithMarker is <code>null</code>,
-        // the test code fails with NPE since it's used in a wrong way.
-
-        boolean anyMatch = true;
-        foundMatch:
-        for (String marker : Resources.INTELLIJ_PROJECT_PREFIXES) {
-            if (actual.equals(expectedWithMarker)) {
-                anyMatch = false;
-                break foundMatch;
-            }
-        }
-
-        if (!anyMatch) {
-            assertEquals(messagePrefix, expectedWithMarker.replaceAll(INFIX_MARKER, ""),
actual);
-        }
+        assertEquals("Open archive element", "<resource name='src/test/resources/elements/dummy.jar'><type
name='archive'/>", out.toString());
     }
 }

Modified: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java?rev=1681876&r1=1681875&r2=1681876&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/test/utils/Resources.java
Tue May 26 22:04:20 2015
@@ -29,8 +29,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
-import java.util.Arrays;
-import java.util.List;
 
 
 /**
@@ -45,9 +43,6 @@ public class Resources {
         // Does nothing
     }
 
-    // If started in IntelliJ the working directory is different, thus tests are not running
through
-    public static final List<String> INTELLIJ_PROJECT_PREFIXES = Arrays.asList("",
"apache-rat-core/" /*,"apache-rat-plugin/"*/);
-
     public static final String SRC_TEST_RESOURCES = "src/test/resources";
     public static final String SRC_MAIN_RESOURCES = "src/main/resources";
     private static File TEST_RESOURCE_BASE_PATH = new File(SRC_TEST_RESOURCES);
@@ -73,17 +68,7 @@ public class Resources {
     private static File getResourceFromBase(File baseDir, String pResource) throws IOException
{
         File f = new File(baseDir, pResource);
         if (!f.isFile()) {
-            // try IntelliJ workaround before giving up
-            for (String prefix : INTELLIJ_PROJECT_PREFIXES) {
-                f = new File(new File(prefix + baseDir.getPath()), pResource);
-                System.out.println("Trying: " + f.getAbsolutePath());
-                if (!f.isFile()) continue;
-            }
-
-            if (!f.isFile()) {
-                throw new FileNotFoundException("Unable to locate resource file: " + pResource);
-            }
-
+            throw new FileNotFoundException("Unable to locate resource file: " + pResource);
         }
         return f;
     }
@@ -95,16 +80,7 @@ public class Resources {
     public static File[] getResourceFiles(String pResource) throws IOException {
         File f = new File(TEST_RESOURCE_BASE_PATH, pResource);
         if (!f.isDirectory()) {
-            // try IntelliJ workaround before giving up
-            for (String prefix : INTELLIJ_PROJECT_PREFIXES) {
-                f = new File(new File(prefix + TEST_RESOURCE_BASE_PATH.getPath()), pResource);
-                System.out.println("Trying: " + f.getAbsolutePath());
-                if (!f.isDirectory()) continue;
-            }
-
-            if (!f.isDirectory()) {
-                throw new FileNotFoundException("Unable to locate resource directory: " +
pResource);
-            }
+            throw new FileNotFoundException("Unable to locate resource directory: " + pResource);
         }
 
         return f.listFiles(new FileFilter() {



Mime
View raw message