Skip to content

Commit

Permalink
add boolean equality operator predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Jun 21, 2024
1 parent 4d63b7b commit ee2789c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public boolean test(Object property, Object operandRight) {

if (property instanceof List<?> list) {
return list.stream().anyMatch(it -> Objects.equals(it, operandRight));
} else if (property instanceof Boolean) {
return property.equals(Boolean.parseBoolean(operandRight.toString()));

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
operandRight
may be null at this access as suggested by
this
null guard.
}

return Objects.equals(property, operandRight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ void shouldMatchPredicate_whenObjectIsList() {
assertThat(predicate.test(List.of("one", "two"), "three")).isFalse();
}

@Test
void shouldCheckName_whenPropertyIsBoolean() {
assertThat(predicate.test(Boolean.TRUE, "ENTRY2")).isFalse();
assertThat(predicate.test(Boolean.TRUE, "true")).isTrue();
assertThat(predicate.test(Boolean.TRUE, true)).isTrue();
assertThat(predicate.test(Boolean.TRUE, false)).isFalse();
assertThat(predicate.test(Boolean.TRUE, "false")).isFalse();
assertThat(predicate.test(true, false)).isFalse();
}

public enum TestEnum {
ENTRY1, ENTRY2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ void shouldMatchPredicate_whenObjectIsList() {
assertThat(predicate.test(List.of("one", "two"), "three")).isTrue();
}

@Test
void shouldCheckName_whenPropertyIsBoolean() {
assertThat(predicate.test(Boolean.TRUE, "ENTRY2")).isTrue();
assertThat(predicate.test(Boolean.TRUE, "true")).isFalse();
assertThat(predicate.test(Boolean.TRUE, true)).isFalse();
assertThat(predicate.test(Boolean.TRUE, false)).isTrue();
assertThat(predicate.test(Boolean.TRUE, "false")).isTrue();
assertThat(predicate.test(true, false)).isTrue();
}

public enum TestEnum {
ENTRY1, ENTRY2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public JsonObjectToAssetTransformer() {

// the asset is a Catalog Asset, i.e. it links to another catalog
if (EDC_CATALOG_ASSET_TYPE.equals(nodeType(jsonObject))) {
builder.property(Asset.PROPERTY_IS_CATALOG, "true");
builder.property(Asset.PROPERTY_IS_CATALOG, true);
}

return builderResult(builder::build, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void queryAsset_byCustomComplexProperty(ManagementEndToEndTestContext context) {
void queryAsset_byCatalogProperty(ManagementEndToEndTestContext context, AssetIndex assetIndex) {
var id = UUID.randomUUID().toString();
assetIndex.create(Asset.Builder.newInstance()
.property(Asset.PROPERTY_IS_CATALOG, "true")
.property(Asset.PROPERTY_IS_CATALOG, true)
.id(id)
.contentType("application/octet-stream")
.dataAddress(createDataAddress().build())
Expand Down

0 comments on commit ee2789c

Please sign in to comment.