Comments (6)
넵, 저도 버전 변경에 따른 리플렉션이 원인이 아닐까?라는 추측은 하긴하였습니다.
여튼 해결책 빨리 말씀주셔서 감사합니다.
from fixture-monkey.
안녕하세요. @mygoaway 님
일단 원인부터 말씀드리면, 픽스쳐 몽키에서는 인터페이스가 입력되는 경우 다른 설정이 없다면 자동으로 익명 객체를 생성해줍니다.
MultipartFile
내부에 getResource
메소드의 반환 값인 Resource
를 생성하고, Resource
내부에 getFile
메소드의 반환 값인 File을 생성할 때 이슈가 발생하고 있습니다.
기본으로 설정하신 Introspector인 FieldReflectionArbitraryIntrospector
은 빈 생성자를 사용해 인스턴스를 생성하고, 리플렉션을 통해 값을 변경하는 방식으로 객체를 생성하고 있습니다. 문서 참조
File
은 빈 생성자가 존재하지 않아 FieldReflectionArbitraryIntrospector
으로는 생성할 수 없습니다.
원하시는 의도에 따라 해결하는 방법이 달라질 것 같습니다.
MultipartFile가 필요가 없는 경우
private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
.pushAssignableTypeArbitraryIntrospector(
MultipartFile.class,
it -> new ArbitraryIntrospectorResult(CombinableArbitrary.from((Object)null))
)
.build();
MultipartFile가 테스트에서 필요하고, 원하시는 구현체가 있는 경우
private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
.pushAssignableTypeArbitraryIntrospector(
MultipartFile.class,
it -> new ArbitraryIntrospectorResult(CombinableArbitrary.from(new MultipartFileImpl())
)
.build();
필요하신 다른 케이스가 있으시면 말씀해주시면 방법을 공유드리겠습니다.
감사합니다.
from fixture-monkey.
아, 넵! 말씀주신대로 작업하니 문제없이 처리되네요.
추가적으로 한가지 더 질문드려도 괜찮을까요?
기존 자바 8에서는 문제 안되다가 최근 프로젝트를 자바 11버전으로 업그레이드한 이후 해당 문제가 발생했는데 혹시 해당 이유도 알 수 있을까요?
from fixture-monkey.
@mygoaway
해결이 돼서 다행이네요 😄 혹시 자바11로 업그레이드하시면서 스프링 버전도 업그레이드 하셨을까요?
지금 문제가 된 메소드가 spring-web
5.1 버전부터 추가됐는데, 그 영향일 가능성이 커보입니다.
from fixture-monkey.
스프링 버전은 변경하지 않았습니다. 2.3.0 버전 사용중에 있습니다.
from fixture-monkey.
그럼 정확한 원인을 공유드리기는 어려울 것 같습니다.
일단 픽스쳐 몽키에서는 multi release가 적용이 되있어서 JDK 버전마다 동작이 달라지긴 하는데요, JDK 17에만 대응하고 있습니다. JDK11에서는 동작이 모두 동일합니다.
제 추측을 말씀드리면, JDK 버전이 변경되면서 리플렉션 동작이 달라져서 생긴 이슈일 것 같다는 생각이 듭니다.
JDK vendor마다 리플렉션 구현이 조금씩 다르다고 알고 있습니다. 실제로 리플렉션을 통해 조회한 생성자, 메소드 순서가 JDK vendor마다 다릅니다.
from fixture-monkey.
Related Issues (20)
- 코틀린 primary constructor가 private일 경우 초기화 불가능합니다.
- Make the API to use a javaGetter neater HOT 2
- Java 8 is not supported HOT 5
- Can't set a property value which represents an object of a subclass of the property type. HOT 8
- Stop generating random values HOT 3
- Call for Korean translators for document! HOT 30
- java.sql.Timestamp not recognized HOT 14
- FixtureMonkey in Kotlin (sealed class + object) HOT 2
- Unable to set value on Object HOT 3
- Unable to set list value HOT 5
- Fixture Monkey doesn't work with Kotlin value classes HOT 2
- Error while generating class where constructor as different types from parent HOT 1
- 내부 value class 프로퍼티의 생성자가 private 일 경우 테스트 객체 생성에 실패합니다. HOT 2
- Fail test depending on the constructor declaration order HOT 1
- ask; Setting Super Class Property Values in Kotlin HOT 2
- When attempting to create an instance of a Kotlin class containing a Java reference type class property, the creation fails HOT 1
- Minor bugs on the newly added translated docs HOT 1
- Class changes when setting value HOT 3
- FieldReflectionArbitraryIntrospector 사용시 Getter, Setter 없이 Fixture 생성 질문드립니다. HOT 6
- I want fields to be injected with a Kotlin Duration type HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fixture-monkey.