diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/BasicPluginTest.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/BasicPluginTest.java index c6391ae..c24a79a 100644 --- a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/BasicPluginTest.java +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/BasicPluginTest.java @@ -19,7 +19,13 @@ import org.junit.Test; import org.moditect.deptective.plugintest.PluginTestBase; -import org.moditect.deptective.plugintest.basic.bar.Bar; +import org.moditect.deptective.plugintest.basic.barctorcall.BarCtorCall; +import org.moditect.deptective.plugintest.basic.barfield.BarField; +import org.moditect.deptective.plugintest.basic.barlocalvar.BarLocalVar; +import org.moditect.deptective.plugintest.basic.barloopvar.BarLoopVar; +import org.moditect.deptective.plugintest.basic.barparameter.BarParameter; +import org.moditect.deptective.plugintest.basic.barretval.BarRetVal; +import org.moditect.deptective.plugintest.basic.bartypearg.BarTypeArg; import org.moditect.deptective.plugintest.basic.foo.Foo; import com.google.testing.compile.Compilation; @@ -35,14 +41,42 @@ public void shouldDetectDisallowedPackageDependence() { getConfigFileOption() ) .compile( - forTestClass(Bar.class), + forTestClass(BarCtorCall.class), + forTestClass(BarField.class), + forTestClass(BarLocalVar.class), + forTestClass(BarLoopVar.class), + forTestClass(BarParameter.class), + forTestClass(BarRetVal.class), + forTestClass(BarTypeArg.class), forTestClass(Foo.class) ); assertThat(compilation).failed(); + + // TODO https://github.com/moditect/deptective/issues/7 +// assertThat(compilation).hadErrorContaining( +// "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barctorcall" +// ); + assertThat(compilation).hadErrorContaining( + "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barfield" + ); + assertThat(compilation).hadErrorContaining( + "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barlocalvar" + ); + assertThat(compilation).hadErrorContaining( + "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barloopvar" + ); assertThat(compilation).hadErrorContaining( - "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.bar" + "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barparameter" ); + + // TODO https://github.com/moditect/deptective/issues/7 +// assertThat(compilation).hadErrorContaining( +// "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barretval" +// ); +// assertThat(compilation).hadErrorContaining( +// "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.bartypearg" +// ); } @Test @@ -54,13 +88,19 @@ public void shouldUseWarnReportingPolicy() { "-Adeptective.reportingpolicy=WARN" ) .compile( - forTestClass(Bar.class), + forTestClass(BarCtorCall.class), + forTestClass(BarField.class), + forTestClass(BarLocalVar.class), + forTestClass(BarLoopVar.class), + forTestClass(BarParameter.class), + forTestClass(BarRetVal.class), + forTestClass(BarTypeArg.class), forTestClass(Foo.class) ); assertThat(compilation).succeeded(); assertThat(compilation).hadWarningContaining( - "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.bar" + "package org.moditect.deptective.plugintest.basic.foo does not read org.moditect.deptective.plugintest.basic.barfield" ); } } diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barctorcall/BarCtorCall.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barctorcall/BarCtorCall.java new file mode 100644 index 0000000..2a6c0b6 --- /dev/null +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barctorcall/BarCtorCall.java @@ -0,0 +1,20 @@ +/** + * Copyright 2019 The ModiTect authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.moditect.deptective.plugintest.basic.barctorcall; + +public class BarCtorCall { + +} diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/bar/Bar.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barfield/BarField.java similarity index 88% rename from javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/bar/Bar.java rename to javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barfield/BarField.java index 054c68d..c1257ef 100644 --- a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/bar/Bar.java +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barfield/BarField.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.moditect.deptective.plugintest.basic.bar; +package org.moditect.deptective.plugintest.basic.barfield; -public class Bar { +public class BarField { } diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barlocalvar/BarLocalVar.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barlocalvar/BarLocalVar.java new file mode 100644 index 0000000..ab7b264 --- /dev/null +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barlocalvar/BarLocalVar.java @@ -0,0 +1,20 @@ +/** + * Copyright 2019 The ModiTect authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.moditect.deptective.plugintest.basic.barlocalvar; + +public class BarLocalVar { + +} diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barloopvar/BarLoopVar.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barloopvar/BarLoopVar.java new file mode 100644 index 0000000..76b3dff --- /dev/null +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barloopvar/BarLoopVar.java @@ -0,0 +1,20 @@ +/** + * Copyright 2019 The ModiTect authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.moditect.deptective.plugintest.basic.barloopvar; + +public class BarLoopVar { + +} diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barparameter/BarParameter.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barparameter/BarParameter.java new file mode 100644 index 0000000..6108e21 --- /dev/null +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barparameter/BarParameter.java @@ -0,0 +1,20 @@ +/** + * Copyright 2019 The ModiTect authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.moditect.deptective.plugintest.basic.barparameter; + +public class BarParameter { + +} diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barretval/BarRetVal.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barretval/BarRetVal.java new file mode 100644 index 0000000..d5da0e2 --- /dev/null +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/barretval/BarRetVal.java @@ -0,0 +1,20 @@ +/** + * Copyright 2019 The ModiTect authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.moditect.deptective.plugintest.basic.barretval; + +public class BarRetVal { + +} diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/bartypearg/BarTypeArg.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/bartypearg/BarTypeArg.java new file mode 100644 index 0000000..e15d75d --- /dev/null +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/bartypearg/BarTypeArg.java @@ -0,0 +1,20 @@ +/** + * Copyright 2019 The ModiTect authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.moditect.deptective.plugintest.basic.bartypearg; + +public class BarTypeArg { + +} diff --git a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/foo/Foo.java b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/foo/Foo.java index 03cb873..cf49bf6 100644 --- a/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/foo/Foo.java +++ b/javac-plugin/src/test/java/org/moditect/deptective/plugintest/basic/foo/Foo.java @@ -15,10 +15,37 @@ */ package org.moditect.deptective.plugintest.basic.foo; -import org.moditect.deptective.plugintest.basic.bar.Bar; +import java.util.ArrayList; +import java.util.List; + +import org.moditect.deptective.plugintest.basic.barctorcall.BarCtorCall; +import org.moditect.deptective.plugintest.basic.barfield.BarField; +import org.moditect.deptective.plugintest.basic.barlocalvar.BarLocalVar; +import org.moditect.deptective.plugintest.basic.barloopvar.BarLoopVar; +import org.moditect.deptective.plugintest.basic.barparameter.BarParameter; +import org.moditect.deptective.plugintest.basic.barretval.BarRetVal; +import org.moditect.deptective.plugintest.basic.bartypearg.BarTypeArg; public class Foo { private String s; - private final Bar bar = new Bar(); + private final BarField bar = new BarField(); + + public Foo(BarParameter bar) { + } + + public BarRetVal doSomething(BarParameter bar) { + BarLocalVar varLocalVar = new BarLocalVar(); + + List bars = new ArrayList<>(); + + for (BarLoopVar oneBar : new ArrayList()) { + } + + new BarCtorCall(); + + return null; + } + + } diff --git a/javac-plugin/src/test/resources/org/moditect/deptective/plugintest/basic/deptective.json b/javac-plugin/src/test/resources/org/moditect/deptective/plugintest/basic/deptective.json index 78418d6..0c4339d 100644 --- a/javac-plugin/src/test/resources/org/moditect/deptective/plugintest/basic/deptective.json +++ b/javac-plugin/src/test/resources/org/moditect/deptective/plugintest/basic/deptective.json @@ -1,12 +1,31 @@ { "packages" : [ { - "name" : "org.moditect.deptective.plugintest.basic.bar" + "name" : "org.moditect.deptective.plugintest.basic.barctorcall" + }, + { + "name" : "org.moditect.deptective.plugintest.basic.barfield" + }, + { + "name" : "org.moditect.deptective.plugintest.basic.barlocalvar" + }, + { + "name" : "org.moditect.deptective.plugintest.basic.barloopvar" + }, + { + "name" : "org.moditect.deptective.plugintest.basic.barparameter" + }, + { + "name" : "org.moditect.deptective.plugintest.basic.barretval" + }, + { + "name" : "org.moditect.deptective.plugintest.basic.bartypearg" }, { "name" : "org.moditect.deptective.plugintest.basic.foo", "reads" : [ - "java.lang" + "java.lang", + "java.util" ] } ]