Skip to content

Commit

Permalink
Fix InnerSpec inner API (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Dec 31, 2024
1 parent 2bab10b commit b1947a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.navercorp.fixturemonkey.api.plugin.InterfacePlugin
import com.navercorp.fixturemonkey.api.property.ConcreteTypeCandidateConcretePropertyResolver
import com.navercorp.fixturemonkey.api.property.PropertyUtils
import com.navercorp.fixturemonkey.api.type.Types.GeneratingWildcardType
import com.navercorp.fixturemonkey.customizer.InnerSpec
import com.navercorp.fixturemonkey.customizer.Values
import com.navercorp.fixturemonkey.javax.validation.plugin.JavaxValidationPlugin
import com.navercorp.fixturemonkey.javax.validation.validator.JavaxArbitraryValidator
Expand Down Expand Up @@ -1306,6 +1307,31 @@ class KotlinTest {
then(actual).isNotNull
}

@RepeatedTest(TEST_COUNT)
fun innerSpecInner() {
// given
data class ChildObject(val values: List<String>)

data class ParentObject(val list: List<ChildObject>)

// when
val actual = SUT.giveMeKotlinBuilder<ParentObject>()
.setInner {
property("list") { l ->
l.size(1)
.listElement(0) { e ->
e.inner(
InnerSpec()
.property("values") { v -> v.size(5) }
)
}
}
}.sample().list[0].values

// then
then(actual).hasSize(5)
}

companion object {
private val SUT: FixtureMonkey = FixtureMonkey.builder()
.plugin(KotlinPlugin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;

import com.navercorp.fixturemonkey.tree.NextNodePredicate;
import com.navercorp.fixturemonkey.tree.StartNodePredicate;

@API(since = "0.5.0", status = Status.MAINTAINED)
final class InnerSpecState {
Expand Down Expand Up @@ -70,7 +72,10 @@ InnerSpecState withPrefix(List<NextNodePredicate> nextNodePredicates) {

if (this.objectHolder != null) {
List<NextNodePredicate> concat = new ArrayList<>(nextNodePredicates);
concat.addAll(this.objectHolder.nextNodePredicates);
List<NextNodePredicate> setNextNodePredicates = this.objectHolder.nextNodePredicates.stream()
.filter(it -> !(it instanceof StartNodePredicate))
.collect(Collectors.toList());
concat.addAll(setNextNodePredicates);
newState.objectHolder = new NodeResolverObjectHolder(
this.objectHolder.sequence,
concat,
Expand All @@ -80,7 +85,11 @@ InnerSpecState withPrefix(List<NextNodePredicate> nextNodePredicates) {

if (this.filterHolder != null) {
List<NextNodePredicate> concat = new ArrayList<>(nextNodePredicates);
concat.addAll(this.filterHolder.nextNodePredicates);
List<NextNodePredicate> setPostConditionNextNodePredicates =
this.filterHolder.nextNodePredicates.stream()
.filter(it -> !(it instanceof StartNodePredicate))
.collect(Collectors.toList());
concat.addAll(setPostConditionNextNodePredicates);
newState.filterHolder = new FilterHolder(
this.filterHolder.sequence,
concat,
Expand All @@ -91,7 +100,11 @@ InnerSpecState withPrefix(List<NextNodePredicate> nextNodePredicates) {

if (this.containerInfoHolder != null) {
List<NextNodePredicate> concat = new ArrayList<>(nextNodePredicates);
concat.addAll(this.containerInfoHolder.nextNodePredicates);
List<NextNodePredicate> containerHolderNextNodePredicates =
this.containerInfoHolder.nextNodePredicates.stream()
.filter(it -> !(it instanceof StartNodePredicate))
.collect(Collectors.toList());
concat.addAll(containerHolderNextNodePredicates);
newState.containerInfoHolder = new ContainerInfoHolder(
this.containerInfoHolder.sequence,
concat,
Expand Down

0 comments on commit b1947a5

Please sign in to comment.