Skip to content

Commit

Permalink
Fix not registering size API if decomposing (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Nov 22, 2024
1 parent bcbe281 commit d4feae0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/content/v1.1.x-kor/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
## v.1.1.4
Fix not registering size API if decomposing.

sectionEnd

sectionStart
## v.1.1.3
Fix generating empty String with @Size annotation.
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.1.x/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
## v.1.1.4
Fix not registering size API if decomposing.

sectionEnd

sectionStart
## v.1.1.3
Fix generating empty String with @Size annotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ class KotlinTest {
}

@Test
fun sizeZero(){
fun sizeZero() {
// given
class StringWithSizeZero(
@field:Size(min = 0, max = 0)
Expand All @@ -1069,6 +1069,34 @@ class KotlinTest {
then(actual).isEqualTo("")
}

@Test
fun setAndRegister() {
// given
class ListStringObject(val list: List<String>)
class ListStringObjectObject(val value: ListStringObject)

val sut = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.register(ListStringObjectObject::class.java) {
it.giveMeBuilder<ListStringObjectObject>()
.size("value.list", 3)
}
.build()

val set = ListStringObject(listOf("a", "b"))

// when
val actual = sut.giveMeBuilder<ListStringObjectObject>()
.set("value", set)
.sample()
.value
.list

// then
val expected = set.list
then(actual).isEqualTo(expected)
}

companion object {
private val SUT: FixtureMonkey = FixtureMonkey.builder()
.plugin(KotlinPlugin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,19 @@ public final class ObjectNode implements ObjectTreeNode {
private final List<Function<CombinableArbitrary<?>, CombinableArbitrary<?>>> arbitraryCustomizers =
new ArrayList<>();

private final LazyArbitrary<Boolean> childManipulated = LazyArbitrary.lazy(() -> {
for (ObjectNode child : this.resolveChildren()) {
if (child.manipulated() || child.childManipulated.getValue()) {
return true;
}
}

return false;
});

private final LazyArbitrary<Boolean> childNotCacheable = LazyArbitrary.lazy(() -> {
for (ObjectNode child : this.resolveChildren()) {
if (child.manipulated() || child.childNotCacheable.getValue() || child.treeProperty.isContainer()) {
if (childManipulated.getValue() || child.treeProperty.isContainer()) {
return true;
}
}
Expand Down Expand Up @@ -257,6 +267,10 @@ public boolean manipulated() {
return !manipulators.isEmpty() || !containerInfoManipulators.isEmpty();
}

public boolean childManipulated() {
return this.childManipulated.getValue();
}

public boolean cacheable() {
return !manipulated() && !treeProperty.isContainer() && !childNotCacheable.getValue();
}
Expand Down Expand Up @@ -293,6 +307,7 @@ public void expand(TypeDefinition typeDefinition) {
typeDefinition.getPropertyGenerator()
.generateChildProperties(typeDefinition.getResolvedProperty()),
this.nullInject,
false,
this.traverseContext
);
}
Expand Down Expand Up @@ -320,6 +335,7 @@ public void expand() {
typeDefinition.getPropertyGenerator()
.generateChildProperties(typeDefinition.getResolvedProperty()),
this.nullInject,
false,
this.traverseContext
).stream();
}
Expand All @@ -346,6 +362,7 @@ public void forceExpand() {
typeDefinition.getPropertyGenerator()
.generateChildProperties(typeDefinition.getResolvedProperty()),
this.nullInject,
false,
traverseContext.withParentProperties()
).stream();
}
Expand All @@ -369,6 +386,7 @@ public void forceExpand(TypeDefinition typeDefinition) {
typeDefinition.getPropertyGenerator()
.generateChildProperties(typeDefinition.getResolvedProperty()),
this.nullInject,
false,
this.traverseContext.withParentProperties()
);
}
Expand Down Expand Up @@ -402,6 +420,7 @@ private Stream<ObjectNode> expandContainerNode(TypeDefinition typeDefinition, Tr
typeDefinition.getResolvedProperty(),
elementProperties,
this.nullInject,
true,
traverseContext
).stream();
}
Expand Down Expand Up @@ -562,11 +581,20 @@ private List<ObjectNode> generateChildrenNodes(
Property resolvedParentProperty,
List<Property> childProperties,
double parentNullInject,
boolean container,
TraverseContext context
) {
List<ObjectNode> children = new ArrayList<>();

for (int sequence = 0; sequence < childProperties.size(); sequence++) {
boolean childNodeAlreadyExists = this.children != null && this.children.size() > sequence;
if (container && childNodeAlreadyExists) {
ObjectNode currentChildNode = this.children.get(sequence);
if (currentChildNode.manipulated() || currentChildNode.childManipulated()) {
children.add(currentChildNode);
continue;
}
}
Property childProperty = childProperties.get(sequence);

if (context.isTraversed(childProperty)
Expand All @@ -593,7 +621,8 @@ private static ContainerInfoManipulator resolveAppliedContainerInfoManipulator(
List<ContainerInfoManipulator> containerInfoManipulators,
List<ObjectProperty> objectProperties
) {
if (!container) {
if (!container || objectProperties.isEmpty()
|| !(objectProperties.get(0).getProperty() instanceof RootProperty)) {
return null;
}

Expand Down

0 comments on commit d4feae0

Please sign in to comment.