Skip to content

Commit

Permalink
Implement random selection
Browse files Browse the repository at this point in the history
Signed-off-by: yongjunhong <[email protected]>
  • Loading branch information
YongGoose committed Nov 29, 2024
1 parent e508ba8 commit 06111d8
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static java.util.stream.Collectors.toList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -36,6 +37,7 @@
import com.navercorp.fixturemonkey.api.matcher.NamedMatcher;
import com.navercorp.fixturemonkey.api.option.FixtureMonkeyOptions;
import com.navercorp.fixturemonkey.api.property.RootProperty;
import com.navercorp.fixturemonkey.api.random.Randoms;
import com.navercorp.fixturemonkey.api.type.LazyAnnotatedType;
import com.navercorp.fixturemonkey.api.type.TypeReference;
import com.navercorp.fixturemonkey.customizer.ArbitraryManipulator;
Expand Down Expand Up @@ -204,13 +206,18 @@ private void initializeRegisteredArbitraryBuilders(
private void initializeNamedArbitraryBuilderMap(
Map<String, MatcherOperator<Function<FixtureMonkey, ? extends ArbitraryBuilder<?>>>> mapsByRegisteredName
) {
mapsByRegisteredName.forEach((registeredName, matcherOperator) -> {
registeredArbitraryBuilders.add(
List<String> registeredNames = new ArrayList<>(mapsByRegisteredName.keySet());
Collections.shuffle(registeredNames, Randoms.current());

for (String registeredName : registeredNames) {
MatcherOperator<Function<FixtureMonkey, ? extends ArbitraryBuilder<?>>> matcherOperator =
mapsByRegisteredName.get(registeredName);
this.registeredArbitraryBuilders.add(
new MatcherOperator<>(
new NamedMatcher(matcherOperator.getMatcher(), registeredName),
matcherOperator.getOperator().apply(this)
)
);
});
}
}
}

0 comments on commit 06111d8

Please sign in to comment.