From 829c97de896209a799427a70eddd7124490f83ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Tue, 19 Nov 2024 20:47:31 +0900 Subject: [PATCH 1/9] feat : switch order of if - condition in resolveFieldName method --- .../expression/JavaGetterPropertyFieldNameResolver.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/expression/JavaGetterPropertyFieldNameResolver.java b/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/expression/JavaGetterPropertyFieldNameResolver.java index a8295d8ce..be2000a22 100644 --- a/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/expression/JavaGetterPropertyFieldNameResolver.java +++ b/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/expression/JavaGetterPropertyFieldNameResolver.java @@ -28,13 +28,14 @@ public final class JavaGetterPropertyFieldNameResolver { @Nullable public String resolveFieldName(Class targetClass, String methodName) { - if (hasPrefix(GET_PREFIX, methodName)) { + + if (isValidField(targetClass, methodName)) { + // class could be using property-style getters (e.g. java record) + return methodName; + } else if (hasPrefix(GET_PREFIX, methodName)) { return stripPrefixPropertyName(targetClass, methodName, GET_PREFIX.length()); } else if (hasPrefix(IS_PREFIX, methodName)) { return stripPrefixPropertyName(targetClass, methodName, IS_PREFIX.length()); - } else if (isValidField(targetClass, methodName)) { - // class could be using property-style getters (e.g. java record) - return methodName; } return null; From 62beb854da88bce5d63dbb391fdce3fd50f4d1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Tue, 26 Nov 2024 00:19:04 +0900 Subject: [PATCH 2/9] test: add tests of JavaGetterPropertyFieldNameResolverTest.java --- ...vaGetterPropertyFieldNameResolverTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java new file mode 100644 index 000000000..b003108eb --- /dev/null +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -0,0 +1,70 @@ +package com.navercorp.fixturemonkey.tests.java; + +import static org.junit.jupiter.api.Assertions.*; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.Test; + +import lombok.Getter; + +import com.navercorp.fixturemonkey.api.expression.JavaGetterPropertyFieldNameResolver; + +public class JavaGetterPropertyFieldNameResolverTest { + + private final JavaGetterPropertyFieldNameResolver resolver = new JavaGetterPropertyFieldNameResolver(); + + @Test + void testNonBooleanFieldWithIsPrefix() { + assertDoesNotThrow(() -> { + Method method = TestClass.class.getDeclaredMethod("getIsStatus"); + String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + assertEquals("isStatus", fieldName, "Should strip 'get' from a non-boolean getter with the 'is' prefix."); + }, "Method 'getIsStatus' should exist and not throw an exception."); + } + + @Test + void testPrimitiveTypeBooleanFieldWithIsPrefix() { + assertDoesNotThrow(() -> { + Method method = TestClass.class.getDeclaredMethod("isActive"); + String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + assertEquals("isActive", fieldName, "Should not strip the 'is' prefix from a getter for a primitive boolean field."); + }, "Method 'isActive' should exist and not throw an exception."); + } + + @Test + void testBooleanFieldWithoutIsPrefix() { + assertDoesNotThrow(() -> { + Method method = TestClass.class.getDeclaredMethod("isEnabled"); + String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + assertEquals("enabled", fieldName, "Should strip the 'is' prefix from a getter for a boolean field without the 'is' prefix in the field name."); + }, "Method 'isEnabled' should exist and not throw an exception."); + } + + @Test + void testNonBooleanFieldWithoutIsPrefix() { + assertDoesNotThrow(() -> { + Method method = TestClass.class.getDeclaredMethod("getName"); + String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + assertEquals("name", fieldName, "Should strip 'get' from a getter for a non-boolean field without the 'is' prefix."); + }, "Method 'getName' should exist and not throw an exception."); + } + + @Test + void testWrapperTypeBooleanFieldWithIsPrefix() { + assertDoesNotThrow(() -> { + Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); + String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + assertEquals("isDeleted", fieldName, "Should strip 'get' from a getter for a wrapper type Boolean field with the 'is' prefix."); + }, "Method 'getIsDeleted' should exist and not throw an exception."); + } + + @Getter + private static class TestClass { + private String isStatus; + private boolean isActive; + private boolean enabled; + private String name; + private Boolean isDeleted; + } +} From 3c0b8acfef594fb6f93b1485389d1e8adc1e4bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Sun, 1 Dec 2024 18:16:22 +0900 Subject: [PATCH 3/9] test: fix test to pass checkStyleTest --- ...vaGetterPropertyFieldNameResolverTest.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index b003108eb..d29f399bc 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -1,6 +1,7 @@ package com.navercorp.fixturemonkey.tests.java; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Method; @@ -19,7 +20,8 @@ void testNonBooleanFieldWithIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("getIsStatus"); String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); - assertEquals("isStatus", fieldName, "Should strip 'get' from a non-boolean getter with the 'is' prefix."); + assertEquals("isStatus", fieldName, + "Should strip 'get' from a non-boolean getter with the 'is' prefix."); }, "Method 'getIsStatus' should exist and not throw an exception."); } @@ -28,7 +30,8 @@ void testPrimitiveTypeBooleanFieldWithIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("isActive"); String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); - assertEquals("isActive", fieldName, "Should not strip the 'is' prefix from a getter for a primitive boolean field."); + assertEquals("isActive", fieldName, + "Should not strip the 'is' prefix from a getter for a primitive boolean field."); }, "Method 'isActive' should exist and not throw an exception."); } @@ -37,7 +40,10 @@ void testBooleanFieldWithoutIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("isEnabled"); String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); - assertEquals("enabled", fieldName, "Should strip the 'is' prefix from a getter for a boolean field without the 'is' prefix in the field name."); + assertEquals( + "enabled", fieldName, + "Should strip the 'is' prefix from " + + "a getter for a boolean field without the 'is' prefix in the field name."); }, "Method 'isEnabled' should exist and not throw an exception."); } @@ -46,7 +52,8 @@ void testNonBooleanFieldWithoutIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("getName"); String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); - assertEquals("name", fieldName, "Should strip 'get' from a getter for a non-boolean field without the 'is' prefix."); + assertEquals("name", fieldName, + "Should strip 'get' from a getter for a non-boolean field without the 'is' prefix."); }, "Method 'getName' should exist and not throw an exception."); } @@ -55,7 +62,8 @@ void testWrapperTypeBooleanFieldWithIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); - assertEquals("isDeleted", fieldName, "Should strip 'get' from a getter for a wrapper type Boolean field with the 'is' prefix."); + assertEquals("isDeleted", fieldName, + "Should strip 'get' from a getter for a wrapper type Boolean field with the 'is' prefix."); }, "Method 'getIsDeleted' should exist and not throw an exception."); } From 21b5ce0fa83d4419f355eb273c15b151753e2f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Mon, 16 Dec 2024 20:23:17 +0900 Subject: [PATCH 4/9] =?UTF-8?q?test:=20License=20=EC=B6=94=EA=B0=80,=20pub?= =?UTF-8?q?lic=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vaGetterPropertyFieldNameResolverTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index d29f399bc..8afbc8425 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -1,3 +1,21 @@ +/* + * Fixture Monkey + * + * Copyright (c) 2021-present NAVER Corp. + * + * 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 com.navercorp.fixturemonkey.tests.java; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -11,7 +29,7 @@ import com.navercorp.fixturemonkey.api.expression.JavaGetterPropertyFieldNameResolver; -public class JavaGetterPropertyFieldNameResolverTest { +class JavaGetterPropertyFieldNameResolverTest { private final JavaGetterPropertyFieldNameResolver resolver = new JavaGetterPropertyFieldNameResolver(); From af1765f375d9f6f9e2971bcad31dcabc9bf33ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Mon, 16 Dec 2024 20:23:42 +0900 Subject: [PATCH 5/9] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=8C=80=EC=83=81=20SUT=20=EB=AA=85=EB=AA=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JavaGetterPropertyFieldNameResolverTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index 8afbc8425..8fbc7cc34 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -31,13 +31,13 @@ class JavaGetterPropertyFieldNameResolverTest { - private final JavaGetterPropertyFieldNameResolver resolver = new JavaGetterPropertyFieldNameResolver(); + private final JavaGetterPropertyFieldNameResolver SUT = new JavaGetterPropertyFieldNameResolver(); @Test void testNonBooleanFieldWithIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("getIsStatus"); - String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); assertEquals("isStatus", fieldName, "Should strip 'get' from a non-boolean getter with the 'is' prefix."); }, "Method 'getIsStatus' should exist and not throw an exception."); @@ -47,7 +47,7 @@ void testNonBooleanFieldWithIsPrefix() { void testPrimitiveTypeBooleanFieldWithIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("isActive"); - String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); assertEquals("isActive", fieldName, "Should not strip the 'is' prefix from a getter for a primitive boolean field."); }, "Method 'isActive' should exist and not throw an exception."); @@ -57,7 +57,7 @@ void testPrimitiveTypeBooleanFieldWithIsPrefix() { void testBooleanFieldWithoutIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("isEnabled"); - String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); assertEquals( "enabled", fieldName, "Should strip the 'is' prefix from " @@ -69,7 +69,7 @@ void testBooleanFieldWithoutIsPrefix() { void testNonBooleanFieldWithoutIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("getName"); - String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); assertEquals("name", fieldName, "Should strip 'get' from a getter for a non-boolean field without the 'is' prefix."); }, "Method 'getName' should exist and not throw an exception."); @@ -79,7 +79,7 @@ void testNonBooleanFieldWithoutIsPrefix() { void testWrapperTypeBooleanFieldWithIsPrefix() { assertDoesNotThrow(() -> { Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); - String fieldName = resolver.resolveFieldName(TestClass.class, method.getName()); + String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); assertEquals("isDeleted", fieldName, "Should strip 'get' from a getter for a wrapper type Boolean field with the 'is' prefix."); }, "Method 'getIsDeleted' should exist and not throw an exception."); From 7d4a940b894d02a2a2635ae34c2fe3974321006e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Mon, 16 Dec 2024 20:39:09 +0900 Subject: [PATCH 6/9] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vaGetterPropertyFieldNameResolverTest.java | 60 +++++++------------ 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index 8fbc7cc34..b42de8538 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -18,8 +18,7 @@ package com.navercorp.fixturemonkey.tests.java; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.BDDAssertions.then; import java.lang.reflect.Method; @@ -34,55 +33,38 @@ class JavaGetterPropertyFieldNameResolverTest { private final JavaGetterPropertyFieldNameResolver SUT = new JavaGetterPropertyFieldNameResolver(); @Test - void testNonBooleanFieldWithIsPrefix() { - assertDoesNotThrow(() -> { - Method method = TestClass.class.getDeclaredMethod("getIsStatus"); - String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); - assertEquals("isStatus", fieldName, - "Should strip 'get' from a non-boolean getter with the 'is' prefix."); - }, "Method 'getIsStatus' should exist and not throw an exception."); + void testNonBooleanFieldWithIsPrefix() throws NoSuchMethodException { + Method method = TestClass.class.getDeclaredMethod("getIsStatus"); + + then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isStatus"); } @Test - void testPrimitiveTypeBooleanFieldWithIsPrefix() { - assertDoesNotThrow(() -> { - Method method = TestClass.class.getDeclaredMethod("isActive"); - String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); - assertEquals("isActive", fieldName, - "Should not strip the 'is' prefix from a getter for a primitive boolean field."); - }, "Method 'isActive' should exist and not throw an exception."); + void testPrimitiveTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { + Method method = TestClass.class.getDeclaredMethod("isActive"); + + then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isActive"); } @Test - void testBooleanFieldWithoutIsPrefix() { - assertDoesNotThrow(() -> { - Method method = TestClass.class.getDeclaredMethod("isEnabled"); - String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); - assertEquals( - "enabled", fieldName, - "Should strip the 'is' prefix from " - + "a getter for a boolean field without the 'is' prefix in the field name."); - }, "Method 'isEnabled' should exist and not throw an exception."); + void testBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { + Method method = TestClass.class.getDeclaredMethod("isEnabled"); + + then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("enabled"); } @Test - void testNonBooleanFieldWithoutIsPrefix() { - assertDoesNotThrow(() -> { - Method method = TestClass.class.getDeclaredMethod("getName"); - String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); - assertEquals("name", fieldName, - "Should strip 'get' from a getter for a non-boolean field without the 'is' prefix."); - }, "Method 'getName' should exist and not throw an exception."); + void testNonBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { + Method method = TestClass.class.getDeclaredMethod("getName"); + + then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("name"); } @Test - void testWrapperTypeBooleanFieldWithIsPrefix() { - assertDoesNotThrow(() -> { - Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); - String fieldName = SUT.resolveFieldName(TestClass.class, method.getName()); - assertEquals("isDeleted", fieldName, - "Should strip 'get' from a getter for a wrapper type Boolean field with the 'is' prefix."); - }, "Method 'getIsDeleted' should exist and not throw an exception."); + void testWrapperTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { + Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); + + then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isDeleted"); } @Getter From bc731d16e2ee2cd179eafaf94bb45b5a757e5bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Mon, 16 Dec 2024 20:52:11 +0900 Subject: [PATCH 7/9] =?UTF-8?q?test:=20style=20=EA=B7=9C=EC=95=BD=20?= =?UTF-8?q?=EC=A4=80=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JavaGetterPropertyFieldNameResolverTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index b42de8538..7028b7d40 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -30,41 +30,41 @@ class JavaGetterPropertyFieldNameResolverTest { - private final JavaGetterPropertyFieldNameResolver SUT = new JavaGetterPropertyFieldNameResolver(); + private final JavaGetterPropertyFieldNameResolver sut = new JavaGetterPropertyFieldNameResolver(); @Test void testNonBooleanFieldWithIsPrefix() throws NoSuchMethodException { Method method = TestClass.class.getDeclaredMethod("getIsStatus"); - then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isStatus"); + then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isStatus"); } @Test void testPrimitiveTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { Method method = TestClass.class.getDeclaredMethod("isActive"); - then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isActive"); + then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isActive"); } @Test void testBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { Method method = TestClass.class.getDeclaredMethod("isEnabled"); - then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("enabled"); + then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("enabled"); } @Test void testNonBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { Method method = TestClass.class.getDeclaredMethod("getName"); - then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("name"); + then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("name"); } @Test void testWrapperTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); - then(SUT.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isDeleted"); + then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isDeleted"); } @Getter From 259326e3997d4976b1e49af868509a908fe6a02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Sat, 21 Dec 2024 17:32:32 +0900 Subject: [PATCH 8/9] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vaGetterPropertyFieldNameResolverTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index 7028b7d40..5142afe7c 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -34,41 +34,41 @@ class JavaGetterPropertyFieldNameResolverTest { @Test void testNonBooleanFieldWithIsPrefix() throws NoSuchMethodException { - Method method = TestClass.class.getDeclaredMethod("getIsStatus"); + Method method = JavaGetterObject.class.getDeclaredMethod("getIsStatus"); - then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isStatus"); + then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("isStatus"); } @Test void testPrimitiveTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { - Method method = TestClass.class.getDeclaredMethod("isActive"); + Method method = JavaGetterObject.class.getDeclaredMethod("isActive"); - then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isActive"); + then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("isActive"); } @Test void testBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { - Method method = TestClass.class.getDeclaredMethod("isEnabled"); + Method method = JavaGetterObject.class.getDeclaredMethod("isEnabled"); - then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("enabled"); + then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("enabled"); } @Test void testNonBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { - Method method = TestClass.class.getDeclaredMethod("getName"); + Method method = JavaGetterObject.class.getDeclaredMethod("getName"); - then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("name"); + then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("name"); } @Test void testWrapperTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { - Method method = TestClass.class.getDeclaredMethod("getIsDeleted"); + Method method = JavaGetterObject.class.getDeclaredMethod("getIsDeleted"); - then(sut.resolveFieldName(TestClass.class, method.getName())).isEqualTo("isDeleted"); + then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("isDeleted"); } @Getter - private static class TestClass { + private static class JavaGetterObject { private String isStatus; private boolean isActive; private boolean enabled; From 465795d50d2cc61a5f7bb49ff3d19e0b37a6a01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B1=B4=ED=9A=8C?= Date: Sun, 29 Dec 2024 16:28:28 +0900 Subject: [PATCH 9/9] =?UTF-8?q?test:=20public=20API=EB=A5=BC=20=ED=86=B5?= =?UTF-8?q?=ED=95=9C=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EA=B8=B0=EB=B0=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vaGetterPropertyFieldNameResolverTest.java | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java index 5142afe7c..e4b719693 100644 --- a/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java +++ b/fixture-monkey-tests/java-tests/src/test/java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java @@ -18,55 +18,60 @@ package com.navercorp.fixturemonkey.tests.java; -import static org.assertj.core.api.BDDAssertions.then; +import static com.navercorp.fixturemonkey.api.expression.JavaGetterMethodPropertySelector.javaGetter; +import static com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT; +import static org.assertj.core.api.BDDAssertions.thenCode; -import java.lang.reflect.Method; - -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.RepeatedTest; +import lombok.AllArgsConstructor; import lombok.Getter; -import com.navercorp.fixturemonkey.api.expression.JavaGetterPropertyFieldNameResolver; +import com.navercorp.fixturemonkey.FixtureMonkey; +import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector; class JavaGetterPropertyFieldNameResolverTest { - private final JavaGetterPropertyFieldNameResolver sut = new JavaGetterPropertyFieldNameResolver(); - - @Test - void testNonBooleanFieldWithIsPrefix() throws NoSuchMethodException { - Method method = JavaGetterObject.class.getDeclaredMethod("getIsStatus"); + private static final FixtureMonkey SUT = FixtureMonkey.builder() + .objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) + .build(); - then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("isStatus"); + @RepeatedTest(TEST_COUNT) + void testNonBooleanFieldWithIsPrefix() { + thenCode(SUT.giveMeBuilder(JavaGetterObject.class) + .set(javaGetter(JavaGetterObject::getIsStatus), "javaGetterStringStatus")::sample) + .doesNotThrowAnyException(); } - @Test - void testPrimitiveTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { - Method method = JavaGetterObject.class.getDeclaredMethod("isActive"); - - then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("isActive"); + @RepeatedTest(TEST_COUNT) + void testPrimitiveTypeBooleanFieldWithIsPrefix() { + thenCode(SUT.giveMeBuilder(JavaGetterObject.class) + .set(javaGetter(JavaGetterObject::isActive), true)::sample) + .doesNotThrowAnyException(); } - @Test - void testBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { - Method method = JavaGetterObject.class.getDeclaredMethod("isEnabled"); - - then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("enabled"); + @RepeatedTest(TEST_COUNT) + void testBooleanFieldWithoutIsPrefix() { + thenCode(SUT.giveMeBuilder(JavaGetterObject.class) + .set(javaGetter(JavaGetterObject::isEnabled), true)::sample) + .doesNotThrowAnyException(); } - @Test - void testNonBooleanFieldWithoutIsPrefix() throws NoSuchMethodException { - Method method = JavaGetterObject.class.getDeclaredMethod("getName"); - - then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("name"); + @RepeatedTest(TEST_COUNT) + void testNonBooleanFieldWithoutIsPrefix() { + thenCode(SUT.giveMeBuilder(JavaGetterObject.class) + .set(javaGetter(JavaGetterObject::getName), "javaGetterObjectName")::sample) + .doesNotThrowAnyException(); } - @Test - void testWrapperTypeBooleanFieldWithIsPrefix() throws NoSuchMethodException { - Method method = JavaGetterObject.class.getDeclaredMethod("getIsDeleted"); - - then(sut.resolveFieldName(JavaGetterObject.class, method.getName())).isEqualTo("isDeleted"); + @RepeatedTest(TEST_COUNT) + void testWrapperTypeBooleanFieldWithIsPrefix() { + thenCode(SUT.giveMeBuilder(JavaGetterObject.class) + .set(javaGetter(JavaGetterObject::getIsDeleted), true)::sample) + .doesNotThrowAnyException(); } + @AllArgsConstructor @Getter private static class JavaGetterObject { private String isStatus;