Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid setting all properties to null in ModelConstructionTest #640

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -1018,7 +1019,16 @@ public void mediaTypeTest() {
@SuppressWarnings("deprecation") // Testing deprecated Schema methods
@Test
public void schemaTest() {
final Schema s = processConstructible(Schema.class);
final Schema s = processConstructible(Schema.class, Set.of("booleanSchema"));

s.setBooleanSchema(Boolean.TRUE);
assertSame(s.getBooleanSchema(), Boolean.TRUE, "Schema.getBooleanSchema should return the value that was set");
Schema s2 = s.booleanSchema(Boolean.FALSE);
assertSame(s2, s, "Schema.booleanSchema should return the same object");
assertSame(s.getBooleanSchema(), Boolean.FALSE,
"Schema.getBooleanSchema should return the value that was set with the builder method");
s.setBooleanSchema(null);
assertNull(s.getBooleanSchema(), "Should be able to set Schema.booleanSchema to null");

final Schema ap = createConstructibleInstance(Schema.class);
checkSameObject(s, s.additionalPropertiesSchema(ap));
Expand All @@ -1029,7 +1039,7 @@ public void schemaTest() {
checkSameObject(s, s.additionalPropertiesBoolean(Boolean.TRUE));
assertEquals(s.getAdditionalPropertiesBoolean(), Boolean.TRUE,
"AdditionalProperties (Boolean type) is expected to be true");
Schema s2 = s.getAdditionalPropertiesSchema();
s2 = s.getAdditionalPropertiesSchema();
assertNotNull(s2, "AdditionalProperties (Schema type) is expected to be non-null");
assertEquals(s2.getBooleanSchema(), Boolean.TRUE,
"AdditionalProperties (Schema type) is expected to return a boolean-true schema");
Expand Down Expand Up @@ -1721,6 +1731,10 @@ public void tagTest() {
}

private <T extends Constructible> T processConstructible(Class<T> clazz) {
return processConstructible(clazz, Collections.emptySet());
}

private <T extends Constructible> T processConstructible(Class<T> clazz, Set<String> propertiesToIgnore) {
final T o = createConstructibleInstance(clazz);
if (o instanceof Extensible && Extensible.class.isAssignableFrom(clazz)) {
processExtensible((Extensible<?>) o);
Expand All @@ -1729,9 +1743,12 @@ private <T extends Constructible> T processConstructible(Class<T> clazz) {
processReference((Reference<?>) o);
}
final Map<String, Property> properties = collectProperties(clazz);
properties.values().stream().filter((p) -> p.isComplete()).forEach((p) -> {
processConstructibleProperty(o, p, clazz);
});
properties.values().stream()
.filter((p) -> p.isComplete())
.filter((p) -> !propertiesToIgnore.contains(p.getName()))
.forEach((p) -> {
processConstructibleProperty(o, p, clazz);
});
return o;
}

Expand Down