-
Notifications
You must be signed in to change notification settings - Fork 118
Refactor : Adjust resolveFieldName Method Logic to Correctly Handle Primitive boolean Field Names #1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seongahjo
merged 13 commits into
naver:main
from
rawfishthelgh:refactor/switch_condition_order
Mar 4, 2025
Merged
Refactor : Adjust resolveFieldName Method Logic to Correctly Handle Primitive boolean Field Names #1096
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
829c97d
feat : switch order of if - condition in resolveFieldName method
rawfishthelgh 62beb85
test: add tests of JavaGetterPropertyFieldNameResolverTest.java
rawfishthelgh 3c0b8ac
test: fix test to pass checkStyleTest
rawfishthelgh 21b5ce0
test: License 추가, public 제거
rawfishthelgh af1765f
test: 테스트 대상 SUT 명명
rawfishthelgh 7d4a940
test: 테스트 컨벤션 통일
rawfishthelgh bc731d1
test: style 규약 준수
rawfishthelgh 259326e
test: 테스트클래스 네이밍 변경
rawfishthelgh 465795d
test: public API를 통한 생성자 기반 테스트 변경
rawfishthelgh 6285c1c
test: set 연산 동작 검증 추가
rawfishthelgh aa3ec87
test: 와일드카드 import 해제
rawfishthelgh ce763aa
test: import 순서 변경
rawfishthelgh 693c1d5
test: 테스트 메소드 네이밍 및 테스트 순서 변경
rawfishthelgh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
.../java/com/navercorp/fixturemonkey/tests/java/JavaGetterPropertyFieldNameResolverTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * 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 com.navercorp.fixturemonkey.api.expression.JavaGetterMethodPropertySelector.javaGetter; | ||
| import static com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT; | ||
| import static org.assertj.core.api.BDDAssertions.then; | ||
|
|
||
| import org.junit.jupiter.api.RepeatedTest; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| import com.navercorp.fixturemonkey.FixtureMonkey; | ||
| import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector; | ||
|
|
||
| class JavaGetterPropertyFieldNameResolverTest { | ||
| private static final FixtureMonkey SUT = FixtureMonkey.builder() | ||
| .objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE) | ||
| .build(); | ||
|
|
||
| @RepeatedTest(TEST_COUNT) | ||
| void nonBooleanFieldWithIsPrefixReturns() { | ||
| JavaGetterObject actual = SUT.giveMeBuilder(JavaGetterObject.class) | ||
| .set(javaGetter(JavaGetterObject::getIsStatus), "javaGetterStringStatus") | ||
| .sample(); | ||
|
|
||
| then(actual.getIsStatus()).isEqualTo("javaGetterStringStatus"); | ||
| } | ||
|
|
||
| @RepeatedTest(TEST_COUNT) | ||
| void primitiveTypeBooleanFieldWithIsPrefixReturns() { | ||
| JavaGetterObject actual = SUT.giveMeBuilder(JavaGetterObject.class) | ||
| .set(javaGetter(JavaGetterObject::isActive), true) | ||
| .sample(); | ||
|
|
||
| then(actual.isActive).isTrue(); | ||
| } | ||
|
|
||
| @RepeatedTest(TEST_COUNT) | ||
| void booleanFieldWithoutIsPrefixReturns() { | ||
| JavaGetterObject actual = SUT.giveMeBuilder(JavaGetterObject.class) | ||
| .set(javaGetter(JavaGetterObject::isEnabled), true) | ||
| .sample(); | ||
|
|
||
| then(actual.isEnabled()).isTrue(); | ||
| } | ||
|
|
||
| @RepeatedTest(TEST_COUNT) | ||
| void nonBooleanFieldWithoutIsPrefixReturns() { | ||
| JavaGetterObject actual = SUT.giveMeBuilder(JavaGetterObject.class) | ||
| .set(javaGetter(JavaGetterObject::getName), "javaGetterObjectName") | ||
| .sample(); | ||
|
|
||
| then(actual.getName()).isEqualTo("javaGetterObjectName"); | ||
| } | ||
|
|
||
| @RepeatedTest(TEST_COUNT) | ||
| void wrapperTypeBooleanFieldWithIsPrefixReturns() { | ||
| JavaGetterObject actual = SUT.giveMeBuilder(JavaGetterObject.class) | ||
| .set(javaGetter(JavaGetterObject::getIsDeleted), true) | ||
| .sample(); | ||
|
|
||
| then(actual.isDeleted).isTrue(); | ||
| } | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| private static class JavaGetterObject { | ||
| private String isStatus; | ||
| private boolean isActive; | ||
| private boolean enabled; | ||
| private String name; | ||
| private Boolean isDeleted; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하위호환을 보장하고 안전하게 변경됨을 보장하기 위해 다음 테스트들이 추가되면 좋을 것 같습니다.
is가 이름의 prefix로 붙은 boolean이 아닌 필드를 setis가 이름의 prefix로 붙지않은 boolean의 필드를 setis가 이름의 prefix로 붙은 boolean인 필드를 setis가 이름의 prefix로 붙지않은 boolean이 아닌 필드를 setUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 추가했습니다!
추가로 Boolean 필드가 Wrapper Type일 경우와 Primitive Type일 경우의 테스트도 작성했습니다.