Skip to content

Commit

Permalink
Fix not caching when registered
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Jun 15, 2023
1 parent a414019 commit af72772
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Fixture Monkey
*
* Copyright (c) 2021-present NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.fixturemonkey.tests.java;

import java.util.List;

import lombok.Value;

class ImmutableDepthTestSpecs {
@Value
public static class OneDepthStringValue {
String value;
}

@Value
public static class TwoDepthStringValue {
OneDepthStringValue value;
}

@Value
public static class DepthStringValueList {
List<OneDepthStringValue> oneDepthList;
List<TwoDepthStringValue> twoDepthList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.junit.jupiter.api.RepeatedTest;

import net.jqwik.api.Arbitraries;

import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;
import com.navercorp.fixturemonkey.api.type.TypeReference;
import com.navercorp.fixturemonkey.resolver.ArbitraryBuilderCandidateFactory;
import com.navercorp.fixturemonkey.resolver.ArbitraryBuilderCandidateList;
import com.navercorp.fixturemonkey.tests.java.ImmutableDepthTestSpecs.DepthStringValueList;
import com.navercorp.fixturemonkey.tests.java.ImmutableDepthTestSpecs.OneDepthStringValue;
import com.navercorp.fixturemonkey.tests.java.ImmutableDepthTestSpecs.TwoDepthStringValue;
import com.navercorp.fixturemonkey.tests.java.ImmutableGenericTypeSpecs.GenericArrayObject;
import com.navercorp.fixturemonkey.tests.java.ImmutableGenericTypeSpecs.GenericImplementationObject;
import com.navercorp.fixturemonkey.tests.java.ImmutableGenericTypeSpecs.GenericObject;
Expand Down Expand Up @@ -439,4 +448,35 @@ void fixedThreeGenericObjectProperty() {
then(actual.getValue2()).isNotNull();
then(actual.getValue3()).isNotNull();
}

@RepeatedTest(TEST_COUNT)
void registerListWouldNotCached() {
AtomicInteger sequence = new AtomicInteger();
FixtureMonkey sut = FixtureMonkey.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.registerGroup(() -> ArbitraryBuilderCandidateList.create()
.add(
ArbitraryBuilderCandidateFactory
.of(DepthStringValueList.class)
.builder(builder -> builder.size("twoDepthList", 3))
)
.add(
ArbitraryBuilderCandidateFactory
.of(OneDepthStringValue.class)
.builder(builder -> builder.set(
"value",
Arbitraries.ofSuppliers(() -> String.valueOf(sequence.getAndIncrement()))
))
)
)
.build();

Set<String> actual = sut.giveMe(DepthStringValueList.class, 3).stream()
.flatMap(it -> it.getTwoDepthList().stream())
.map(TwoDepthStringValue::getValue)
.map(OneDepthStringValue::getValue)
.collect(Collectors.toSet());

then(actual).hasSize(9);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ public List<ObjectNode> resolve(ObjectNode objectNode) {
for (ObjectNode node : objectNodes) {
ObjectNode parent = node.getParent();
while (parent != null) {
if (!parent.isNotManipulated()) {
break;
}
parent.setManipulated(true);
parent = parent.getParent();
}
Expand Down

0 comments on commit af72772

Please sign in to comment.