Skip to content

Commit

Permalink
Merge pull request #46 from epam/main
Browse files Browse the repository at this point in the history
Fix TextFormat with multiple facets (#45)

* fixes TextFormatImpl failing on init when multiple facets are present due to 'inconsistent value type'
  • Loading branch information
buhaiovos authored Apr 10, 2024
2 parents 321abf7 + 0377097 commit fb095e2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ public TextFormatImpl(Set<Facet> facets) {
sentinelValues = f.getSentinelValues();
}

final FacetValueType newValueType = f.getValueType();

if (newValueType == null) {
continue;
}

if (valueType == null) {
valueType = f.getValueType();
valueType = newValueType;
} else {
if (valueType != f.getValueType()) {
throw new IllegalStateException("Inconsistent text format, multiple value types present: " + valueType + " and " + f.getValueType());
if (valueType != newValueType) {
throw new IllegalStateException("Inconsistent text format, multiple value types present: " + valueType + " and " + newValueType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.epam.jsdmx.infomodel.sdmx30;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import java.util.Set;

import org.junit.jupiter.api.Test;

class TextFormatImplTest {

@Test
void shouldNotFailOnMultipleFacets() {
Facet f1 = new BaseFacetImpl(FacetValueType.STRING);
var f2 = new BaseFacetImpl();
f2.setType(FacetType.IS_MULTILINGUAL);
f2.setValue("true");

TextFormat value = assertDoesNotThrow(() -> new TextFormatImpl(Set.of(f1, f2)));

assertThat(value.getValueType()).contains(FacetValueType.STRING);
assertThat(value.getIsMultiLingual()).contains(true);
}

}

0 comments on commit fb095e2

Please sign in to comment.