Author: pottlinger
Date: Sat May 23 20:54:29 2015
New Revision: 1681382
URL: http://svn.apache.org/r1681382
Log:
RAT-202: Make tests run from within IntelliJ
* Apart from loading the resources via Resources.java
the assertions need to adapt flexibly in case the test
runs from within IntelliJ
* Working directory differs from IDE thus 'apache-rat-core'
needs to be added flexibly to expectations.
Modified:
creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.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=1681382&r1=1681381&r2=1681382&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
Sat May 23 20:54:29 2015
@@ -33,6 +33,9 @@ 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;
@@ -59,27 +62,28 @@ public class AnalyserFactoryTest {
MonolithicFileDocument document = new
MonolithicFileDocument(Resources.getResourceFile("/elements/Text.txt"));
analyser.analyse(document);
reporter.report(document);
- 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" +
- " * regarding copyright ownership. The ASF licenses this
file\n" +
- " * to you under the Apache License, Version 2.0 (the
\"License\");\n" +
- " * you may not use this file except in compliance with the
License.\n" +
- " * You may obtain a copy of the License at\n" +
- " *\n" +
- " * http://www.apache.org/licenses/LICENSE-2.0\n" +
- " *\n" +
- " * Unless required by applicable law or agreed to in
writing,\n" +
- " * software distributed under the License is distributed on
an\n" +
- " * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
ANY\n" +
- " * KIND, either express or implied. See the License for
the\n" +
- " * specific language governing permissions and limitations\n"
+
- " * under the License. \n" +
- " */\n" +
- "\n" +
- " \n" +
- "</header-sample><header-type name='?????'/><license-family
name='?????'/><type name='standard'/>", out.toString());
+ assertEqualsWithPathInfix("Open standard element", //
+ "<resource name='" + INFIX_MARKER +
"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" +
+ " * regarding copyright ownership. The ASF licenses
this file\n" +
+ " * to you under the Apache License, Version 2.0 (the
\"License\");\n" +
+ " * you may not use this file except in compliance
with the License.\n" +
+ " * You may obtain a copy of the License at\n" +
+ " *\n" +
+ " * http://www.apache.org/licenses/LICENSE-2.0\n" +
+ " *\n" +
+ " * Unless required by applicable law or agreed to in
writing,\n" +
+ " * software distributed under the License is
distributed on an\n" +
+ " * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY\n" +
+ " * KIND, either express or implied. See the License
for the\n" +
+ " * specific language governing permissions and
limitations\n" +
+ " * under the License. \n" +
+ " */\n" +
+ "\n" +
+ " \n" +
+ "</header-sample><header-type
name='?????'/><license-family name='?????'/><type name='standard'/>",
out.toString());
}
@@ -88,7 +92,7 @@ public class AnalyserFactoryTest {
MonolithicFileDocument document = new
MonolithicFileDocument(Resources.getResourceFile("/elements/LICENSE"));
analyser.analyse(document);
reporter.report(document);
- assertEquals("Open note element", "<resource
name='src/test/resources/elements/LICENSE'><type name='notice'/>",
out.toString());
+ assertEqualsWithPathInfix("Open note element", "<resource name='" +
INFIX_MARKER + "src/test/resources/elements/LICENSE'><type name='notice'/>",
out.toString());
}
@Test
@@ -96,7 +100,7 @@ public class AnalyserFactoryTest {
MonolithicFileDocument document = new
MonolithicFileDocument(Resources.getResourceFile("/elements/Image.png"));
analyser.analyse(document);
reporter.report(document);
- assertEquals("Open binary element", "<resource
name='src/test/resources/elements/Image.png'><type name='binary'/>",
out.toString());
+ assertEqualsWithPathInfix("Open binary element", "<resource name='" +
INFIX_MARKER + "src/test/resources/elements/Image.png'><type name='binary'/>",
out.toString());
}
@Test
@@ -104,11 +108,32 @@ public class AnalyserFactoryTest {
MonolithicFileDocument document = new
MonolithicFileDocument(Resources.getResourceFile("/elements/dummy.jar"));
analyser.analyse(document);
reporter.report(document);
- assertEquals("Open archive element", "<resource
name='src/test/resources/elements/dummy.jar'><type name='archive'/>",
out.toString());
+ assertEqualsWithPathInfix("Open archive element", "<resource name='" +
INFIX_MARKER + "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"));
+ 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());
}
- // TODO make tests run from within IntelliJ
- private static void equalsWithPathInfixOrNot(String messagePrefix, String
expectedWithMarker, String actual) {
- // TODO use Resources.INTELLIJ_PROJECT_PREFIXES and provide an either
with/without equals to match test results
+ 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);
+ }
}
}