Skip to content

Commit 9879a47

Browse files
authored
Merge pull request #31 from scijava/fix-licensed-integration-tests
Fix integration test licensing through test rewrites
2 parents 4b50b16 + 647cd3a commit 9879a47

File tree

1,738 files changed

+168
-22687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,738 files changed

+168
-22687
lines changed

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
<license.licenseName>bsd_2</license.licenseName>
138138
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
139139
<license.projectName>A plugin for managing SciJava-based projects.</license.projectName>
140-
<license.excludes>**/fitnesse-target/**</license.excludes>
141140

142141
<jdepend.version>2.9.5</jdepend.version>
143142
<jgrapht.version>0.8.3</jgrapht.version>

src/test/java/org/scijava/maven/plugin/enforcer/NoPackageCyclesRuleIntegrationTest.java

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -56,54 +56,67 @@
5656
import java.io.IOException;
5757
import java.net.URISyntaxException;
5858
import java.net.URL;
59+
import java.nio.charset.Charset;
5960

6061
import org.apache.commons.io.IOUtils;
6162
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
6263
import org.junit.Before;
6364
import org.junit.Test;
6465

66+
/**
67+
* Tests {@link NoPackageCyclesRule} on a dummy project
68+
* @author Gabriel Selzer
69+
*/
6570
public class NoPackageCyclesRuleIntegrationTest {
66-
private static final URL FITNESSE_TARGET_FOLDER = getResource("fitnesse-target");
67-
private static final URL FITNESSE_EXPECTED_OUTPUT = getResource("fitnesse-expected-output-package-cycle.txt");
68-
private static final URL JUNIT_TARGET_FOLDER = getResource("junit-target");
69-
private static final URL JUNIT_EXPECTED_OUTPUT = getResource("junit-expected-output-package-cycle.txt");
70-
71-
private NoPackageCyclesRule rule;
72-
private EnforcerRuleHelperMock helper;
73-
74-
@Before
75-
public void setUp() throws Exception {
76-
rule = new NoPackageCyclesRule();
77-
helper = new EnforcerRuleHelperMock();
78-
}
71+
// Cyclic dependency test files
72+
private static final URL CYCLIC_TARGET_FOLDER = getResource("cyclic-target");
73+
private static final URL CYCLIC_EXPECTED_OUTPUT = getResource("cyclic-expected-output.txt");
74+
// Control test files
75+
private static final URL CONTROL_TARGET_FOLDER = getResource("control-target");
7976

80-
@Test
81-
public void fitnesseIntegrationTest() throws Exception {
82-
assertPackageCycles(FITNESSE_TARGET_FOLDER, FITNESSE_EXPECTED_OUTPUT);
83-
}
77+
private NoPackageCyclesRule rule;
78+
private EnforcerRuleHelperMock helper;
8479

85-
@Test
86-
public void junitIntegrationTest() throws Exception {
87-
assertPackageCycles(JUNIT_TARGET_FOLDER, JUNIT_EXPECTED_OUTPUT);
88-
}
80+
@Before
81+
public void setUp() throws Exception {
82+
rule = new NoPackageCyclesRule();
83+
helper = new EnforcerRuleHelperMock();
84+
}
8985

90-
private void assertPackageCycles(URL targetFolder, URL expectedOutput) throws URISyntaxException, IOException {
91-
helper.setTestClassesDir(new File("non-existent"));
92-
helper.setClassesDir(new File(targetFolder.toURI()));
93-
try {
94-
rule.execute(helper);
95-
fail("expected EnforcerRuleException");
96-
} catch (EnforcerRuleException e) {
97-
// using assertEquals to get a nice comparison editor in eclipse
98-
assertEquals(getExpectedOutput(expectedOutput), e.getMessage());
99-
}
100-
}
86+
/**
87+
* Test that package cycles throw an error
88+
*/
89+
@Test
90+
public void cyclicIntegrationTest() throws URISyntaxException, IOException {
91+
helper.setTestClassesDir(new File("non-existent"));
92+
helper.setClassesDir(new File(CYCLIC_TARGET_FOLDER.toURI()));
93+
try {
94+
rule.execute(helper);
95+
fail("expected EnforcerRuleException");
96+
} catch (EnforcerRuleException e) {
97+
String expected = IOUtils.toString(CYCLIC_EXPECTED_OUTPUT.openStream(), (Charset) null) //
98+
.replaceAll("\r", "") //
99+
.trim();
100+
String actual = e.getMessage().trim();
101+
assertEquals(expected, actual);
102+
}
103+
}
101104

102-
private String getExpectedOutput(URL expectedOutput) throws IOException {
103-
return IOUtils.toString(expectedOutput.openStream()).replaceAll("\r", "");
104-
}
105+
/**
106+
* Test no error thrown for acyclic package structure
107+
*/
108+
@Test
109+
public void controlIntegrationTest() throws URISyntaxException {
110+
helper.setTestClassesDir(new File("non-existent"));
111+
helper.setClassesDir(new File(CONTROL_TARGET_FOLDER.toURI()));
112+
try {
113+
rule.execute(helper);
114+
} catch (EnforcerRuleException e) {
115+
fail("expected EnforcerRuleException");
116+
}
117+
}
105118

106-
private static URL getResource(String path) {
107-
return Thread.currentThread().getContextClassLoader().getResource(path);
108-
}
119+
private static URL getResource(String path) {
120+
return Thread.currentThread().getContextClassLoader().getResource(path);
121+
}
109122
}

src/test/java/org/scijava/maven/plugin/enforcer/NoSubpackageDependenceRuleIntegrationTest.java

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -56,54 +56,70 @@
5656
import java.io.IOException;
5757
import java.net.URISyntaxException;
5858
import java.net.URL;
59+
import java.nio.charset.Charset;
5960

6061
import org.apache.commons.io.IOUtils;
6162
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
6263
import org.junit.Before;
6364
import org.junit.Test;
6465

66+
/**
67+
* Tests {@link NoSubpackageDependenceRule} on a dummy project
68+
* @author Gabriel Selzer
69+
*/
6570
public class NoSubpackageDependenceRuleIntegrationTest {
66-
private static final URL FITNESSE_TARGET_FOLDER = getResource("fitnesse-target");
67-
private static final URL FITNESSE_EXPECTED_OUTPUT = getResource("fitnesse-expected-output-subpackage-dependence.txt");
68-
private static final URL JUNIT_TARGET_FOLDER = getResource("junit-target");
69-
private static final URL JUNIT_EXPECTED_OUTPUT = getResource("junit-expected-output-subpackage-dependence.txt");
71+
// Subpackage dependence test files
72+
private static final URL SUBPACKAGE_DEPENDENT_TARGET_FOLDER = //
73+
getResource("subpackage-dependent-target");
74+
private static final URL SUBPACKAGE_DEPENDENT_EXPECTED_OUTPUT = //
75+
getResource("subpackage-dependent-expected-output.txt");
76+
// Control test files
77+
private static final URL CONTROL_TARGET_FOLDER = getResource("control-target");
7078

71-
private NoSubpackageDependenceRule rule;
72-
private EnforcerRuleHelperMock helper;
79+
private NoSubpackageDependenceRule rule;
80+
private EnforcerRuleHelperMock helper;
7381

74-
@Before
75-
public void setUp() throws Exception {
76-
rule = new NoSubpackageDependenceRule();
77-
helper = new EnforcerRuleHelperMock();
78-
}
82+
@Before
83+
public void setUp() throws Exception {
84+
rule = new NoSubpackageDependenceRule();
85+
helper = new EnforcerRuleHelperMock();
86+
}
7987

80-
@Test
81-
public void fitnesseIntegrationTest() throws Exception {
82-
assertPackageCycles(FITNESSE_TARGET_FOLDER, FITNESSE_EXPECTED_OUTPUT);
83-
}
88+
/**
89+
* Test that a subpackage dependence throws an error
90+
*/
91+
@Test
92+
public void subpackageDependentIntegrationTest() throws URISyntaxException, IOException {
93+
helper.setTestClassesDir(new File("non-existent"));
94+
helper.setClassesDir(new File(SUBPACKAGE_DEPENDENT_TARGET_FOLDER.toURI()));
95+
try {
96+
rule.execute(helper);
97+
fail("expected EnforcerRuleException");
98+
} catch (EnforcerRuleException e) {
99+
String expected = IOUtils.toString(SUBPACKAGE_DEPENDENT_EXPECTED_OUTPUT.openStream(), (Charset) null) //
100+
.replaceAll("\r", "") //
101+
.trim();
102+
String actual = e.getMessage().trim();
103+
assertEquals(expected, actual);
104+
}
105+
}
84106

85-
@Test
86-
public void junitIntegrationTest() throws Exception {
87-
assertPackageCycles(JUNIT_TARGET_FOLDER, JUNIT_EXPECTED_OUTPUT);
88-
}
107+
/**
108+
* Test no error thrown for no subpackage dependence
109+
*/
110+
@Test
111+
public void controlIntegrationTest() throws URISyntaxException {
112+
helper.setTestClassesDir(new File("non-existent"));
113+
helper.setClassesDir(new File(CONTROL_TARGET_FOLDER.toURI()));
114+
try {
115+
rule.execute(helper);
116+
} catch (EnforcerRuleException e) {
117+
fail("expected EnforcerRuleException");
118+
}
119+
}
89120

90-
private void assertPackageCycles(URL targetFolder, URL expectedOutput) throws URISyntaxException, IOException {
91-
helper.setTestClassesDir(new File("non-existent"));
92-
helper.setClassesDir(new File(targetFolder.toURI()));
93-
try {
94-
rule.execute(helper);
95-
fail("expected EnforcerRuleException");
96-
} catch (EnforcerRuleException e) {
97-
// using assertEquals to get a nice comparison editor in eclipse
98-
assertEquals(getExpectedOutput(expectedOutput), e.getMessage());
99-
}
100-
}
101-
102-
private String getExpectedOutput(URL expectedOutput) throws IOException {
103-
return IOUtils.toString(expectedOutput.openStream()).replaceAll("\r", "");
104-
}
105-
106-
private static URL getResource(String path) {
107-
return Thread.currentThread().getContextClassLoader().getResource(path);
108-
}
121+
private static URL getResource(String path) {
122+
return Thread.currentThread().getContextClassLoader().getResource(path);
123+
}
109124
}
125+
196 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example.foo;
2+
3+
public class Foo {
4+
public Foo() {}
5+
}
246 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.foo.bar;
2+
3+
import com.example.foo.Foo;
4+
5+
public class Bar {
6+
public Bar() {
7+
final Foo foo = new Foo();
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
There are package cycles:
2+
3+
Package-cycle found involving com.example.bar, com.example.foo:
4+
com.example.bar depends on:
5+
com.example.foo (Bar)
6+
com.example.foo depends on:
7+
com.example.bar (Foo)
242 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.bar;
2+
3+
import com.example.foo.Foo;
4+
5+
public class Bar {
6+
public Bar() {
7+
final Foo foo = new Foo();
8+
}
9+
}

0 commit comments

Comments
 (0)