Skip to content

Commit

Permalink
issues/200 - Fixed stream matchers for inversion of unserializable to…
Browse files Browse the repository at this point in the history
… serializable
  • Loading branch information
meywood committed Feb 5, 2024
1 parent 3951735 commit 792c776
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setListType(AbstractCLType listType) {
@Override
public boolean isDeserializable() {

return getChildTypes().stream().anyMatch(childType -> {
return getChildTypes().stream().allMatch(childType -> {
if (childType instanceof CLTypeAny) {
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public boolean isDeserializable() {
// The map contains an 'Any' type therefore cannot be deserialized
return false;
} else if (getKeyValueTypes().valueType instanceof AbstractCLTypeWithChildren) {
return getChildTypes().stream().anyMatch(childType -> {
return getChildTypes().stream().allMatch(childType -> {
if (childType instanceof CLTypeAny) {
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public void setOptionType(AbstractCLType listType) {

@Override
public boolean isDeserializable() {
return getOptionType().isDeserializable() || getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable);
return getOptionType().isDeserializable() || getChildTypes().stream().allMatch(AbstractCLType::isDeserializable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ protected List<Object> getChildTypeObjects() {

@Override
public boolean isDeserializable() {
return getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable);
return getChildTypes().stream().allMatch(AbstractCLType::isDeserializable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ protected List<Object> getChildTypeObjects() {

@Override
public boolean isDeserializable() {
return getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable);
return getChildTypes().stream().allMatch(AbstractCLType::isDeserializable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ protected List<Object> getChildTypeObjects() {

@Override
public boolean isDeserializable() {
return getChildTypes().stream().anyMatch(AbstractCLType::isDeserializable);
return getChildTypes().stream().allMatch(AbstractCLType::isDeserializable);
}
}
35 changes: 34 additions & 1 deletion src/test/java/com/casper/sdk/model/clvalue/NestedAnyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void readStepEventWithMapContainingAnyValue() throws Exception {
}

@Test
public void nestedMapWithoutAny() throws Exception {
public void nestedEmptyMapiWithoutAny() throws Exception {

final String json = " {\n" +
" \"cl_type\": {\n" +
Expand All @@ -93,4 +93,37 @@ public void nestedMapWithoutAny() throws Exception {
assertThat(clValueMap.getBytes(), is("00000000"));
}

@Test
void nestedListWithAny() throws Exception {

final String json = " {\n" +
" \"cl_type\": {\n" +
" \"List\": \"Any\"\n" +
" },\n" +
" \"bytes\": \"00000000\",\n" +
" \"parsed\": null\n" +
"}";

final CLValueList clValueList = (CLValueList) new ObjectMapper().readValue(json, AbstractCLValue.class);
assertThat(clValueList, is(notNullValue()));
assertThat(clValueList.getClType().isDeserializable(), is(false));
assertThat(clValueList.getBytes(), is("00000000"));
}

@Test
void nestedListWithoutAny() throws Exception {

final String json = " {\n" +
" \"cl_type\": {\n" +
" \"List\": \"U256\"\n" +
" },\n" +
" \"bytes\": \"00000000\",\n" +
" \"parsed\": null\n" +
"}";

final CLValueList clValueList = (CLValueList) new ObjectMapper().readValue(json, AbstractCLValue.class);
assertThat(clValueList, is(notNullValue()));
assertThat(clValueList.getClType().isDeserializable(), is(true));
assertThat(clValueList.getBytes(), is("00000000"));
}
}

0 comments on commit 792c776

Please sign in to comment.