MatcherOperator을 확장해서 namedArbitraryBuilder을 제거하고 registeredArbitraryBuilders로만 register한 연산을 선택할 수 있도록 해야 한다.
질문 : MatcherOperator을 확장하여 name + property도 식별할 수 있게 하려고 합니다. initializeNamedArbitraryBuilderMap
에서 name과 함께 MatcherOperator
객체를 생성하고, selectName에서 입력 받은 name으로 식별을 하면 되는 것으로 이해하고 있는데 맞게 이해한 것인지 궁금합니다.
extending the MatcherOperator to remove namedArbitraryBuilder, allowing register operation selection through registeredArbitraryBuilders.
Create a 'registeredName' field in the MatcherOperator class. Then, in the 'initializeNamedArbitraryBuilderMap' method, store the name registered via the 'registerName' method in the MatcherOperator object. Subsequently, in the 'selectName' method, identify the MatcherOperator using the input name along with property.
@API(since = "0.4.0", status = Status.MAINTAINED)
public final class MatcherOperator<T> implements Matcher {
private final Matcher matcher;
private final T operator;
private final String registeredName;
...
@Override
public boolean match(Property property) {
return this.matcher.match(property) && registeredName == null;
}
public boolean match(Property property, String name) {
if (this.registeredName == null) {
return this.match(property);
}
if (this.registeredName.equals(name)) {
return this.matcher.match(property);
}
return false;
}
...
private void initializeNamedArbitraryBuilderMap(
Map<String, MatcherOperator<Function<FixtureMonkey, ? extends ArbitraryBuilder<?>>>> mapsByRegisteredName
) {
mapsByRegisteredName.forEach((name, matcherOperator) -> {
registeredArbitraryBuilders.add(
new MatcherOperator<>(matcherOperator.getMatcher(), matcherOperator.getOperator().apply(this), name)
);
});
}
@Override
public ArbitraryBuilder<T> selectName(String... names) {
ArbitraryBuilderContext builderContext = new ArbitraryBuilderContext();
for (String name : names) {
builderContext = registeredArbitraryBuilders.stream()
.filter(it -> it.match(rootProperty, name))
.map(MatcherOperator::getOperator)
.findAny()
.map(DefaultArbitraryBuilder.class::cast)
.map(DefaultArbitraryBuilder::getContext)
.orElse(new ArbitraryBuilderContext());
}
return new DefaultArbitraryBuilder<>(
this.fixtureMonkeyOptions,
this.rootProperty,
new ArbitraryResolver(
this.traverser,
this.manipulatorOptimizer,
this.monkeyManipulatorFactory,
this.fixtureMonkeyOptions,
this.monkeyContext,
this.registeredArbitraryBuilders
),
this.traverser,
this.monkeyManipulatorFactory,
builderContext.copy(),
this.registeredArbitraryBuilders,
this.monkeyContext,
this.manipulatorOptimizer,
this.fixtureMonkeyOptions.getInstantiatorProcessor()
);
}
위 코드에서 Wrapper Class는 잘 생성이 되나, SimpleObject와 같이 값을 조합해서 만드는 객체 생성에서 문제가 생겼습니다. basecase에서 문제가 생긴 것으로 추측이 되나, 아직 자세한 원인을 찾아 보지 않아 조금 더 찾아볼 계획입니다!
그 외, 한 가지 질문이 있습니다. 성아님께서 값을 property로만 식별하는 것이 아니라, property와 name으로도 식별하라고 하셨습니다. MatcherOperator 객체를 생성할 때, 위 코드와 같이 이름을 함께 등록하고 seleteName API에서 전달받은 이름과 property를 함께 사용해 값을 식별하는 방향이 맞는지 궁금합니다!