Skip to content
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

FieldReflectionArbitraryIntrospector 사용시 Getter, Setter 없이 Fixture 생성 질문드립니다. #961

Open
YunNote opened this issue Mar 22, 2024 · 6 comments
Labels
question Further information is requested

Comments

@YunNote
Copy link
Contributor

YunNote commented Mar 22, 2024

Describe your question

생성할 클래스는 인자가 없는 생성자(또는 기본 생성자)와 getter 또는 setter 중 하나를 가져야 합니다. 라고 설명이 되어있는것으로 확인하였습니다.

테스트시 getter, setter가 없이 기본생성자만 있어도 값이 설정이되는것 같습니다.

해당 부분 제가 잘못이해하였는지 궁금합니다.

fixtureMonkey 버전은 1.0.14 사용중입니다.

@YunNote YunNote added the question Further information is requested label Mar 22, 2024
@seongahjo
Copy link
Contributor

@YunNote 님 안녕하세요.
FieldReflectionArbitraryIntrospector는 리플렉션을 사용해 필드를 설정해주는 ArbitraryIntrospector라서 객체는 생성될 수 있으나 getter, setter 가 있어야 필드를 정상적으로 설정해줍니다.

아래 테스트를 통해 확인했을 때도 null로 생성이 됩니다. 혹시 어떤 경우에 기본 생성자만 있을 때 필드도 설정이 되는지 재현 가능한 케이스를 공유해주실 수 있을까요?

public class NoGetterNoSetter {
	private final String string;
	private final String integer;

	public NoGetterNoSetter(String string, String integer) {
		this.string = string;
		this.integer = integer;
	}
}
@Test
	void noGetterNoSetter(){
		FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
			.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
			.build();

		NoGetterNoSetter actual = fixtureMonkey.giveMeOne(NoGetterNoSetter.class);

		then(actual).isNull();
	}

@YunNote
Copy link
Contributor Author

YunNote commented Mar 26, 2024

@seongahjo 님 안녕하세요

image

위 사진처럼 코드를 생성하였습니다.

NoGetterNoSetter 클래스처럼 final 및 생성자 추가 후 실행시에는 null로 생성되지 않는것 확인하였습니다.

반드시 final로 사용하였을때문 생성이 안되는것이지 궁금합니다!

@seongahjo
Copy link
Contributor

seongahjo commented Mar 27, 2024

@YunNote
말씀하신 것처럼 다음과 같이 final이 아닌 필드를 가진 경우에 필드 값을 제어할 수 있는 FieldAccessor를 생성 가능하니까 리플렉션 사용이 가능하겠네요.
image

저희 팀 내부에서는 가변 객체를 잘 사용안해서 확인을 못하고 가이드를 잘못드렸군요. 확인 감사합니다!
혹시 괜찮으시면 문서에 수정 부탁드려도 괜찮을까요?

@YunNote
Copy link
Contributor Author

YunNote commented Mar 27, 2024

@seongahjo 님 안녕하세요
먼저 빠르게 확인해주셔서 감사합니다!

해당 FieldReflectionArbitraryIntrospector 설명에 대한 부분 말씀해주시는 것일까요??
가능하다면 수정해서 PR 요청 따로 드리면 되는지 가이드라인이 궁금합니다! (처음입니다 ..)

@seongahjo
Copy link
Contributor

seongahjo commented Mar 27, 2024

@YunNote
넵 맞습니다. FieldReflectionArbitraryIntrospector의 설명을 final이 아닌 변수가 있으면 사용 가능하다 정도로 변경하면 어떨까 싶습니다.

아래 참조하시면 어떻게 문서 기여하는지 나와있습니다!
https://github.com/naver/fixture-monkey/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-document

문서가 지금 영어/한글가 있어서 두곳에 반영이 되야할 것 같습니다.

@YunNote
Copy link
Contributor Author

YunNote commented Mar 27, 2024

@seongahjo
넵 감사합니다!

작성하여 요청드리겠습니다 !
감사합니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants