Skip to content

Commit

Permalink
Add setSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Dec 30, 2021
1 parent 83f6e4a commit 49fc22a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import com.navercorp.fixturemonkey.arbitrary.AbstractArbitrarySet;
import com.navercorp.fixturemonkey.arbitrary.ArbitraryExpression;
import com.navercorp.fixturemonkey.arbitrary.ArbitraryExpressionManipulator;
import com.navercorp.fixturemonkey.arbitrary.ArbitraryNode;
import com.navercorp.fixturemonkey.arbitrary.ArbitraryNullity;
import com.navercorp.fixturemonkey.arbitrary.ArbitrarySet;
Expand Down Expand Up @@ -237,6 +238,8 @@ public ArbitraryBuilder<T> set(String expression, @Nullable Object value) {
return this.set(expression, (Arbitrary<T>)value);
} else if (value instanceof ArbitraryBuilder) {
return this.setBuilder(expression, (ArbitraryBuilder<?>)value);
} else if (value instanceof ExpressionSpec) {
return this.setSpec(expression, (ExpressionSpec)value);
}
ArbitraryExpression arbitraryExpression = ArbitraryExpression.from(expression);
this.builderManipulators.add(new ArbitrarySet<>(arbitraryExpression, value));
Expand Down Expand Up @@ -570,6 +573,18 @@ private List<BuilderManipulator> getActiveManipulators() {
return activeManipulators;
}

private ArbitraryBuilder<T> setSpec(String expression, ExpressionSpec expressionSpec) {
for (BuilderManipulator builderManipulator : expressionSpec.getBuilderManipulators()) {
if (builderManipulator instanceof ArbitraryExpressionManipulator) {
ArbitraryExpressionManipulator arbitraryExpressionManipulator =
(ArbitraryExpressionManipulator)builderManipulator;
arbitraryExpressionManipulator.addPrefix(expression);
}
}
spec(expressionSpec);
return this;
}

private List<BuilderManipulator> extractOrderedManipulatorsFrom(List<BuilderManipulator> manipulators) {
return manipulators.stream()
.filter(it -> !(it instanceof MetadataManipulator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import com.navercorp.fixturemonkey.ArbitraryBuilder;
import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.customizer.ExpressionSpec;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.DefaultArbitraryGroup;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.DefaultArbitraryGroup2;
import com.navercorp.fixturemonkey.test.FixtureMonkeyTestSpecs.DuplicateArbitraryGroup;
Expand Down Expand Up @@ -1310,4 +1311,16 @@ void copyValidOnly() {
.copy()
.sample());
}

@Property
void setSpec() {
ExpressionSpec expressionSpec = new ExpressionSpec()
.set("value", "test");

StringAndInt actual = SUT.giveMeBuilder(StringAndInt.class)
.set("value1", expressionSpec)
.sample();

then(actual.getValue1().getValue()).isEqualTo("test");
}
}

0 comments on commit 49fc22a

Please sign in to comment.