Skip to content

Commit

Permalink
Complete code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
YongGoose committed Nov 8, 2024
1 parent fa4a08c commit d7f8333
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
package com.navercorp.fixturemonkey.api.matcher;

public interface MatcherMetadata {
String getName();
String getMatcherAlias();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ public NamedMatcher(Matcher matcher, String registeredName) {
this.registeredName = registeredName;
}

public boolean matchRegisteredName(String registeredName) {
return this.registeredName.equals(registeredName);
}

@Override
public boolean match(Property property) {
return this.matcher.match(property);
}

@Override
public boolean match(Property property, MatcherMetadata matcherMetadata) {
return this.matcher.match(property) && registeredName.equals(matcherMetadata.getName());
return this.matcher.match(property) && registeredName.equals(matcherMetadata.getMatcherAlias());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

package com.navercorp.fixturemonkey.api.matcher;

public class NamedMatcherMetadata implements MatcherMetadata {
public final class NamedMatcherMetadata implements MatcherMetadata {
private final String selectedName;

public NamedMatcherMetadata(String selectedName) {
this.selectedName = selectedName;
}

@Override
public String getName() {
public String getMatcherAlias() {
return selectedName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.navercorp.fixturemonkey.api.instantiator.InstantiatorProcessor;
import com.navercorp.fixturemonkey.api.lazy.LazyArbitrary;
import com.navercorp.fixturemonkey.api.matcher.MatcherOperator;
import com.navercorp.fixturemonkey.api.matcher.NamedMatcher;
import com.navercorp.fixturemonkey.api.matcher.NamedMatcherMetadata;
import com.navercorp.fixturemonkey.api.option.FixtureMonkeyOptions;
import com.navercorp.fixturemonkey.api.property.PropertyNameResolver;
Expand Down Expand Up @@ -185,18 +184,6 @@ public ArbitraryBuilder<T> setLazy(PropertySelector propertySelector, Supplier<?
}

public ArbitraryBuilder<T> selectName(String... names) {
Stream.of(names).forEach(name -> {
boolean matched = registeredArbitraryBuilders.stream()
.map(MatcherOperator::getMatcher)
.filter(NamedMatcher.class::isInstance)
.map(NamedMatcher.class::cast)
.anyMatch(operator -> operator.matchRegisteredName(name));

if (!matched) {
throw new IllegalArgumentException("Given name is not registered. name: " + name);
}
});

ArbitraryBuilderContext builderContext = registeredArbitraryBuilders.stream()
.filter(operator -> Arrays.stream(names)
.anyMatch(name -> operator.match(rootProperty, new NamedMatcherMetadata(name)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,18 +840,6 @@ void registeredNameWithSameRegisteredName() {
.hasMessage("Duplicated ArbitraryBuilder name: test");
}

@Property
void registeredNameWithUnregisteredName() {
FixtureMonkey sut = FixtureMonkey.builder()
.build();

thenThrownBy(() -> sut.giveMeBuilder(SimpleObject.class)
.selectName("test3")
.sample()
).isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage("Given name is not registered. name: test3");
}

@Property
void generateSampleListWithRegisteredNames() {
FixtureMonkey sut = FixtureMonkey.builder()
Expand Down

0 comments on commit d7f8333

Please sign in to comment.