From f79dd434a1a30558b97a33f9acf718de7df3145f Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 22:36:04 +0300 Subject: [PATCH 01/30] Create BaseDomainTest --- demo/src/test/java/NoPackageDomainTest.java | 31 ++++----- .../metter/demo/BaseDomainTest.java | 65 +++++++++++++++++++ 2 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java diff --git a/demo/src/test/java/NoPackageDomainTest.java b/demo/src/test/java/NoPackageDomainTest.java index 0b251c7..f944567 100644 --- a/demo/src/test/java/NoPackageDomainTest.java +++ b/demo/src/test/java/NoPackageDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,36 +14,29 @@ * limitations under the License. */ +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -public class NoPackageDomainTest { +public class NoPackageDomainTest extends BaseDomainTest { @Test public void should_contains_allGetters() { - Map> getterByField = new NoPackageDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 1", 1, getterByField.size()); - assertTrue("Map not contain getter for 'integer' field", getterByField.containsKey("integer")); + Map> getterByField = getGetterMap(new NoPackageDomainGetterSupplier()); + assertSize(getterByField, 1); + assertGetterFields(getterByField, "integer"); NoPackageDomain domain = new NoPackageDomain(1); - assertEquals("Getter for 'integer' field returns wrong value", - 1, getterByField.get("integer").apply(domain)); + assertGetterValue(getterByField, domain, "integer", 1); } @Test public void should_contains_allSetters() { - Map> setterByField = new NoPackageDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 1", 1, setterByField.size()); - assertTrue("Map not contain setter for 'integer' field", setterByField.containsKey("integer")); - NoPackageDomain domain = new NoPackageDomain(0); - setterByField.get("integer").accept(domain, 1); - assertEquals("Setter for 'integer' field sets wrong value", 1, domain.getInteger()); + Map> setterByField = getSetterMap(new NoPackageDomainSetterSupplier()); + assertSize(setterByField, 1); + assertSetterFields(setterByField, "integer"); + NoPackageDomain domain = new NoPackageDomain(1); + assertSetterValue(setterByField, domain, "integer", 10, NoPackageDomain::getInteger); } } \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java new file mode 100644 index 0000000..4e6fb86 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.Supplier; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public abstract class BaseDomainTest { + protected Map> getGetterMap(Supplier>> domainGetterSupplier) { + Map> getterByField = domainGetterSupplier.get(); + assertNotNull("Map is null", getterByField); + return getterByField; + } + + protected Map> getSetterMap(Supplier>> domainSetterSupplier) { + Map> setterByField = domainSetterSupplier.get(); + assertNotNull("Map is null", setterByField); + return setterByField; + } + + protected void assertSize(Map map, int size) { + assertEquals("Map size is incorrect", size, map.size()); + } + + protected void assertGetterFields(Map> getterByField, String... fields) { + for (String field : fields) { + assertTrue("Map not contain getter for field '" + field + "'", getterByField.containsKey(field)); + } + } + + protected void assertSetterFields(Map> setterByField, String... fields) { + for (String field : fields) { + assertTrue("Map not contain setter for field '" + field + "'", setterByField.containsKey(field)); + } + } + + protected void assertGetterValue(Map> getterByField, T domain, String field, Object value) { + assertEquals("Getter for field '" + field + "' returns wrong value", value, getterByField.get(field).apply(domain)); + } + + protected void assertSetterValue(Map> setterByField, T domain, String field, Object value, Function getter) { + setterByField.get(field).accept(domain, value); + assertEquals("Setter for field '" + field + "' sets wrong value", value, getter.apply(domain)); + } +} From a9aef4108b19b98fc5b0716fe8fef8f159dfb06f Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 22:36:14 +0300 Subject: [PATCH 02/30] Create tests on inheritance --- .../metter/demo/inheritance/FatherDomain.java | 38 +++++++++++++++ .../demo/inheritance/GrandsonDomain.java | 39 +++++++++++++++ .../metter/demo/inheritance/SonDomain.java | 39 +++++++++++++++ .../demo/inheritance/FatherDomainTest.java | 44 +++++++++++++++++ .../demo/inheritance/GrandsonDomainTest.java | 48 +++++++++++++++++++ .../demo/inheritance/SonDomainTest.java | 46 ++++++++++++++++++ 6 files changed, 254 insertions(+) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/inheritance/FatherDomain.java create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomain.java create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/inheritance/SonDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/inheritance/FatherDomainTest.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomainTest.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/inheritance/SonDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/FatherDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/FatherDomain.java new file mode 100644 index 0000000..f370e78 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/FatherDomain.java @@ -0,0 +1,38 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.inheritance; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier +@SetterSupplier +public class FatherDomain { + private int fatherInt; + + public FatherDomain(int fatherInt) { + this.fatherInt = fatherInt; + } + + public int getFatherInt() { + return fatherInt; + } + + public void setFatherInt(int fatherInt) { + this.fatherInt = fatherInt; + } +} diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomain.java new file mode 100644 index 0000000..75c69c2 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomain.java @@ -0,0 +1,39 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.inheritance; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier +@SetterSupplier +public class GrandsonDomain extends SonDomain { + private int grandsonInt; + + public GrandsonDomain(int fatherInt, int sonInt, int grandsonInt) { + super(fatherInt, sonInt); + this.grandsonInt = grandsonInt; + } + + public int getGrandsonInt() { + return grandsonInt; + } + + public void setGrandsonInt(int grandsonInt) { + this.grandsonInt = grandsonInt; + } +} diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/SonDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/SonDomain.java new file mode 100644 index 0000000..59687e9 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/inheritance/SonDomain.java @@ -0,0 +1,39 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.inheritance; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier +@SetterSupplier +public class SonDomain extends FatherDomain { + private int sonInt; + + public SonDomain(int fatherInt, int sonInt) { + super(fatherInt); + this.sonInt = sonInt; + } + + public int getSonInt() { + return sonInt; + } + + public void setSonInt(int sonInt) { + this.sonInt = sonInt; + } +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/FatherDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/FatherDomainTest.java new file mode 100644 index 0000000..6aa3089 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/FatherDomainTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.inheritance; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class FatherDomainTest extends BaseDomainTest { + @Test + public void should_contains_allGettersWithSuper() { + Map> getterByField = getGetterMap(new FatherDomainGetterSupplier()); + assertSize(getterByField, 1); + assertGetterFields(getterByField, "fatherInt"); + FatherDomain domain = new FatherDomain(1); + assertGetterValue(getterByField, domain, "fatherInt", 1); + } + + @Test + public void should_contains_allSettersWithSuper() { + Map> setterByField = getSetterMap(new FatherDomainSetterSupplier()); + assertSize(setterByField, 1); + assertSetterFields(setterByField, "fatherInt"); + FatherDomain domain = new FatherDomain(1); + assertSetterValue(setterByField, domain, "fatherInt", 10, FatherDomain::getFatherInt); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomainTest.java new file mode 100644 index 0000000..c329856 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/GrandsonDomainTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.inheritance; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class GrandsonDomainTest extends BaseDomainTest { + @Test + public void should_contains_allGettersWithSuper() { + Map> getterByField = getGetterMap(new GrandsonDomainGetterSupplier()); + assertSize(getterByField, 3); + assertGetterFields(getterByField, "fatherInt", "sonInt", "grandsonInt"); + GrandsonDomain domain = new GrandsonDomain(1, 2, 3); + assertGetterValue(getterByField, domain, "fatherInt", 1); + assertGetterValue(getterByField, domain, "sonInt", 2); + assertGetterValue(getterByField, domain, "grandsonInt", 3); + } + + @Test + public void should_contains_allSettersWithSuper() { + Map> setterByField = getSetterMap(new GrandsonDomainSetterSupplier()); + assertSize(setterByField, 3); + assertSetterFields(setterByField, "fatherInt", "sonInt", "grandsonInt"); + GrandsonDomain domain = new GrandsonDomain(1, 2, 3); + assertSetterValue(setterByField, domain, "fatherInt", 10, GrandsonDomain::getFatherInt); + assertSetterValue(setterByField, domain, "sonInt", 20, GrandsonDomain::getSonInt); + assertSetterValue(setterByField, domain, "grandsonInt", 30, GrandsonDomain::getGrandsonInt); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/SonDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/SonDomainTest.java new file mode 100644 index 0000000..8539260 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/inheritance/SonDomainTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.inheritance; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class SonDomainTest extends BaseDomainTest { + @Test + public void should_contains_allGettersWithSuper() { + Map> getterByField = getGetterMap(new SonDomainGetterSupplier()); + assertSize(getterByField, 2); + assertGetterFields(getterByField, "fatherInt", "sonInt"); + SonDomain domain = new SonDomain(1, 2); + assertGetterValue(getterByField, domain, "fatherInt", 1); + assertGetterValue(getterByField, domain, "sonInt", 2); + } + + @Test + public void should_contains_allSettersWithSuper() { + Map> setterByField = getSetterMap(new SonDomainSetterSupplier()); + assertSize(setterByField, 2); + assertSetterFields(setterByField, "fatherInt", "sonInt"); + SonDomain domain = new SonDomain(1, 2); + assertSetterValue(setterByField, domain, "fatherInt", 10, SonDomain::getFatherInt); + assertSetterValue(setterByField, domain, "sonInt", 20, SonDomain::getSonInt); + } +} \ No newline at end of file From 5671c741441441f698c892eb2de8a1cabc6fee6c Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 22:37:22 +0300 Subject: [PATCH 03/30] Create tests on inheritance with excluding --- .../excluding/InheritedExcludedDomain.java | 39 ++++++++++++++ .../demo/excluding/ExcludedDomainTest.java | 35 ++++++------- .../InheritedExcludedDomainTest.java | 52 +++++++++++++++++++ 3 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomain.java new file mode 100644 index 0000000..d72ee78 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomain.java @@ -0,0 +1,39 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.excluding; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier(excludedFields = {"excluded", "alsoExcluded"}) +@SetterSupplier(excludedFields = {"excluded", "alsoExcluded"}) +public class InheritedExcludedDomain extends ExcludedDomain { + private int alsoExcluded; + + public InheritedExcludedDomain(int integer, int excluded, int alsoExcluded) { + super(integer, excluded); + this.alsoExcluded = alsoExcluded; + } + + public int getAlsoExcluded() { + return alsoExcluded; + } + + public void setAlsoExcluded(int alsoExcluded) { + this.alsoExcluded = alsoExcluded; + } +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/excluding/ExcludedDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/excluding/ExcludedDomainTest.java index 9f05cd3..3c8d7cd 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/excluding/ExcludedDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/excluding/ExcludedDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package dev.alexengrig.metter.demo.excluding; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; @@ -23,32 +24,26 @@ import java.util.function.Function; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -public class ExcludedDomainTest { +public class ExcludedDomainTest extends BaseDomainTest { @Test public void should_contains_allNotExcludedGetters() { - Map> getterByField = new ExcludedDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 1", 1, getterByField.size()); - assertTrue("Map not contain getter for 'integer' field", getterByField.containsKey("integer")); - assertFalse("Map contains getter for 'excluded' field", getterByField.containsKey("excluded")); + Map> getterByField = getGetterMap(new ExcludedDomainGetterSupplier()); + assertSize(getterByField, 1); + assertGetterFields(getterByField, "integer"); ExcludedDomain domain = new ExcludedDomain(1, 2); - assertEquals("Getter for 'integer' field returns wrong value", - 1, getterByField.get("integer").apply(domain)); + assertGetterValue(getterByField, domain, "integer", 1); + assertEquals("Excluded field value is incorrect", 2, domain.getExcluded()); } @Test public void should_contains_allNotExcludedSetters() { - Map> setterByField = new ExcludedDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 1", 1, setterByField.size()); - assertTrue("Map not contain setter for 'integer' field", setterByField.containsKey("integer")); - assertFalse("Map contains setter for 'excluded' field", setterByField.containsKey("excluded")); - ExcludedDomain domain = new ExcludedDomain(0, 2); - setterByField.get("integer").accept(domain, 1); - assertEquals("Setter for 'integer' field sets wrong value", 1, domain.getInteger()); + Map> setterByField = getSetterMap(new ExcludedDomainSetterSupplier()); + assertSize(setterByField, 1); + assertSetterFields(setterByField, "integer"); + ExcludedDomain domain = new ExcludedDomain(1, 2); + assertSetterValue(setterByField, domain, "integer", 10, ExcludedDomain::getInteger); + domain.setExcluded(20); + assertEquals("Excluded field value is incorrect", 20, domain.getExcluded()); } } \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomainTest.java new file mode 100644 index 0000000..fd472ef --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomainTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.excluding; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +import static org.junit.Assert.assertEquals; + +public class InheritedExcludedDomainTest extends BaseDomainTest { + @Test + public void should_contains_allNotExcludedGettersWithSuper() { + Map> getterByField = getGetterMap(new InheritedExcludedDomainGetterSupplier()); + assertSize(getterByField, 1); + assertGetterFields(getterByField, "integer"); + InheritedExcludedDomain domain = new InheritedExcludedDomain(1, 2, 3); + assertGetterValue(getterByField, domain, "integer", 1); + assertEquals("Excluded field value is incorrect", 2, domain.getExcluded()); + assertEquals("Also excluded field value is incorrect", 3, domain.getAlsoExcluded()); + } + + @Test + public void should_contains_allNotExcludedSetters() { + Map> setterByField = getSetterMap(new InheritedExcludedDomainSetterSupplier()); + assertSize(setterByField, 1); + assertSetterFields(setterByField, "integer"); + InheritedExcludedDomain domain = new InheritedExcludedDomain(1, 2, 3); + assertSetterValue(setterByField, domain, "integer", 10, InheritedExcludedDomain::getInteger); + domain.setExcluded(20); + assertEquals("Excluded field value is incorrect", 20, domain.getExcluded()); + domain.setAlsoExcluded(30); + assertEquals("Also excluded field value is incorrect", 30, domain.getAlsoExcluded()); + } +} \ No newline at end of file From de8480011548598de3efd27033e653ba3d5b4298 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 22:45:54 +0300 Subject: [PATCH 04/30] Create tests on inheritance with including --- .../including/InheritedIncludedDomain.java | 49 +++++++++++++++++ .../demo/including/IncludedDomainTest.java | 35 ++++++------ .../InheritedIncludedDomainTest.java | 54 +++++++++++++++++++ 3 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomain.java new file mode 100644 index 0000000..d7a8c55 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomain.java @@ -0,0 +1,49 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.including; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier(includedFields = {"included", "alsoIncluded"}) +@SetterSupplier(includedFields = {"included", "alsoIncluded"}) +public class InheritedIncludedDomain extends IncludedDomain { + private int alsoIncluded; + private int alsoIgnored; + + public InheritedIncludedDomain(int included, int ignored, int alsoIncluded, int alsoIgnored) { + super(included, ignored); + this.alsoIncluded = alsoIncluded; + this.alsoIgnored = alsoIgnored; + } + + public int getAlsoIncluded() { + return alsoIncluded; + } + + public void setAlsoIncluded(int alsoIncluded) { + this.alsoIncluded = alsoIncluded; + } + + public int getAlsoIgnored() { + return alsoIgnored; + } + + public void setAlsoIgnored(int alsoIgnored) { + this.alsoIgnored = alsoIgnored; + } +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/including/IncludedDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/including/IncludedDomainTest.java index 66c062b..d1e0523 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/including/IncludedDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/including/IncludedDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package dev.alexengrig.metter.demo.including; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; @@ -23,32 +24,26 @@ import java.util.function.Function; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -public class IncludedDomainTest { +public class IncludedDomainTest extends BaseDomainTest { @Test public void should_contains_allIncludedGetters() { - Map> getterByField = new IncludedDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 1", 1, getterByField.size()); - assertTrue("Map not contain getter for 'included' field", getterByField.containsKey("included")); - assertFalse("Map contains getter for 'ignored' field", getterByField.containsKey("ignored")); + Map> getterByField = getGetterMap(new IncludedDomainGetterSupplier()); + assertSize(getterByField, 1); + assertGetterFields(getterByField, "included"); IncludedDomain domain = new IncludedDomain(1, 2); - assertEquals("Getter for 'included' field returns wrong value", - 1, getterByField.get("included").apply(domain)); + assertGetterValue(getterByField, domain, "included", 1); + assertEquals("Ignored field value is incorrect", 2, domain.getIgnored()); } @Test public void should_contains_allIncludedSetters() { - Map> setterByField = new IncludedDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 1", 1, setterByField.size()); - assertTrue("Map not contain setter for 'included' field", setterByField.containsKey("included")); - assertFalse("Map contains setter for 'ignored' field", setterByField.containsKey("ignored")); - IncludedDomain domain = new IncludedDomain(0, 2); - setterByField.get("included").accept(domain, 1); - assertEquals("Setter for 'included' field sets wrong value", 1, domain.getIncluded()); + Map> setterByField = getSetterMap(new IncludedDomainSetterSupplier()); + assertSize(setterByField, 1); + assertSetterFields(setterByField, "included"); + IncludedDomain domain = new IncludedDomain(1, 2); + assertSetterValue(setterByField, domain, "included", 10, IncludedDomain::getIncluded); + domain.setIgnored(20); + assertEquals("Ignored field value is incorrect", 20, domain.getIgnored()); } } \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomainTest.java new file mode 100644 index 0000000..b1a2d3a --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomainTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.including; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +import static org.junit.Assert.assertEquals; + +public class InheritedIncludedDomainTest extends BaseDomainTest { + @Test + public void should_contains_allIncludedGetters() { + Map> getterByField = getGetterMap(new InheritedIncludedDomainGetterSupplier()); + assertSize(getterByField, 2); + assertGetterFields(getterByField, "included", "alsoIncluded"); + InheritedIncludedDomain domain = new InheritedIncludedDomain(1, 2, 3, 4); + assertGetterValue(getterByField, domain, "included", 1); + assertGetterValue(getterByField, domain, "alsoIncluded", 3); + assertEquals("Ignored field value is incorrect", 2, domain.getIgnored()); + assertEquals("Also ignored field value is incorrect", 4, domain.getAlsoIgnored()); + } + + @Test + public void should_contains_allIncludedSetters() { + Map> setterByField = getSetterMap(new InheritedIncludedDomainSetterSupplier()); + assertSize(setterByField, 2); + assertSetterFields(setterByField, "included", "alsoIncluded"); + InheritedIncludedDomain domain = new InheritedIncludedDomain(1, 2, 3, 4); + assertSetterValue(setterByField, domain, "included", 10, InheritedIncludedDomain::getIncluded); + assertSetterValue(setterByField, domain, "alsoIncluded", 30, InheritedIncludedDomain::getAlsoIncluded); + domain.setIgnored(20); + assertEquals("Ignored field value is incorrect", 20, domain.getIgnored()); + domain.setAlsoIgnored(40); + assertEquals("Also ignored field value is incorrect", 40, domain.getAlsoIgnored()); + } +} \ No newline at end of file From 900a9bd39f4f1e2e553cf38d7502146b3f35233f Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 22:54:22 +0300 Subject: [PATCH 05/30] Create BaseDomainTest#assertEmpty --- .../test/java/dev/alexengrig/metter/demo/BaseDomainTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java index 4e6fb86..0f40b75 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/BaseDomainTest.java @@ -42,6 +42,10 @@ protected void assertSize(Map map, int size) { assertEquals("Map size is incorrect", size, map.size()); } + protected void assertEmpty(Map map) { + assertTrue("Map isn't empty", map.isEmpty()); + } + protected void assertGetterFields(Map> getterByField, String... fields) { for (String field : fields) { assertTrue("Map not contain getter for field '" + field + "'", getterByField.containsKey(field)); From e1d4e190230c974aded93c944ed97b6320f882b0 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 22:54:39 +0300 Subject: [PATCH 06/30] Create tests on inheritance with private getters and setters --- ...heritedPrivateGettersAndSettersDomain.java | 34 ++++++++++++++++ ...tedPrivateGettersAndSettersDomainTest.java | 40 +++++++++++++++++++ .../PrivateGettersAndSettersDomainTest.java | 15 ++++--- 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomain.java new file mode 100644 index 0000000..6e85349 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomain.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.privategettersandsetters; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier +@SetterSupplier +public class InheritedPrivateGettersAndSettersDomain extends PrivateGettersAndSettersDomain { + private long longer; + + private long getLonger() { + return longer; + } + + private void setLonger(long longer) { + this.longer = longer; + } +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomainTest.java new file mode 100644 index 0000000..b8ca888 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomainTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.privategettersandsetters; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class InheritedPrivateGettersAndSettersDomainTest extends BaseDomainTest { + @Test + public void should_ignores_privateGetters() { + Map> getterByField + = getGetterMap(new InheritedPrivateGettersAndSettersDomainGetterSupplier()); + assertEmpty(getterByField); + } + + @Test + public void should_ignores_privateSetters() { + Map> setterByField + = getSetterMap(new InheritedPrivateGettersAndSettersDomainSetterSupplier()); + assertEmpty(setterByField); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/PrivateGettersAndSettersDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/PrivateGettersAndSettersDomainTest.java index 214947e..f6a1dc8 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/PrivateGettersAndSettersDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/privategettersandsetters/PrivateGettersAndSettersDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,26 +16,25 @@ package dev.alexengrig.metter.demo.privategettersandsetters; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertTrue; - -public class PrivateGettersAndSettersDomainTest { +public class PrivateGettersAndSettersDomainTest extends BaseDomainTest { @Test public void should_ignores_privateGetters() { Map> getterByField - = new PrivateGettersAndSettersDomainGetterSupplier().get(); - assertTrue("Map is not empty", getterByField.isEmpty()); + = getGetterMap(new PrivateGettersAndSettersDomainGetterSupplier()); + assertEmpty(getterByField); } @Test public void should_ignores_privateSetters() { Map> setterByField - = new PrivateGettersAndSettersDomainSetterSupplier().get(); - assertTrue("Map is not empty", setterByField.isEmpty()); + = getSetterMap(new PrivateGettersAndSettersDomainSetterSupplier()); + assertEmpty(setterByField); } } From e7fa062057e8ea360b7b752fce3164efdb334178 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:14:05 +0300 Subject: [PATCH 07/30] Create tests on inheritance with including and excluding --- .../InheritedIncludedAndExcludedDomain.java | 59 +++++++++++++++++++ .../IncludedAndExcludedDomainTest.java | 42 ++++++------- 2 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomain.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomain.java new file mode 100644 index 0000000..344c016 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomain.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.includingandexcluding; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; + +@GetterSupplier(includedFields = {"included", "alsoIncluded"}, excludedFields = {"excluded", "alsoExcluded"}) +@SetterSupplier(includedFields = {"included", "alsoIncluded"}, excludedFields = {"excluded", "alsoExcluded"}) +public class InheritedIncludedAndExcludedDomain extends IncludedAndExcludedDomain { + private int alsoIncluded; + private int alsoIgnored; + private int alsoExcluded; + + public InheritedIncludedAndExcludedDomain(int included, int ignored, int excluded, int alsoIncluded, int alsoIgnored, int alsoExcluded) { + super(included, ignored, excluded); + this.alsoIncluded = alsoIncluded; + this.alsoIgnored = alsoIgnored; + this.alsoExcluded = alsoExcluded; + } + + public int getAlsoIncluded() { + return alsoIncluded; + } + + public void setAlsoIncluded(int alsoIncluded) { + this.alsoIncluded = alsoIncluded; + } + + public int getAlsoIgnored() { + return alsoIgnored; + } + + public void setAlsoIgnored(int alsoIgnored) { + this.alsoIgnored = alsoIgnored; + } + + public int getAlsoExcluded() { + return alsoExcluded; + } + + public void setAlsoExcluded(int alsoExcluded) { + this.alsoExcluded = alsoExcluded; + } +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/IncludedAndExcludedDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/IncludedAndExcludedDomainTest.java index b8c2c54..15a7593 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/IncludedAndExcludedDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/IncludedAndExcludedDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package dev.alexengrig.metter.demo.includingandexcluding; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; @@ -23,36 +24,29 @@ import java.util.function.Function; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -public class IncludedAndExcludedDomainTest { +public class IncludedAndExcludedDomainTest extends BaseDomainTest { @Test public void should_contains_allIncludedGetters() { - Map> getterByField - = new IncludedAndExcludedDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 1", 1, getterByField.size()); - assertTrue("Map not contain getter for 'included' field", getterByField.containsKey("included")); - assertFalse("Map contains getter for 'ignored' field", getterByField.containsKey("ignored")); - assertFalse("Map contains getter for 'excluded' field", getterByField.containsKey("excluded")); + Map> getterByField = getGetterMap(new IncludedAndExcludedDomainGetterSupplier()); + assertSize(getterByField, 1); + assertGetterFields(getterByField, "included"); IncludedAndExcludedDomain domain = new IncludedAndExcludedDomain(1, 2, 3); - assertEquals("Getter for 'included' field returns wrong value", - 1, getterByField.get("included").apply(domain)); + assertGetterValue(getterByField, domain, "included", 1); + assertEquals("Ignored field value is incorrect", 2, domain.getIgnored()); + assertEquals("Excluded field value is incorrect", 3, domain.getExcluded()); } @Test public void should_contains_allIncludedSetters() { - Map> setterByField - = new IncludedAndExcludedDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 1", 1, setterByField.size()); - assertTrue("Map not contain setter for 'included' field", setterByField.containsKey("included")); - assertFalse("Map contains setter for 'ignored' field", setterByField.containsKey("ignored")); - assertFalse("Map contains setter for 'excluded' field", setterByField.containsKey("excluded")); - IncludedAndExcludedDomain domain = new IncludedAndExcludedDomain(0, 2, 3); - setterByField.get("included").accept(domain, 1); - assertEquals("Setter for 'included' field sets wrong value", 1, domain.getIncluded()); + Map> setterByField = getSetterMap(new IncludedAndExcludedDomainSetterSupplier()); + assertSize(setterByField, 1); + assertSetterFields(setterByField, "included"); + IncludedAndExcludedDomain domain = new IncludedAndExcludedDomain(1, 2, 3); + assertSetterValue(setterByField, domain, "included", 10, IncludedAndExcludedDomain::getIncluded); + domain.setIgnored(20); + assertEquals("Ignored field value is incorrect", 20, domain.getIgnored()); + domain.setExcluded(30); + assertEquals("Excluded field value is incorrect", 30, domain.getExcluded()); } } \ No newline at end of file From 2670e5421a4eca50cd095b8500d6d0e3ac4e3e0e Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:27:59 +0300 Subject: [PATCH 08/30] Create tests on inheritance with Lombok Data --- .../lombokdata/InheritedLombokDataDomain.java | 35 ++++++++++++++ .../demo/lombokdata/LombokDataDomain.java | 4 +- .../InheritedLombokDataDomainTest.java | 48 +++++++++++++++++++ .../demo/lombokdata/LombokDataDomainTest.java | 39 ++++++--------- 4 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomain.java new file mode 100644 index 0000000..8a2644c --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomain.java @@ -0,0 +1,35 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.lombokdata; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@GetterSupplier +@SetterSupplier +@EqualsAndHashCode(callSuper = true) +public class InheritedLombokDataDomain extends LombokDataDomain { + private long longer; + + public InheritedLombokDataDomain(int integer, boolean bool, long longer) { + super(integer, bool); + this.longer = longer; + } +} diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomain.java index c4cac10..b7684ec 100644 --- a/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomain.java +++ b/demo/src/main/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomain.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,12 @@ import dev.alexengrig.metter.annotation.SetterSupplier; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data @GetterSupplier @SetterSupplier +@NoArgsConstructor @AllArgsConstructor public class LombokDataDomain { private int integer; diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomainTest.java new file mode 100644 index 0000000..d01a5d2 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomainTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.lombokdata; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class InheritedLombokDataDomainTest extends BaseDomainTest { + @Test + public void should_contains_allGetters() { + Map> getterByField = getGetterMap(new InheritedLombokDataDomainGetterSupplier()); + assertSize(getterByField, 3); + assertGetterFields(getterByField, "integer", "bool", "longer"); + InheritedLombokDataDomain domain = new InheritedLombokDataDomain(1, true, 3); + assertGetterValue(getterByField, domain, "integer", 1); + assertGetterValue(getterByField, domain, "bool", true); + assertGetterValue(getterByField, domain, "longer", 3L); + } + + @Test + public void should_contains_allSetters() { + Map> setterByField = getSetterMap(new InheritedLombokDataDomainSetterSupplier()); + assertSize(setterByField, 3); + assertSetterFields(setterByField, "integer", "bool", "longer"); + InheritedLombokDataDomain domain = new InheritedLombokDataDomain(1, true, 3); + assertSetterValue(setterByField, domain, "integer", 10, InheritedLombokDataDomain::getInteger); + assertSetterValue(setterByField, domain, "bool", false, InheritedLombokDataDomain::isBool); + assertSetterValue(setterByField, domain, "longer", 30L, InheritedLombokDataDomain::getLonger); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomainTest.java index c23d272..1c1210e 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,42 +16,31 @@ package dev.alexengrig.metter.demo.lombokdata; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -public class LombokDataDomainTest { +public class LombokDataDomainTest extends BaseDomainTest { @Test public void should_contains_allGetters() { - Map> getterByField = new LombokDataDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 2", 2, getterByField.size()); - assertTrue("Map not contain getter for 'integer' field", getterByField.containsKey("integer")); - assertTrue("Map not contain getter for 'bool' field", getterByField.containsKey("bool")); + Map> getterByField = getGetterMap(new LombokDataDomainGetterSupplier()); + assertSize(getterByField, 2); + assertGetterFields(getterByField, "integer", "bool"); LombokDataDomain domain = new LombokDataDomain(1, true); - assertEquals("Getter for 'integer' field returns wrong value", - 1, getterByField.get("integer").apply(domain)); - assertEquals("Getter for 'bool' field returns wrong value", - true, getterByField.get("bool").apply(domain)); + assertGetterValue(getterByField, domain, "integer", 1); + assertGetterValue(getterByField, domain, "bool", true); } @Test public void should_contains_allSetters() { - Map> setterByField = new LombokDataDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 2", 2, setterByField.size()); - assertTrue("Map not contain setter for 'integer' field", setterByField.containsKey("integer")); - assertTrue("Map not contain setter for 'bool' field", setterByField.containsKey("bool")); - LombokDataDomain domain = new LombokDataDomain(0, false); - setterByField.get("integer").accept(domain, 1); - assertEquals("Setter for 'integer' field sets wrong value", 1, domain.getInteger()); - setterByField.get("bool").accept(domain, true); - assertTrue("Setter for 'bool' field sets wrong value", domain.isBool()); + Map> setterByField = getSetterMap(new LombokDataDomainSetterSupplier()); + assertSize(setterByField, 2); + assertSetterFields(setterByField, "integer", "bool"); + LombokDataDomain domain = new LombokDataDomain(1, true); + assertSetterValue(setterByField, domain, "integer", 10, LombokDataDomain::getInteger); + assertSetterValue(setterByField, domain, "bool", false, LombokDataDomain::isBool); } } \ No newline at end of file From 45587d09dbe73b1e5c4c10a6ffd2ec50d01477fe Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:39:23 +0300 Subject: [PATCH 09/30] Create tests on inheritance with Lombok Getter and Setter --- .../InheritedLombokGetterAndSetterDomain.java | 35 +++++++++++++ ...eritedLombokGetterAndSetterDomainTest.java | 51 +++++++++++++++++++ .../LombokGetterAndSetterDomainTest.java | 41 +++++---------- 3 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomain.java new file mode 100644 index 0000000..c7f7ae7 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomain.java @@ -0,0 +1,35 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.lombokgetterandsetter; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@GetterSupplier +@SetterSupplier +public class InheritedLombokGetterAndSetterDomain extends LombokGetterAndSetterDomain { + private long longer; + + public InheritedLombokGetterAndSetterDomain(int integer, boolean bool, long longer) { + super(integer, bool); + this.longer = longer; + } +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomainTest.java new file mode 100644 index 0000000..8f7844a --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomainTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.lombokgetterandsetter; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class InheritedLombokGetterAndSetterDomainTest extends BaseDomainTest { + @Test + public void should_contains_allGetters() { + Map> getterByField + = getGetterMap(new InheritedLombokGetterAndSetterDomainGetterSupplier()); + assertSize(getterByField, 3); + assertGetterFields(getterByField, "integer", "bool", "longer"); + InheritedLombokGetterAndSetterDomain domain = new InheritedLombokGetterAndSetterDomain(1, true, 3L); + assertGetterValue(getterByField, domain, "integer", 1); + assertGetterValue(getterByField, domain, "bool", true); + assertGetterValue(getterByField, domain, "longer", 3L); + } + + @Test + public void should_contains_allSetters() { + Map> setterByField + = getSetterMap(new InheritedLombokGetterAndSetterDomainSetterSupplier()); + assertSize(setterByField, 3); + assertSetterFields(setterByField, "integer", "bool", "longer"); + InheritedLombokGetterAndSetterDomain domain = new InheritedLombokGetterAndSetterDomain(1, true, 3L); + assertSetterValue(setterByField, domain, "integer", 10, InheritedLombokGetterAndSetterDomain::getInteger); + assertSetterValue(setterByField, domain, "bool", false, InheritedLombokGetterAndSetterDomain::isBool); + assertSetterValue(setterByField, domain, "longer", 30L, InheritedLombokGetterAndSetterDomain::getLonger); + } + +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/LombokGetterAndSetterDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/LombokGetterAndSetterDomainTest.java index f3d9e09..911422e 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/LombokGetterAndSetterDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgetterandsetter/LombokGetterAndSetterDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,44 +16,31 @@ package dev.alexengrig.metter.demo.lombokgetterandsetter; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -public class LombokGetterAndSetterDomainTest { +public class LombokGetterAndSetterDomainTest extends BaseDomainTest { @Test public void should_contains_allGetters() { - Map> getterByField - = new LombokGetterAndSetterDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 2", 2, getterByField.size()); - assertTrue("Map not contain getter for 'integer' field", getterByField.containsKey("integer")); - assertTrue("Map not contain getter for 'bool' field", getterByField.containsKey("bool")); + Map> getterByField = getGetterMap(new LombokGetterAndSetterDomainGetterSupplier()); + assertSize(getterByField, 2); + assertGetterFields(getterByField, "integer", "bool"); LombokGetterAndSetterDomain domain = new LombokGetterAndSetterDomain(1, true); - assertEquals("Getter for 'integer' field returns wrong value", - 1, getterByField.get("integer").apply(domain)); - assertEquals("Getter for 'bool' field returns wrong value", - true, getterByField.get("bool").apply(domain)); + assertGetterValue(getterByField, domain, "integer", 1); + assertGetterValue(getterByField, domain, "bool", true); } @Test public void should_contains_allSetters() { - Map> setterByField - = new LombokGetterAndSetterDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 2", 2, setterByField.size()); - assertTrue("Map not contain setter for 'integer' field", setterByField.containsKey("integer")); - assertTrue("Map not contain setter for 'bool' field", setterByField.containsKey("bool")); - LombokGetterAndSetterDomain domain = new LombokGetterAndSetterDomain(0, false); - setterByField.get("integer").accept(domain, 1); - assertEquals("Setter for 'integer' field sets wrong value", 1, domain.getInteger()); - setterByField.get("bool").accept(domain, true); - assertTrue("Setter for 'bool' field sets wrong value", domain.isBool()); + Map> setterByField = getSetterMap(new LombokGetterAndSetterDomainSetterSupplier()); + assertSize(setterByField, 2); + assertSetterFields(setterByField, "integer", "bool"); + LombokGetterAndSetterDomain domain = new LombokGetterAndSetterDomain(1, true); + assertSetterValue(setterByField, domain, "integer", 10, LombokGetterAndSetterDomain::getInteger); + assertSetterValue(setterByField, domain, "bool", false, LombokGetterAndSetterDomain::isBool); } } \ No newline at end of file From b8d70c11ef312d530625e47dcc18da55a41692a6 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:46:14 +0300 Subject: [PATCH 10/30] Create tests on inheritance with Lombok Getters and Setters --- ...nheritedLombokGettersAndSettersDomain.java | 35 +++++++++++++ .../LombokGettersAndSettersDomain.java | 3 +- ...itedLombokGettersAndSettersDomainTest.java | 50 +++++++++++++++++++ .../LombokGettersAndSettersDomainTest.java | 42 ++++++---------- 4 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomain.java new file mode 100644 index 0000000..bbbbac2 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomain.java @@ -0,0 +1,35 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.lombokgettersandsetters; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; +import lombok.Getter; +import lombok.Setter; + +@GetterSupplier +@SetterSupplier +public class InheritedLombokGettersAndSettersDomain extends LombokGettersAndSettersDomain { + @Getter + @Setter + private long longer; + + public InheritedLombokGettersAndSettersDomain(int integer, boolean bool, int ignored, long longer) { + super(integer, bool, ignored); + this.longer = longer; + } +} diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomain.java index d3c4c68..740cbda 100644 --- a/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomain.java +++ b/demo/src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomain.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ @GetterSupplier @SetterSupplier public class LombokGettersAndSettersDomain { + @SuppressWarnings({"unused", "FieldCanBeLocal"}) private final int ignored; @Getter @Setter diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomainTest.java new file mode 100644 index 0000000..a63750e --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomainTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.lombokgettersandsetters; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class InheritedLombokGettersAndSettersDomainTest extends BaseDomainTest { + @Test + public void should_contains_allGetters() { + Map> getterByField + = getGetterMap(new InheritedLombokGettersAndSettersDomainGetterSupplier()); + assertSize(getterByField, 3); + assertGetterFields(getterByField, "integer", "bool", "longer"); + InheritedLombokGettersAndSettersDomain domain = new InheritedLombokGettersAndSettersDomain(1, true, 2, 3); + assertGetterValue(getterByField, domain, "integer", 1); + assertGetterValue(getterByField, domain, "bool", true); + assertGetterValue(getterByField, domain, "longer", 3L); + } + + @Test + public void should_contains_allSetters() { + Map> setterByField + = getSetterMap(new InheritedLombokGettersAndSettersDomainSetterSupplier()); + assertSize(setterByField, 3); + assertSetterFields(setterByField, "integer", "bool", "longer"); + InheritedLombokGettersAndSettersDomain domain = new InheritedLombokGettersAndSettersDomain(1, true, 2, 3); + assertSetterValue(setterByField, domain, "integer", 10, InheritedLombokGettersAndSettersDomain::getInteger); + assertSetterValue(setterByField, domain, "bool", false, InheritedLombokGettersAndSettersDomain::isBool); + assertSetterValue(setterByField, domain, "longer", 30L, InheritedLombokGettersAndSettersDomain::getLonger); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomainTest.java index a68e4ff..4dcd85d 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,47 +16,33 @@ package dev.alexengrig.metter.demo.lombokgettersandsetters; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -public class LombokGettersAndSettersDomainTest { +public class LombokGettersAndSettersDomainTest extends BaseDomainTest { @Test public void should_contains_allGetters() { Map> getterByField - = new LombokGettersAndSettersDomainGetterSupplier().get(); - assertNotNull("Map is null", getterByField); - assertEquals("Map size not equal to 2", 2, getterByField.size()); - assertTrue("Map not contain getter for 'integer' field", getterByField.containsKey("integer")); - assertTrue("Map not contain getter for 'bool' field", getterByField.containsKey("bool")); - assertFalse("Map contains getter for 'ignored' field", getterByField.containsKey("ignored")); + = getGetterMap(new LombokGettersAndSettersDomainGetterSupplier()); + assertSize(getterByField, 2); + assertGetterFields(getterByField, "integer", "bool"); LombokGettersAndSettersDomain domain = new LombokGettersAndSettersDomain(1, true, 2); - assertEquals("Getter for 'integer' field returns wrong value", - 1, getterByField.get("integer").apply(domain)); - assertEquals("Getter for 'bool' field returns wrong value", - true, getterByField.get("bool").apply(domain)); + assertGetterValue(getterByField, domain, "integer", 1); + assertGetterValue(getterByField, domain, "bool", true); } @Test public void should_contains_allSetters() { Map> setterByField - = new LombokGettersAndSettersDomainSetterSupplier().get(); - assertNotNull("Map is null", setterByField); - assertEquals("Map size not equal to 2", 2, setterByField.size()); - assertTrue("Map not contain setter for 'integer' field", setterByField.containsKey("integer")); - assertTrue("Map not contain setter for 'bool' field", setterByField.containsKey("bool")); - assertFalse("Map contains setter for 'ignored' field", setterByField.containsKey("ignored")); - LombokGettersAndSettersDomain domain = new LombokGettersAndSettersDomain(0, false, 2); - setterByField.get("integer").accept(domain, 1); - assertEquals("Setter for 'integer' field sets wrong value", 1, domain.getInteger()); - setterByField.get("bool").accept(domain, true); - assertTrue("Setter for 'bool' field sets wrong value", domain.isBool()); + = getSetterMap(new LombokGettersAndSettersDomainSetterSupplier()); + assertSize(setterByField, 2); + assertSetterFields(setterByField, "integer", "bool"); + LombokGettersAndSettersDomain domain = new LombokGettersAndSettersDomain(1, true, 2); + assertSetterValue(setterByField, domain, "integer", 10, LombokGettersAndSettersDomain::getInteger); + assertSetterValue(setterByField, domain, "bool", false, LombokGettersAndSettersDomain::isBool); } } \ No newline at end of file From ef53eadc00dd268de55f199575b4f9eb22a76a85 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:49:12 +0300 Subject: [PATCH 11/30] Create tests on inheritance with private Lombok Getter and Setter --- ...tedPrivateLombokGetterAndSetterDomain.java | 31 ++++++++++++++ ...rivateLombokGetterAndSetterDomainTest.java | 40 +++++++++++++++++++ ...rivateLombokGetterAndSetterDomainTest.java | 15 ++++--- 3 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomain.java new file mode 100644 index 0000000..71c13bc --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomain.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.privatelombokgetterandsetter; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + +@GetterSupplier +@SetterSupplier +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) +public class InheritedPrivateLombokGetterAndSetterDomain extends PrivateLombokGetterAndSetterDomain { + private long longer; +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomainTest.java new file mode 100644 index 0000000..a17809b --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomainTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.privatelombokgetterandsetter; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class InheritedPrivateLombokGetterAndSetterDomainTest extends BaseDomainTest { + @Test + public void should_ignores_privateGetters() { + Map> getterByField + = getGetterMap(new InheritedPrivateLombokGetterAndSetterDomainGetterSupplier()); + assertEmpty(getterByField); + } + + @Test + public void should_ignores_privateSetters() { + Map> setterByField + = getSetterMap(new InheritedPrivateLombokGetterAndSetterDomainSetterSupplier()); + assertEmpty(setterByField); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/PrivateLombokGetterAndSetterDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/PrivateLombokGetterAndSetterDomainTest.java index bf91912..1a2fcf5 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/PrivateLombokGetterAndSetterDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/PrivateLombokGetterAndSetterDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,26 +16,25 @@ package dev.alexengrig.metter.demo.privatelombokgetterandsetter; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertTrue; - -public class PrivateLombokGetterAndSetterDomainTest { +public class PrivateLombokGetterAndSetterDomainTest extends BaseDomainTest { @Test public void should_ignores_privateGetters() { Map> getterByField - = new PrivateLombokGetterAndSetterDomainGetterSupplier().get(); - assertTrue("Map is not empty", getterByField.isEmpty()); + = getGetterMap(new PrivateLombokGetterAndSetterDomainGetterSupplier()); + assertEmpty(getterByField); } @Test public void should_ignores_privateSetters() { Map> setterByField - = new PrivateLombokGetterAndSetterDomainSetterSupplier().get(); - assertTrue("Map is not empty", setterByField.isEmpty()); + = getSetterMap(new PrivateLombokGetterAndSetterDomainSetterSupplier()); + assertEmpty(setterByField); } } From b1fcd6e1e21cf4c543a48700a915333805497614 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:53:02 +0300 Subject: [PATCH 12/30] Create tests on inheritance with private Lombok Getters and Setters --- ...dPrivateLombokGettersAndSettersDomain.java | 31 ++++++++++++++ ...vateLombokGettersAndSettersDomainTest.java | 40 +++++++++++++++++++ ...vateLombokGettersAndSettersDomainTest.java | 15 ++++--- 3 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomain.java create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomainTest.java diff --git a/demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomain.java b/demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomain.java new file mode 100644 index 0000000..7dc9a16 --- /dev/null +++ b/demo/src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomain.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.privatelombokgettersandsetters; + +import dev.alexengrig.metter.annotation.GetterSupplier; +import dev.alexengrig.metter.annotation.SetterSupplier; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + +@GetterSupplier +@SetterSupplier +public class InheritedPrivateLombokGettersAndSettersDomain extends PrivateLombokGettersAndSettersDomain { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private long longer; +} diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomainTest.java new file mode 100644 index 0000000..c6657ee --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomainTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.privatelombokgettersandsetters; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class InheritedPrivateLombokGettersAndSettersDomainTest extends BaseDomainTest { + @Test + public void should_ignores_privateGetters() { + Map> getterByField + = getGetterMap(new InheritedPrivateLombokGettersAndSettersDomainGetterSupplier()); + assertEmpty(getterByField); + } + + @Test + public void should_ignores_privateSetters() { + Map> setterByField + = getSetterMap(new InheritedPrivateLombokGettersAndSettersDomainSetterSupplier()); + assertEmpty(setterByField); + } +} \ No newline at end of file diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/PrivateLombokGettersAndSettersDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/PrivateLombokGettersAndSettersDomainTest.java index faff65a..c6d5429 100644 --- a/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/PrivateLombokGettersAndSettersDomainTest.java +++ b/demo/src/test/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/PrivateLombokGettersAndSettersDomainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,26 +16,25 @@ package dev.alexengrig.metter.demo.privatelombokgettersandsetters; +import dev.alexengrig.metter.demo.BaseDomainTest; import org.junit.Test; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; -import static org.junit.Assert.assertTrue; - -public class PrivateLombokGettersAndSettersDomainTest { +public class PrivateLombokGettersAndSettersDomainTest extends BaseDomainTest { @Test public void should_ignores_privateGetters() { Map> getterByField - = new PrivateLombokGettersAndSettersDomainGetterSupplier().get(); - assertTrue("Map is not empty", getterByField.isEmpty()); + = getGetterMap(new PrivateLombokGettersAndSettersDomainGetterSupplier()); + assertEmpty(getterByField); } @Test public void should_ignores_privateSetters() { Map> setterByField - = new PrivateLombokGettersAndSettersDomainSetterSupplier().get(); - assertTrue("Map is not empty", setterByField.isEmpty()); + = getSetterMap(new PrivateLombokGettersAndSettersDomainSetterSupplier()); + assertEmpty(setterByField); } } \ No newline at end of file From 5557c7e02d9b01a647fe2bb3fd96c6f860df8fd8 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:53:51 +0300 Subject: [PATCH 13/30] Create ElementDescriptor#getElement --- .../element/descriptor/ElementDescriptor.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/element/descriptor/ElementDescriptor.java b/src/main/java/dev/alexengrig/metter/element/descriptor/ElementDescriptor.java index d7bc817..dea4e4c 100644 --- a/src/main/java/dev/alexengrig/metter/element/descriptor/ElementDescriptor.java +++ b/src/main/java/dev/alexengrig/metter/element/descriptor/ElementDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ * * @param type of element * @author Grig Alex - * @version 0.1.1 + * @version 0.2.0 * @since 0.1.1 */ public class ElementDescriptor { @@ -47,6 +47,16 @@ public ElementDescriptor(E element) { this.element = Objects.requireNonNull(element, "Element must not be null"); } + /** + * Returns an element. + * + * @return element + * @since 0.2.0 + */ + public E getElement() { + return element; + } + /** * Check if has an annotation by an annotation type. * From f2f237898f73db2d3a81ebcdcbe8c9bdfe372201 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:57:16 +0300 Subject: [PATCH 14/30] Create BaseProcessor#getAllSuperTypes --- .../metter/processor/BaseProcessor.java | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java b/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java index 2ddbdce..537716d 100644 --- a/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java +++ b/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,18 @@ import javax.annotation.processing.RoundEnvironment; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; import javax.tools.Diagnostic; import java.lang.annotation.Annotation; import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Queue; import java.util.Set; +import java.util.stream.Collectors; /** * Base processor. @@ -34,11 +41,18 @@ * @param type of annotation * @param type of element * @author Grig Alex - * @version 0.1.1 + * @version 0.2.0 * @see javax.annotation.processing.AbstractProcessor * @since 0.1.0 */ public abstract class BaseProcessor extends AbstractProcessor { + /** + * {@link Class#getName()} for {@link Object}. + * + * @since 0.2.0 + */ + protected static final String JAVA_LANG_OBJECT_CLASS_NAME = Object.class.getName(); + /** * Annotation class. * @@ -105,6 +119,36 @@ protected void error(String message, Throwable throwable) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message + System.lineSeparator() + stackTrace); } + /** + * Returns all super type elements for a type element. + * + * @param typeElement type element + * @return all super type elements for {@code typeElement} + * @since 0.2.0 + */ + protected Set getAllSuperTypes(TypeElement typeElement) { + Set target = new HashSet<>(); + Queue queue = new LinkedList<>(); + queue.add(typeElement); + while (!queue.isEmpty()) { + TypeElement type = queue.remove(); + Set superTypes = processingEnv.getTypeUtils().directSupertypes(type.asType()) + .stream() + .filter(typeMirror -> typeMirror.getKind() == TypeKind.DECLARED) + .map(DeclaredType.class::cast) + .map(DeclaredType::asElement) + .filter(element -> element.getKind() == ElementKind.CLASS) + .filter(element -> !JAVA_LANG_OBJECT_CLASS_NAME.equals(element.toString())) + .map(TypeElement.class::cast) + .collect(Collectors.toSet()); + if (!superTypes.isEmpty()) { + target.addAll(superTypes); + queue.addAll(superTypes); + } + } + return target; + } + /** * Returns an empty set. * From e882d9a5e1c8efec11d7f5d53cf249553b40cfb2 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Mon, 19 Apr 2021 23:58:43 +0300 Subject: [PATCH 15/30] Add fields of super classes to BaseMethodSupplierProcessor#getFields --- .../processor/BaseMethodSupplierProcessor.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java b/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java index aba22cb..b243d65 100644 --- a/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java +++ b/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,13 +31,14 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Base processor of method supplier. * * @param type of annotation * @author Grig Alex - * @version 0.1.1 + * @version 0.2.0 * @since 0.1.0 */ public abstract class BaseMethodSupplierProcessor extends BaseProcessor { @@ -169,14 +170,17 @@ protected Map createField2MethodMap(TypeDescriptor type) { } /** - * Returns fields from a type descriptor. + * Returns fields from a type descriptor with fields of super classes. * * @param type descriptor - * @return fields from {@code type} + * @return fields from {@code type} with fields of super classes * @since 0.1.0 */ protected Set getFields(TypeDescriptor type) { - Set fields = type.getFields(); + Set superTypes = getAllSuperTypes(type.getElement()); + Set fields = Stream.concat(Stream.of(type), superTypes.stream().map(TypeDescriptor::new)) + .flatMap(descriptor -> descriptor.getFields().stream()) + .collect(Collectors.toSet()); Set includedFields = getIncludedFields(type); Set excludedFields = getExcludedFields(type); if (includedFields.isEmpty() && excludedFields.isEmpty()) { From d2edc95d8fd185b31bb50d525847341497ef61c3 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Tue, 20 Apr 2021 00:05:20 +0300 Subject: [PATCH 16/30] Create ElementMocks#element --- src/test/java/dev/alexengrig/metter/ElementMocks.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/dev/alexengrig/metter/ElementMocks.java b/src/test/java/dev/alexengrig/metter/ElementMocks.java index 8c581ae..40d6cce 100644 --- a/src/test/java/dev/alexengrig/metter/ElementMocks.java +++ b/src/test/java/dev/alexengrig/metter/ElementMocks.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,12 +44,16 @@ public final class ElementMocks { public static Element annotatedElement(Class type) { - Element element = mock(Element.class); + Element element = element(); A annotation = annotationMock(type); when(element.getAnnotation(type)).thenReturn(annotation); return element; } + public static Element element() { + return mock(Element.class); + } + public static VariableElement fieldMock() { VariableElement mock = mock(VariableElement.class); when(mock.getKind()).thenReturn(ElementKind.FIELD); From 9e87ed00db26a856975715f7a043c09802de3141 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Tue, 20 Apr 2021 00:05:27 +0300 Subject: [PATCH 17/30] Create test for ElementDescriptor#getElement --- .../metter/element/descriptor/ElementDescriptorTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/dev/alexengrig/metter/element/descriptor/ElementDescriptorTest.java b/src/test/java/dev/alexengrig/metter/element/descriptor/ElementDescriptorTest.java index 39cbbaa..1babe2b 100644 --- a/src/test/java/dev/alexengrig/metter/element/descriptor/ElementDescriptorTest.java +++ b/src/test/java/dev/alexengrig/metter/element/descriptor/ElementDescriptorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,16 @@ import javax.lang.model.element.Element; import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; class ElementDescriptorTest { + @Test + void should_return_element() { + Element element = ElementMocks.element(); + ElementDescriptor descriptor = new ElementDescriptor<>(element); + assertSame(element, descriptor.getElement(), "Element is incorrect"); + } @Test void should_return_annotation() { From dd903ba1ba667ceb89abffb6da6fac2f8acbcb75 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Thu, 22 Apr 2021 23:18:58 +0300 Subject: [PATCH 18/30] Refactor BaseProcessorTest --- .../metter/processor/BaseProcessorTest.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java b/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java index a97e5bc..ef9e3d5 100644 --- a/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java +++ b/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,16 +43,8 @@ import static org.mockito.Mockito.when; class BaseProcessorTest { - static final BaseProcessor processor; - static final ProcessingEnvironment environment; - - static { - environment = mock(ProcessingEnvironment.class); - processor = new BaseProcessor(Deprecated.class) { - { - init(environment); - } - + private static BaseProcessor getMock() { + return new BaseProcessor(Deprecated.class) { @Override protected void process(Element annotatedElement) { } @@ -63,6 +55,7 @@ protected void process(Element annotatedElement) { void should_not_process() { RoundEnvironment roundEnvironment = mock(RoundEnvironment.class); when(roundEnvironment.processingOver()).thenReturn(true); + BaseProcessor processor = getMock(); assertFalse(processor.process(Collections.emptySet(), roundEnvironment), "Processor must not process"); } @@ -73,6 +66,7 @@ void should_process() { Element typeElement = ElementMocks.typeElementMock(); Mockito.>when(roundEnvironment.getElementsAnnotatedWith(Deprecated.class)) .thenReturn(Collections.singleton(typeElement)); + BaseProcessor processor = getMock(); assertTrue(processor.process(Collections.emptySet(), roundEnvironment), "Processor must process"); verify(roundEnvironment).getElementsAnnotatedWith(Deprecated.class); } @@ -80,7 +74,10 @@ void should_process() { @Test void should_print_noteMessage() { Messager messager = mock(Messager.class); + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); when(environment.getMessager()).thenReturn(messager); + BaseProcessor processor = getMock(); + processor.init(environment); processor.note("Note message"); verify(messager).printMessage(Diagnostic.Kind.NOTE, "Note message"); } @@ -88,6 +85,7 @@ void should_print_noteMessage() { @Test void should_print_errorMessage() { Messager messager = mock(Messager.class); + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); when(environment.getMessager()).thenReturn(messager); ArrayList messages = new ArrayList<>(); doAnswer(invocation -> { @@ -100,6 +98,8 @@ void should_print_errorMessage() { printWriter.write("java.lang.RuntimeException without stack trace"); return null; }).when(exception).printStackTrace(any(PrintWriter.class)); + BaseProcessor processor = getMock(); + processor.init(environment); processor.error("Error message", exception); verify(messager).printMessage(eq(Diagnostic.Kind.ERROR), any()); assertEquals(1, messages.size(), "Number of messages is not 1"); @@ -110,17 +110,20 @@ void should_print_errorMessage() { @Test void should_return_supportedOptions() { + BaseProcessor processor = getMock(); assertTrue(processor.getSupportedOptions().isEmpty(), "Processor has supported options"); } @Test void should_return_supportedVersion() { + BaseProcessor processor = getMock(); assertEquals(SourceVersion.RELEASE_8, processor.getSupportedSourceVersion(), "Supported source version does not equal to 8"); } @Test void should_return_supportedAnnotations() { + BaseProcessor processor = getMock(); assertEquals(Collections.singleton("java.lang.Deprecated"), processor.getSupportedAnnotationTypes(), "Supported annotation types are not equal to 'java.lang.Deprecated'"); } From 3539c8f11fc341b8211ef72f3a1257d4fa8d1ff0 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Thu, 22 Apr 2021 23:33:17 +0300 Subject: [PATCH 19/30] Create tests for BaseProcessor#getAllSuperTypes and BaseMethodSupplierProcessor#getFields --- .../BaseMethodSupplierProcessor.java | 4 +- .../metter/processor/BaseProcessor.java | 15 +-- .../BaseMethodSupplierProcessorTest.java | 112 +++++++++++++++++- .../metter/processor/BaseProcessorTest.java | 49 ++++++++ 4 files changed, 170 insertions(+), 10 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java b/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java index b243d65..edc05c2 100644 --- a/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java +++ b/src/main/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessor.java @@ -177,8 +177,8 @@ protected Map createField2MethodMap(TypeDescriptor type) { * @since 0.1.0 */ protected Set getFields(TypeDescriptor type) { - Set superTypes = getAllSuperTypes(type.getElement()); - Set fields = Stream.concat(Stream.of(type), superTypes.stream().map(TypeDescriptor::new)) + Set superTypes = getAllSuperTypes(type); + Set fields = Stream.concat(Stream.of(type), superTypes.stream()) .flatMap(descriptor -> descriptor.getFields().stream()) .collect(Collectors.toSet()); Set includedFields = getIncludedFields(type); diff --git a/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java b/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java index 537716d..4368a07 100644 --- a/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java +++ b/src/main/java/dev/alexengrig/metter/processor/BaseProcessor.java @@ -16,6 +16,7 @@ package dev.alexengrig.metter.processor; +import dev.alexengrig.metter.element.descriptor.TypeDescriptor; import dev.alexengrig.metter.util.Exceptions; import javax.annotation.processing.AbstractProcessor; @@ -120,16 +121,16 @@ protected void error(String message, Throwable throwable) { } /** - * Returns all super type elements for a type element. + * Returns all super type descriptors for a type descriptor. * - * @param typeElement type element - * @return all super type elements for {@code typeElement} + * @param typeDescriptor type descriptor + * @return all super type descriptors for {@code typeDescriptor} * @since 0.2.0 */ - protected Set getAllSuperTypes(TypeElement typeElement) { - Set target = new HashSet<>(); + protected Set getAllSuperTypes(TypeDescriptor typeDescriptor) { + Set target = new HashSet<>(); Queue queue = new LinkedList<>(); - queue.add(typeElement); + queue.add(typeDescriptor.getElement()); while (!queue.isEmpty()) { TypeElement type = queue.remove(); Set superTypes = processingEnv.getTypeUtils().directSupertypes(type.asType()) @@ -142,7 +143,7 @@ protected Set getAllSuperTypes(TypeElement typeElement) { .map(TypeElement.class::cast) .collect(Collectors.toSet()); if (!superTypes.isEmpty()) { - target.addAll(superTypes); + target.addAll(superTypes.stream().map(TypeDescriptor::new).collect(Collectors.toSet())); queue.addAll(superTypes); } } diff --git a/src/test/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessorTest.java b/src/test/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessorTest.java index b1a7506..f006f5b 100644 --- a/src/test/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessorTest.java +++ b/src/test/java/dev/alexengrig/metter/processor/BaseMethodSupplierProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +27,14 @@ import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import javax.tools.Diagnostic; import javax.tools.JavaFileObject; import java.io.IOException; @@ -46,12 +51,14 @@ import static dev.alexengrig.metter.ElementMocks.nameMock; import static dev.alexengrig.metter.ElementMocks.typeElementMock; import static java.lang.System.lineSeparator; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -272,10 +279,17 @@ protected String getMethod(FieldDescriptor field) { when(filer.createSourceFile(any())).thenReturn(file); ProcessingEnvironment environment = mock(ProcessingEnvironment.class); when(environment.getFiler()).thenReturn(filer); + + TypeMirror typeMirror = mock(TypeMirror.class); + Types types = mock(Types.class); + when(types.directSupertypes(same(typeMirror))).thenReturn(Collections.emptyList()); + when(environment.getTypeUtils()).thenReturn(types); + VariableElement variableElement = fieldMock("field", String.class); TypeElement typeElement = typeElementMock(String.class); Mockito.>when(typeElement.getEnclosedElements()) .thenReturn(Collections.singletonList(variableElement)); + when(typeElement.asType()).thenReturn(typeMirror); processor.init(environment); processor.process(typeElement); @@ -294,6 +308,18 @@ void should_create_field2MethodMap() { fieldMock("field1"), fieldMock("field2"))); TypeDescriptor typeDescriptor = new TypeDescriptor(typeElement); + + TypeMirror typeMirror = mock(TypeMirror.class); + when(typeElement.asType()).thenReturn(typeMirror); + + Types types = mock(Types.class); + when(types.directSupertypes(same(typeMirror))).thenReturn(Collections.emptyList()); + + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); + when(environment.getTypeUtils()).thenReturn(types); + + processor.init(environment); + Map field2MethodMap = processor.createField2MethodMap(typeDescriptor); assertEquals(2, field2MethodMap.size(), "Size of field-method map is incorrect"); assertTrue(field2MethodMap.containsKey("field1"), "Field-method map has no 'field1'"); @@ -304,21 +330,90 @@ void should_create_field2MethodMap() { void should_return_fields() { BaseMethodSupplierProcessor processor = getMock(); TypeDescriptor typeDescriptor = mock(TypeDescriptor.class); + + TypeMirror typeMirror = mock(TypeMirror.class); + TypeElement typeElement = mock(TypeElement.class); + when(typeElement.asType()).thenReturn(typeMirror); + when(typeDescriptor.getElement()).thenReturn(typeElement); + FieldDescriptor field = new FieldDescriptor(fieldMock("field")); when(typeDescriptor.getFields()).thenReturn(Collections.singleton(field)); + + Types types = mock(Types.class); + when(types.directSupertypes(same(typeMirror))).thenReturn(Collections.emptyList()); + + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); + when(environment.getTypeUtils()).thenReturn(types); + + processor.init(environment); Set fields = processor.getFields(typeDescriptor); assertEquals(1, fields.size(), "Number of fields does not equal to 1"); assertEquals("field", fields.iterator().next().getName(), "Field name does not equal to 'field'"); } + @Test + void should_return_fields_with_superClassFields() { + VariableElement superField = fieldMock("superField"); + + TypeElement superTypeElement = mock(TypeElement.class); + Mockito.>when(superTypeElement.getEnclosedElements()) + .thenReturn(Collections.singletonList(superField)); + when(superTypeElement.getKind()).thenReturn(ElementKind.CLASS); + when(superTypeElement.toString()).thenReturn("NoObject"); + + DeclaredType declaredType = mock(DeclaredType.class); + when(declaredType.asElement()).thenReturn(superTypeElement); + when(declaredType.getKind()).thenReturn(TypeKind.DECLARED); + + TypeMirror typeMirror = mock(TypeMirror.class); + TypeElement typeElement = mock(TypeElement.class); + when(typeElement.asType()).thenReturn(typeMirror); + + Types types = mock(Types.class); + Mockito.>when(types.directSupertypes(same(typeMirror))) + .thenReturn(Collections.singletonList(declaredType)); + + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); + when(environment.getTypeUtils()).thenReturn(types); + + BaseMethodSupplierProcessor processor = getMock(); + + processor.init(environment); + + FieldDescriptor field = new FieldDescriptor(fieldMock("field")); + TypeDescriptor typeDescriptor = mock(TypeDescriptor.class); + when(typeDescriptor.getElement()).thenReturn(typeElement); + when(typeDescriptor.getFields()).thenReturn(Collections.singleton(field)); + + Set fields = processor.getFields(typeDescriptor); + assertEquals(2, fields.size(), "Number of fields does not equal to 2"); + assertArrayEquals(new String[]{"field", "superField"}, + fields.stream().map(FieldDescriptor::getName).sorted().toArray(), "Fields are incorrect"); + } + @Test void should_return_includedFields() { BaseMethodSupplierProcessor processor = getMock(); TypeDescriptor typeDescriptor = mock(TypeDescriptor.class); + + TypeMirror typeMirror = mock(TypeMirror.class); + TypeElement typeElement = mock(TypeElement.class); + when(typeElement.asType()).thenReturn(typeMirror); + when(typeDescriptor.getElement()).thenReturn(typeElement); + FieldDescriptor field = new FieldDescriptor(fieldMock("field")); FieldDescriptor included = new FieldDescriptor(fieldMock("included")); when(typeDescriptor.getFields()).thenReturn(new HashSet<>(Arrays.asList(field, included))); when(processor.getIncludedFields(any())).thenReturn(Collections.singleton("included")); + + Types types = mock(Types.class); + when(types.directSupertypes(same(typeMirror))).thenReturn(Collections.emptyList()); + + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); + when(environment.getTypeUtils()).thenReturn(types); + + processor.init(environment); + Set fields = processor.getFields(typeDescriptor); assertEquals(1, fields.size(), "Number of fields does not equal to 1"); assertEquals("included", fields.iterator().next().getName(), "Field name does not equal to 'included'"); @@ -328,10 +423,25 @@ void should_return_includedFields() { void should_return_notExcludedFields() { BaseMethodSupplierProcessor processor = getMock(); TypeDescriptor typeDescriptor = mock(TypeDescriptor.class); + + TypeMirror typeMirror = mock(TypeMirror.class); + TypeElement typeElement = mock(TypeElement.class); + when(typeElement.asType()).thenReturn(typeMirror); + when(typeDescriptor.getElement()).thenReturn(typeElement); + FieldDescriptor field = new FieldDescriptor(fieldMock("field")); FieldDescriptor excluded = new FieldDescriptor(fieldMock("excluded")); when(typeDescriptor.getFields()).thenReturn(new HashSet<>(Arrays.asList(field, excluded))); when(processor.getExcludedFields(any())).thenReturn(Collections.singleton("excluded")); + + Types types = mock(Types.class); + when(types.directSupertypes(same(typeMirror))).thenReturn(Collections.emptyList()); + + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); + when(environment.getTypeUtils()).thenReturn(types); + + processor.init(environment); + Set fields = processor.getFields(typeDescriptor); assertEquals(1, fields.size(), "Number of fields does not equal to 1"); assertEquals("field", fields.iterator().next().getName(), "Field name does not equal to 'field'"); diff --git a/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java b/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java index ef9e3d5..7b2d73b 100644 --- a/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java +++ b/src/test/java/dev/alexengrig/metter/processor/BaseProcessorTest.java @@ -17,6 +17,7 @@ package dev.alexengrig.metter.processor; import dev.alexengrig.metter.ElementMocks; +import dev.alexengrig.metter.element.descriptor.TypeDescriptor; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -25,18 +26,29 @@ import javax.annotation.processing.RoundEnvironment; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import javax.tools.Diagnostic; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; +import static dev.alexengrig.metter.ElementMocks.fieldMock; import static java.lang.System.lineSeparator; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -108,6 +120,43 @@ void should_print_errorMessage() { "Error message is incorrect"); } + @Test + void should_return_allSuperTypes() { + VariableElement superField = fieldMock("superField"); + + TypeElement superTypeElement = mock(TypeElement.class); + Mockito.>when(superTypeElement.getEnclosedElements()) + .thenReturn(Collections.singletonList(superField)); + when(superTypeElement.getKind()).thenReturn(ElementKind.CLASS); + when(superTypeElement.toString()).thenReturn("NoObject"); + + DeclaredType declaredType = mock(DeclaredType.class); + when(declaredType.asElement()).thenReturn(superTypeElement); + when(declaredType.getKind()).thenReturn(TypeKind.DECLARED); + + TypeMirror typeMirror = mock(TypeMirror.class); + TypeElement typeElement = mock(TypeElement.class); + when(typeElement.asType()).thenReturn(typeMirror); + + Types types = mock(Types.class); + Mockito.>when(types.directSupertypes(same(typeMirror))) + .thenReturn(Collections.singletonList(declaredType)); + + ProcessingEnvironment environment = mock(ProcessingEnvironment.class); + when(environment.getTypeUtils()).thenReturn(types); + + TypeDescriptor typeDescriptor = new TypeDescriptor(typeElement); + + BaseProcessor processor = getMock(); + + processor.init(environment); + + Set superTypes = processor.getAllSuperTypes(typeDescriptor); + + assertEquals(1, superTypes.size(), "Number of super types are incorrect"); + assertSame(superTypeElement, superTypes.iterator().next().getElement(), "Super type element is incorrect"); + } + @Test void should_return_supportedOptions() { BaseProcessor processor = getMock(); From f824cf2bf1d9c1af60940740162ef7650e2caada Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Thu, 22 Apr 2021 23:34:33 +0300 Subject: [PATCH 20/30] Update package version --- src/main/java/dev/alexengrig/metter/element/package-info.java | 4 ++-- .../java/dev/alexengrig/metter/processor/package-info.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/element/package-info.java b/src/main/java/dev/alexengrig/metter/element/package-info.java index 6fdb689..7befa8a 100644 --- a/src/main/java/dev/alexengrig/metter/element/package-info.java +++ b/src/main/java/dev/alexengrig/metter/element/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ * Elements. * * @author Grig Alex - * @version 0.1.1 + * @version 0.2.0 * @since 0.1.0 */ package dev.alexengrig.metter.element; \ No newline at end of file diff --git a/src/main/java/dev/alexengrig/metter/processor/package-info.java b/src/main/java/dev/alexengrig/metter/processor/package-info.java index 865825f..78226b0 100644 --- a/src/main/java/dev/alexengrig/metter/processor/package-info.java +++ b/src/main/java/dev/alexengrig/metter/processor/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ * Processors. * * @author Grig Alex - * @version 0.1.1 + * @version 0.2.0 * @since 0.1.0 */ package dev.alexengrig.metter.processor; \ No newline at end of file From d89c3875406b600bd589edcc14868c8d0edb87e5 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Wed, 14 Jul 2021 05:25:22 -0700 Subject: [PATCH 21/30] Set jar name --- .travis.yml | 2 +- demo/build.gradle | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4b4f314..195280c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: java jdk: - openjdk8 install: - - mvn install -Dgpg.skip=true -B -V + - mvn install -Dgpg.skip=true -Djar.finalName=metter -B -V - cd demo - gradle test - cd .. diff --git a/demo/build.gradle b/demo/build.gradle index c15160e..21e867f 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -26,8 +26,8 @@ repositories { } dependencies { - compileOnly files('../target/metter-0.1.1-SNAPSHOT.jar') - annotationProcessor files('../target/metter-0.1.1-SNAPSHOT.jar') + compileOnly files('../target/metter.jar') + annotationProcessor files('../target/metter.jar') compileOnly 'org.projectlombok:lombok:1.18.12' annotationProcessor 'org.projectlombok:lombok:1.18.12' From 49adc34a42f12b62576fc2fd00752ad9c70fe8f4 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Wed, 14 Jul 2021 06:53:58 -0700 Subject: [PATCH 22/30] Create tests on inheritance with including and excluding --- ...nheritedIncludedAndExcludedDomainTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomainTest.java diff --git a/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomainTest.java b/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomainTest.java new file mode 100644 index 0000000..b764bc5 --- /dev/null +++ b/demo/src/test/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomainTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2020-2021 Alexengrig Dev. + * + * 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 dev.alexengrig.metter.demo.includingandexcluding; + +import dev.alexengrig.metter.demo.BaseDomainTest; +import org.junit.Test; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +import static org.junit.Assert.assertEquals; + +public class InheritedIncludedAndExcludedDomainTest extends BaseDomainTest { + @Test + public void should_contains_allIncludedGetters() { + Map> getterByField + = getGetterMap(new InheritedIncludedAndExcludedDomainGetterSupplier()); + assertSize(getterByField, 2); + assertGetterFields(getterByField, "included"); + assertGetterFields(getterByField, "alsoIncluded"); + InheritedIncludedAndExcludedDomain domain = + new InheritedIncludedAndExcludedDomain(1, 2, 3, 4, 5, 6); + assertGetterValue(getterByField, domain, "included", 1); + assertGetterValue(getterByField, domain, "alsoIncluded", 4); + assertEquals("Ignored field value is incorrect", 2, domain.getIgnored()); + assertEquals("Excluded field value is incorrect", 3, domain.getExcluded()); + assertEquals("AlsoIgnored field value is incorrect", 5, domain.getAlsoIgnored()); + assertEquals("AlsoExcluded field value is incorrect", 6, domain.getAlsoExcluded()); + } + + @Test + public void should_contains_allIncludedSetters() { + Map> setterByField = + getSetterMap(new InheritedIncludedAndExcludedDomainSetterSupplier()); + assertSize(setterByField, 2); + assertSetterFields(setterByField, "included"); + assertSetterFields(setterByField, "alsoIncluded"); + InheritedIncludedAndExcludedDomain domain = + new InheritedIncludedAndExcludedDomain(1, 2, 3, 4, 5, 6); + assertSetterValue(setterByField, domain, "included", 10, InheritedIncludedAndExcludedDomain::getIncluded); + assertSetterValue(setterByField, domain, "alsoIncluded", 40, InheritedIncludedAndExcludedDomain::getAlsoIncluded); + domain.setIgnored(20); + assertEquals("Ignored field value is incorrect", 20, domain.getIgnored()); + domain.setExcluded(30); + assertEquals("Excluded field value is incorrect", 30, domain.getExcluded()); + domain.setAlsoIgnored(50); + assertEquals("AlsoIgnored field value is incorrect", 50, domain.getAlsoIgnored()); + domain.setAlsoExcluded(60); + assertEquals("AlsoExcluded field value is incorrect", 60, domain.getAlsoExcluded()); + } +} \ No newline at end of file From bc7de04396c4e8b3a1c4f6cb04d4e49f6a42a93e Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Wed, 14 Jul 2021 07:02:01 -0700 Subject: [PATCH 23/30] Create README.md for demo --- demo/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 demo/README.md diff --git a/demo/README.md b/demo/README.md new file mode 100644 index 0000000..9eae24e --- /dev/null +++ b/demo/README.md @@ -0,0 +1,35 @@ +# metter demo + +- [Simple domain](src/main/java/dev/alexengrig/metter/demo/simple/SimpleDomain.java) +- [Domain with custom name](src/main/java/dev/alexengrig/metter/demo/naming/NamedDomain.java) +- [Excluding](src/main/java/dev/alexengrig/metter/demo/excluding) + - [Domain with excluded getters/setters](src/main/java/dev/alexengrig/metter/demo/excluding/ExcludedDomain.java) + - [Inherited domain with excluded getters/setters](src/main/java/dev/alexengrig/metter/demo/excluding/InheritedExcludedDomain.java) +- [Including](src/main/java/dev/alexengrig/metter/demo/including) + - [Domain with included getters/setters](src/main/java/dev/alexengrig/metter/demo/including/IncludedDomain.java) + - [Inherited domain with included getters/setters](src/main/java/dev/alexengrig/metter/demo/including/InheritedIncludedDomain.java) +- [Including and excluding](src/main/java/dev/alexengrig/metter/demo/includingandexcluding) + - [Domain with included and excluded getters/setters](src/main/java/dev/alexengrig/metter/demo/includingandexcluding/IncludedAndExcludedDomain.java) + - [Inherited domain with included and excluded getters/setters](src/main/java/dev/alexengrig/metter/demo/includingandexcluding/InheritedIncludedAndExcludedDomain.java) +- [Inheritance](src/main/java/dev/alexengrig/metter/demo/inheritance) +- [Lombok Data annotation](src/main/java/dev/alexengrig/metter/demo/lombokdata) + - [Domain with Lombok Data annotation](src/main/java/dev/alexengrig/metter/demo/lombokdata/LombokDataDomain.java) + - [Inherited domain with Lombok Data annotation](src/main/java/dev/alexengrig/metter/demo/lombokdata/InheritedLombokDataDomain.java) +- [Lombok Getter and Setter annotations on class](src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter) + - [Domain with Lombok Getter and Setter annotations on class](src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter/LombokGetterAndSetterDomain.java) + - [Inherited domain with Lombok Getter and Setter annotations on class](src/main/java/dev/alexengrig/metter/demo/lombokgetterandsetter/InheritedLombokGetterAndSetterDomain.java) +- [Lombok Getter and Setter annotations on field](src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters) + - [Domain with Lombok Getter and Setter annotations on field](src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/LombokGettersAndSettersDomain.java) + - [Inherited domain with Lombok Getter and Setter annotations on field](src/main/java/dev/alexengrig/metter/demo/lombokgettersandsetters/InheritedLombokGettersAndSettersDomain.java) +- [Private getters and setters](src/main/java/dev/alexengrig/metter/demo/privategettersandsetters) + - [Domain with private getters and setters](src/main/java/dev/alexengrig/metter/demo/privategettersandsetters/PrivateGettersAndSettersDomain.java) + - [Inherited domain with private getters and setters](src/main/java/dev/alexengrig/metter/demo/privategettersandsetters/InheritedPrivateGettersAndSettersDomain.java) +- [Lombok Getter and Setter annotations on class with private access](src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter) + - [Domain with Lombok Getter and Setter annotations on class with private access](src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/PrivateLombokGetterAndSetterDomain.java) + - [Inherited domain with Lombok Getter and Setter annotations on class with private access](src/main/java/dev/alexengrig/metter/demo/privatelombokgetterandsetter/InheritedPrivateLombokGetterAndSetterDomain.java) +- [Lombok Getter and Setter annotations on field with private access](src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters) + - [Domain with Lombok Getter and Setter annotations on field with private access](src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/PrivateLombokGettersAndSettersDomain.java) + - [Inherited domain with Lombok Getter and Setter annotations on field with private access](src/main/java/dev/alexengrig/metter/demo/privatelombokgettersandsetters/InheritedPrivateLombokGettersAndSettersDomain.java) +- [Domain without package](src/main/java/NoPackageDomain.java) + +- [Motivation code](src/main/java/dev/alexengrig/metter/motivation) From 5bc3388cacf493760cde976c83d32c65de144e02 Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Wed, 14 Jul 2021 07:45:08 -0700 Subject: [PATCH 24/30] Add JavaDoc to suppliers --- .../GetterSupplierSourceGenerator.java | 24 ++++++- .../MethodSupplierSourceGenerator.java | 40 ++++++++++- .../SetterSupplierSourceGenerator.java | 24 ++++++- .../GetterSupplierSourceGeneratorTest.java | 42 +++++++++++- .../MethodSupplierSourceGeneratorTest.java | 66 +++++++++++++++++-- .../SetterSupplierSourceGeneratorTest.java | 42 +++++++++++- 6 files changed, 223 insertions(+), 15 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java b/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java index adb9e60..b04d54d 100644 --- a/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java +++ b/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -56,4 +56,24 @@ protected GetterSupplierSourceGenerator(boolean withGeneratedDate) { protected String getMapValueType(String domainClassName) { return String.format("java.util.function.Function<%s, java.lang.Object>", domainClassName); } + + /** + * Returns {@code Getters}. + * + * @return {@code Getters} + */ + @Override + protected String getJavaDocTypeNameForClass() { + return "Getters"; + } + + /** + * Returns {@code getter}. + * + * @return {@code getter} + */ + @Override + protected String getJavaDocTypeName() { + return "getter"; + } } diff --git a/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java b/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java index 618511e..29b1424 100644 --- a/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java +++ b/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -68,8 +68,12 @@ public String generate(String className, String domainClassName, Map> {") .ln() + .ln(" /**") + .ft(" * Map, %s function by field name.", javaDocTypeName) + .ln(" */") .ln(" protected final java.util.Map<") .ln(" java.lang.String,") .ft(" %s", mapValueType) .ln(" > getterByField;") .ln() + .ln(" /**") + .ln(" * Constructs this.") + .ln(" */") .ft(" public %s() {", simpleClassName) .ln(" this.getterByField = createMap();") .ln(" }") .ln() + .ln(" /**") + .ft(" * Creates map, %s function by field name.", javaDocTypeName) + .ln(" *") + .ft(" * @return map, %s function by field name", javaDocTypeName) + .ln(" */") .ln(" protected java.util.Map<") .ln(" java.lang.String,") .ft(" %s", mapValueType) @@ -101,6 +116,11 @@ public String generate(String className, String domainClassName, Map", domainClassName); } + + /** + * Returns {@code Setters}. + * + * @return {@code Setters} + */ + @Override + protected String getJavaDocTypeNameForClass() { + return "Setters"; + } + + /** + * Returns {@code setter}. + * + * @return {@code setter} + */ + @Override + protected String getJavaDocTypeName() { + return "setter"; + } } diff --git a/src/test/java/dev/alexengrig/metter/generator/GetterSupplierSourceGeneratorTest.java b/src/test/java/dev/alexengrig/metter/generator/GetterSupplierSourceGeneratorTest.java index 03ad60d..61900de 100644 --- a/src/test/java/dev/alexengrig/metter/generator/GetterSupplierSourceGeneratorTest.java +++ b/src/test/java/dev/alexengrig/metter/generator/GetterSupplierSourceGeneratorTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -30,6 +30,9 @@ class GetterSupplierSourceGeneratorTest { static { SNAPSHOT_OF_SOURCE_WITHOUT_PACKAGE = "" + + "/**\n" + + " * Getters supplier of {@link MyDomain}.\n" + + " */\n" + "@javax.annotation.Generated(\n" + " value = \"dev.alexengrig.metter.generator.GetterSupplierSourceGenerator\")\n" + "public class MyClass implements\n" + @@ -39,15 +42,26 @@ class GetterSupplierSourceGeneratorTest { " java.util.function.Function\n" + " >> {\n" + "\n" + + " /**\n" + + " * Map, getter function by field name.\n" + + " */\n" + " protected final java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.Function\n" + " > getterByField;\n" + "\n" + + " /**\n" + + " * Constructs this.\n" + + " */\n" + " public MyClass() {\n" + " this.getterByField = createMap();\n" + " }\n" + "\n" + + " /**\n" + + " * Creates map, getter function by field name.\n" + + " *\n" + + " * @return map, getter function by field name\n" + + " */\n" + " protected java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.Function\n" + @@ -65,6 +79,11 @@ class GetterSupplierSourceGeneratorTest { " return map;\n" + " }\n" + "\n" + + " /**\n" + + " * Returns map, getter function by field name.\n" + + " *\n" + + " * @return map, getter function by field name\n" + + " */\n" + " @Override\n" + " public java.util.Map<\n" + " java.lang.String,\n" + @@ -76,6 +95,9 @@ class GetterSupplierSourceGeneratorTest { SNAPSHOT_OF_SOURCE_WITH_PACKAGE = "" + "package my.company;\n" + "\n" + + "/**\n" + + " * Getters supplier of {@link my.company.MyDomain}.\n" + + " */\n" + "@javax.annotation.Generated(\n" + " value = \"dev.alexengrig.metter.generator.GetterSupplierSourceGenerator\")\n" + "public class MyClass implements\n" + @@ -85,15 +107,26 @@ class GetterSupplierSourceGeneratorTest { " java.util.function.Function\n" + " >> {\n" + "\n" + + " /**\n" + + " * Map, getter function by field name.\n" + + " */\n" + " protected final java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.Function\n" + " > getterByField;\n" + "\n" + + " /**\n" + + " * Constructs this.\n" + + " */\n" + " public MyClass() {\n" + " this.getterByField = createMap();\n" + " }\n" + "\n" + + " /**\n" + + " * Creates map, getter function by field name.\n" + + " *\n" + + " * @return map, getter function by field name\n" + + " */\n" + " protected java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.Function\n" + @@ -111,6 +144,11 @@ class GetterSupplierSourceGeneratorTest { " return map;\n" + " }\n" + "\n" + + " /**\n" + + " * Returns map, getter function by field name.\n" + + " *\n" + + " * @return map, getter function by field name\n" + + " */\n" + " @Override\n" + " public java.util.Map<\n" + " java.lang.String,\n" + diff --git a/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java b/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java index 88d6d38..3b53ee4 100644 --- a/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java +++ b/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -21,9 +21,7 @@ import java.util.HashMap; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; class MethodSupplierSourceGeneratorTest { static final String SNAPSHOT_OF_SOURCE_WITHOUT_PACKAGE; @@ -31,6 +29,9 @@ class MethodSupplierSourceGeneratorTest { static { SNAPSHOT_OF_SOURCE_WITHOUT_PACKAGE = "" + + "/**\n" + + " * Types supplier of {@link MyDomain}.\n" + + " */\n" + "@javax.annotation.Generated(\n" + " value = \"dev.alexengrig.metter.generator.MethodSupplierSourceGeneratorTest$1\")\n" + "public class MyClass implements\n" + @@ -40,15 +41,26 @@ class MethodSupplierSourceGeneratorTest { " Object\n" + " >> {\n" + "\n" + + " /**\n" + + " * Map, type function by field name.\n" + + " */\n" + " protected final java.util.Map<\n" + " java.lang.String,\n" + " Object\n" + " > getterByField;\n" + "\n" + + " /**\n" + + " * Constructs this.\n" + + " */\n" + " public MyClass() {\n" + " this.getterByField = createMap();\n" + " }\n" + "\n" + + " /**\n" + + " * Creates map, type function by field name.\n" + + " *\n" + + " * @return map, type function by field name\n" + + " */\n" + " protected java.util.Map<\n" + " java.lang.String,\n" + " Object\n" + @@ -62,6 +74,11 @@ class MethodSupplierSourceGeneratorTest { " return map;\n" + " }\n" + "\n" + + " /**\n" + + " * Returns map, type function by field name.\n" + + " *\n" + + " * @return map, type function by field name\n" + + " */\n" + " @Override\n" + " public java.util.Map<\n" + " java.lang.String,\n" + @@ -73,6 +90,9 @@ class MethodSupplierSourceGeneratorTest { SNAPSHOT_OF_SOURCE_WITH_PACKAGE = "" + "package my.company;\n" + "\n" + + "/**\n" + + " * Types supplier of {@link my.company.MyDomain}.\n" + + " */\n" + "@javax.annotation.Generated(\n" + " value = \"dev.alexengrig.metter.generator.MethodSupplierSourceGeneratorTest$1\")\n" + "public class MyClass implements\n" + @@ -82,15 +102,26 @@ class MethodSupplierSourceGeneratorTest { " Object\n" + " >> {\n" + "\n" + + " /**\n" + + " * Map, type function by field name.\n" + + " */\n" + " protected final java.util.Map<\n" + " java.lang.String,\n" + " Object\n" + " > getterByField;\n" + "\n" + + " /**\n" + + " * Constructs this.\n" + + " */\n" + " public MyClass() {\n" + " this.getterByField = createMap();\n" + " }\n" + "\n" + + " /**\n" + + " * Creates map, type function by field name.\n" + + " *\n" + + " * @return map, type function by field name\n" + + " */\n" + " protected java.util.Map<\n" + " java.lang.String,\n" + " Object\n" + @@ -108,6 +139,11 @@ class MethodSupplierSourceGeneratorTest { " return map;\n" + " }\n" + "\n" + + " /**\n" + + " * Returns map, type function by field name.\n" + + " *\n" + + " * @return map, type function by field name\n" + + " */\n" + " @Override\n" + " public java.util.Map<\n" + " java.lang.String,\n" + @@ -123,6 +159,16 @@ class MethodSupplierSourceGeneratorTest { protected String getMapValueType(String domainClassName) { return "Object"; } + + @Override + protected String getJavaDocTypeNameForClass() { + return "Types"; + } + + @Override + protected String getJavaDocTypeName() { + return "type"; + } }; @Test @@ -133,6 +179,16 @@ void should_create_instance() { protected String getMapValueType(String domainClassName) { return null; } + + @Override + protected String getJavaDocTypeNameForClass() { + return null; + } + + @Override + protected String getJavaDocTypeName() { + return null; + } }; assertNotNull(generator); } diff --git a/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java b/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java index 02d2f84..5ee023e 100644 --- a/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java +++ b/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -30,6 +30,9 @@ class SetterSupplierSourceGeneratorTest { static { SNAPSHOT_OF_SOURCE_WITHOUT_PACKAGE = "" + + "/**\n" + + " * Setters supplier of {@link MyDomain}.\n" + + " */\n" + "@javax.annotation.Generated(\n" + " value = \"dev.alexengrig.metter.generator.SetterSupplierSourceGenerator\")\n" + "public class MyClass implements\n" + @@ -39,15 +42,26 @@ class SetterSupplierSourceGeneratorTest { " java.util.function.BiConsumer\n" + " >> {\n" + "\n" + + " /**\n" + + " * Map, setter function by field name.\n" + + " */\n" + " protected final java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.BiConsumer\n" + " > getterByField;\n" + "\n" + + " /**\n" + + " * Constructs this.\n" + + " */\n" + " public MyClass() {\n" + " this.getterByField = createMap();\n" + " }\n" + "\n" + + " /**\n" + + " * Creates map, setter function by field name.\n" + + " *\n" + + " * @return map, setter function by field name\n" + + " */\n" + " protected java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.BiConsumer\n" + @@ -65,6 +79,11 @@ class SetterSupplierSourceGeneratorTest { " return map;\n" + " }\n" + "\n" + + " /**\n" + + " * Returns map, setter function by field name.\n" + + " *\n" + + " * @return map, setter function by field name\n" + + " */\n" + " @Override\n" + " public java.util.Map<\n" + " java.lang.String,\n" + @@ -76,6 +95,9 @@ class SetterSupplierSourceGeneratorTest { SNAPSHOT_OF_SOURCE_WITH_PACKAGE = "" + "package my.company;\n" + "\n" + + "/**\n" + + " * Setters supplier of {@link my.company.MyDomain}.\n" + + " */\n" + "@javax.annotation.Generated(\n" + " value = \"dev.alexengrig.metter.generator.SetterSupplierSourceGenerator\")\n" + "public class MyClass implements\n" + @@ -85,15 +107,26 @@ class SetterSupplierSourceGeneratorTest { " java.util.function.BiConsumer\n" + " >> {\n" + "\n" + + " /**\n" + + " * Map, setter function by field name.\n" + + " */\n" + " protected final java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.BiConsumer\n" + " > getterByField;\n" + "\n" + + " /**\n" + + " * Constructs this.\n" + + " */\n" + " public MyClass() {\n" + " this.getterByField = createMap();\n" + " }\n" + "\n" + + " /**\n" + + " * Creates map, setter function by field name.\n" + + " *\n" + + " * @return map, setter function by field name\n" + + " */\n" + " protected java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.BiConsumer\n" + @@ -111,6 +144,11 @@ class SetterSupplierSourceGeneratorTest { " return map;\n" + " }\n" + "\n" + + " /**\n" + + " * Returns map, setter function by field name.\n" + + " *\n" + + " * @return map, setter function by field name\n" + + " */\n" + " @Override\n" + " public java.util.Map<\n" + " java.lang.String,\n" + From 7afa9918a3d48090358c819750dad7c0a7921a8b Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Wed, 14 Jul 2021 07:54:32 -0700 Subject: [PATCH 25/30] Fix map field name --- .../GetterSupplierSourceGenerator.java | 10 +++++++++ .../MethodSupplierSourceGenerator.java | 19 +++++++++++----- .../SetterSupplierSourceGenerator.java | 15 ++++++++++++- .../metter/generator/package-info.java | 6 ++--- .../MethodSupplierSourceGeneratorTest.java | 22 ++++++++++++++----- .../SetterSupplierSourceGeneratorTest.java | 12 +++++----- 6 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java b/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java index b04d54d..4c3afac 100644 --- a/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java +++ b/src/main/java/dev/alexengrig/metter/generator/GetterSupplierSourceGenerator.java @@ -43,6 +43,16 @@ protected GetterSupplierSourceGenerator(boolean withGeneratedDate) { super(withGeneratedDate); } + /** + * Returns {@code getterByField}. + * + * @return {@code getterByField} + */ + @Override + protected String getMapFieldName() { + return "getterByField"; + } + /** * {@inheritDoc} * diff --git a/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java b/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java index 29b1424..1a07405 100644 --- a/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java +++ b/src/main/java/dev/alexengrig/metter/generator/MethodSupplierSourceGenerator.java @@ -25,7 +25,7 @@ * Base generator source of method supplier. * * @author Grig Alex - * @version 0.1.0 + * @version 0.2.0 * @since 0.1.0 */ public abstract class MethodSupplierSourceGenerator { @@ -67,6 +67,7 @@ protected MethodSupplierSourceGenerator(boolean withGeneratedDate) { public String generate(String className, String domainClassName, Map field2Method) { String packageName = getPackageName(className); String simpleClassName = getSimpleName(className); + String mapFieldName = getMapFieldName(); String mapValueType = getMapValueType(domainClassName); String javaDocTypeName = getJavaDocTypeName(); return new LineJoiner() @@ -90,13 +91,13 @@ public String generate(String className, String domainClassName, Map getterByField;") + .ft(" > %s;", mapFieldName) .ln() .ln(" /**") .ln(" * Constructs this.") .ln(" */") .ft(" public %s() {", simpleClassName) - .ln(" this.getterByField = createMap();") + .ft(" this.%s = createMap();", mapFieldName) .ln(" }") .ln() .ln(" /**") @@ -112,7 +113,7 @@ public String generate(String className, String domainClassName, Map map = new java.util.HashMap<>(%d);", field2Method.size()) - .mp(" map.put(\"%s\",\n %s);", (f, g) -> new Object[]{f, g}, field2Method) + .mp(" map.put(\"%s\",\n %s);", (s, f) -> new Object[]{s, f}, field2Method) .ln(" return map;") .ln(" }") .ln() @@ -126,7 +127,7 @@ public String generate(String className, String domainClassName, Map get() {") - .ln(" return getterByField;") + .ft(" return %s;", mapFieldName) .ln(" }") .ln("}") .toString(); @@ -159,6 +160,14 @@ protected String getSimpleName(String className) { return className.substring(lastIndexOfDot + 1); } + /** + * Returns a field name of map. + * + * @return field name of map + * @since 0.2.0 + */ + protected abstract String getMapFieldName(); + /** * Returns a type of map value from a domain class name. * diff --git a/src/main/java/dev/alexengrig/metter/generator/SetterSupplierSourceGenerator.java b/src/main/java/dev/alexengrig/metter/generator/SetterSupplierSourceGenerator.java index 6ba37b3..63def48 100644 --- a/src/main/java/dev/alexengrig/metter/generator/SetterSupplierSourceGenerator.java +++ b/src/main/java/dev/alexengrig/metter/generator/SetterSupplierSourceGenerator.java @@ -20,7 +20,7 @@ * Generator source of setter supplier. * * @author Grig Alex - * @version 0.1.0 + * @version 0.2.0 * @since 0.1.0 */ public class SetterSupplierSourceGenerator extends MethodSupplierSourceGenerator { @@ -43,6 +43,17 @@ protected SetterSupplierSourceGenerator(boolean withGeneratedDate) { super(withGeneratedDate); } + /** + * Returns {@code setterByField}. + * + * @return {@code setterByField} + * @since 0.2.0 + */ + @Override + protected String getMapFieldName() { + return "setterByField"; + } + /** * {@inheritDoc} * @@ -61,6 +72,7 @@ protected String getMapValueType(String domainClassName) { * Returns {@code Setters}. * * @return {@code Setters} + * @since 0.2.0 */ @Override protected String getJavaDocTypeNameForClass() { @@ -71,6 +83,7 @@ protected String getJavaDocTypeNameForClass() { * Returns {@code setter}. * * @return {@code setter} + * @since 0.2.0 */ @Override protected String getJavaDocTypeName() { diff --git a/src/main/java/dev/alexengrig/metter/generator/package-info.java b/src/main/java/dev/alexengrig/metter/generator/package-info.java index 515e86c..9c474ed 100644 --- a/src/main/java/dev/alexengrig/metter/generator/package-info.java +++ b/src/main/java/dev/alexengrig/metter/generator/package-info.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -18,7 +18,7 @@ * Generators. * * @author Grig Alex - * @version 0.1.1 + * @version 0.2.0 * @since 0.1.0 */ package dev.alexengrig.metter.generator; \ No newline at end of file diff --git a/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java b/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java index 3b53ee4..de25996 100644 --- a/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java +++ b/src/test/java/dev/alexengrig/metter/generator/MethodSupplierSourceGeneratorTest.java @@ -47,13 +47,13 @@ class MethodSupplierSourceGeneratorTest { " protected final java.util.Map<\n" + " java.lang.String,\n" + " Object\n" + - " > getterByField;\n" + + " > typeByField;\n" + "\n" + " /**\n" + " * Constructs this.\n" + " */\n" + " public MyClass() {\n" + - " this.getterByField = createMap();\n" + + " this.typeByField = createMap();\n" + " }\n" + "\n" + " /**\n" + @@ -84,7 +84,7 @@ class MethodSupplierSourceGeneratorTest { " java.lang.String,\n" + " Object\n" + " > get() {\n" + - " return getterByField;\n" + + " return typeByField;\n" + " }\n" + "}\n"; SNAPSHOT_OF_SOURCE_WITH_PACKAGE = "" + @@ -108,13 +108,13 @@ class MethodSupplierSourceGeneratorTest { " protected final java.util.Map<\n" + " java.lang.String,\n" + " Object\n" + - " > getterByField;\n" + + " > typeByField;\n" + "\n" + " /**\n" + " * Constructs this.\n" + " */\n" + " public MyClass() {\n" + - " this.getterByField = createMap();\n" + + " this.typeByField = createMap();\n" + " }\n" + "\n" + " /**\n" + @@ -149,12 +149,17 @@ class MethodSupplierSourceGeneratorTest { " java.lang.String,\n" + " Object\n" + " > get() {\n" + - " return getterByField;\n" + + " return typeByField;\n" + " }\n" + "}\n"; } final MethodSupplierSourceGenerator generator = new MethodSupplierSourceGenerator(false) { + @Override + protected String getMapFieldName() { + return "typeByField"; + } + @Override protected String getMapValueType(String domainClassName) { return "Object"; @@ -175,6 +180,11 @@ protected String getJavaDocTypeName() { void should_create_instance() { // coverage MethodSupplierSourceGenerator generator = new MethodSupplierSourceGenerator() { + @Override + protected String getMapFieldName() { + return null; + } + @Override protected String getMapValueType(String domainClassName) { return null; diff --git a/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java b/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java index 5ee023e..41831dc 100644 --- a/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java +++ b/src/test/java/dev/alexengrig/metter/generator/SetterSupplierSourceGeneratorTest.java @@ -48,13 +48,13 @@ class SetterSupplierSourceGeneratorTest { " protected final java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.BiConsumer\n" + - " > getterByField;\n" + + " > setterByField;\n" + "\n" + " /**\n" + " * Constructs this.\n" + " */\n" + " public MyClass() {\n" + - " this.getterByField = createMap();\n" + + " this.setterByField = createMap();\n" + " }\n" + "\n" + " /**\n" + @@ -89,7 +89,7 @@ class SetterSupplierSourceGeneratorTest { " java.lang.String,\n" + " java.util.function.BiConsumer\n" + " > get() {\n" + - " return getterByField;\n" + + " return setterByField;\n" + " }\n" + "}\n"; SNAPSHOT_OF_SOURCE_WITH_PACKAGE = "" + @@ -113,13 +113,13 @@ class SetterSupplierSourceGeneratorTest { " protected final java.util.Map<\n" + " java.lang.String,\n" + " java.util.function.BiConsumer\n" + - " > getterByField;\n" + + " > setterByField;\n" + "\n" + " /**\n" + " * Constructs this.\n" + " */\n" + " public MyClass() {\n" + - " this.getterByField = createMap();\n" + + " this.setterByField = createMap();\n" + " }\n" + "\n" + " /**\n" + @@ -154,7 +154,7 @@ class SetterSupplierSourceGeneratorTest { " java.lang.String,\n" + " java.util.function.BiConsumer\n" + " > get() {\n" + - " return getterByField;\n" + + " return setterByField;\n" + " }\n" + "}\n"; } From 322ce9f05720742dd3d5be3d797ff10f5e5f860f Mon Sep 17 00:00:00 2001 From: Grig Alex Date: Wed, 14 Jul 2021 07:56:51 -0700 Subject: [PATCH 26/30] Update version --- demo/build.gradle | 6 +++--- pom.xml | 6 +++--- src/main/java/dev/alexengrig/metter/package-info.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 21e867f..ced19c0 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,11 +1,11 @@ /* - * Copyright 2021 Alexengrig Dev. + * Copyright 2020-2021 Alexengrig Dev. * * 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 + * 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, @@ -19,7 +19,7 @@ plugins { } group 'dev.alexengrig' -version '0.1.1-SNAPSHOT' +version '0.2.0-SNAPSHOT' repositories { mavenCentral() diff --git a/pom.xml b/pom.xml index 989ba5c..9992a24 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,12 @@