Skip to content

Commit

Permalink
refactor(#110): sonar review
Browse files Browse the repository at this point in the history
Signed-off-by: Samir Romdhani <[email protected]>
  • Loading branch information
samirromdhani committed Aug 28, 2023
1 parent 343295f commit 9fe0f18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ public static Map<String, PrivateLinkedToStds> createMapICDSystemVersionUuidAndS
PrivateUtils.extractCompasICDHeader(tp)
.map(TCompasICDHeader::getICDSystemVersionUUID)
.ifPresent(icdSysVer -> {
PrivateLinkedToStds PrivateLinkedToStds = icdSysVerToPrivateStdsMap.get(icdSysVer);
List<SCL> list = PrivateLinkedToStds != null ? PrivateLinkedToStds.stdList() : new ArrayList<>();
PrivateLinkedToStds privateLinkedToStds = icdSysVerToPrivateStdsMap.get(icdSysVer);
List<SCL> list = privateLinkedToStds != null ? privateLinkedToStds.stdList() : new ArrayList<>();
list.add(std);
icdSysVerToPrivateStdsMap.put(icdSysVer, new PrivateLinkedToStds(tp, list));
})
Expand All @@ -216,7 +216,7 @@ public static Map<String, PrivateLinkedToStds> createMapICDSystemVersionUuidAndS
*/
public static void checkSTDCorrespondanceWithLNodeCompasICDHeader(Map<String, PrivateLinkedToStds> mapICDSystemVersionUuidAndSTDFile) throws ScdException {
mapICDSystemVersionUuidAndSTDFile.values().stream()
.filter(PrivateLinkedToStds -> PrivateLinkedToStds.stdList().size() != 1)
.filter(privateLinkedToStds -> privateLinkedToStds.stdList().size() != 1)
.findFirst()
.ifPresent(pToStd -> {
throw new ScdException("There are several STD files corresponding to " + stdCheckFormatExceptionMessage(pToStd.tPrivate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ void testImportSTDElementsInSCD_with_Multiple_STD() {
SCL std0 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
SCL std1 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_SITESITE1SCU1.xml");
SCL std2 = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_SITESITE1SCU2.xml");
SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);

assertDoesNotThrow(() -> sclEditorService.importSTDElementsInSCD(scd, List.of(std0, std1, std2), DTO.SUB_NETWORK_TYPES));
assertThat(scd.getIED()).hasSize(3);
Expand Down Expand Up @@ -266,20 +265,19 @@ void testImportSTDElementsInSCD_Compas_ICDHeader_Not_Match() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std_with_same_ICDSystemVersionUUID.xml");
SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
List<SCL> stdList = List.of(std);
//When Then
assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, List.of(std), DTO.SUB_NETWORK_TYPES));
assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES));
assertIsMarshallable(scd);
}

@Test
void testImportSTDElementsInSCD_No_STD_Match() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
List<SCL> stdList = List.of();
//When Then
Set<SCL> stds = new HashSet<>();
assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, List.of(), DTO.SUB_NETWORK_TYPES));
assertThrows(ScdException.class, () -> sclEditorService.importSTDElementsInSCD(scd, stdList, DTO.SUB_NETWORK_TYPES));
assertIsMarshallable(scd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void addSubstation_when_SCD_has_no_substation_should_succeed() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scl-root-test-schema-conf/add_ied_test.xml");
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
assertThat(scd.getSubstation().size()).isZero();
assertThat(scd.getSubstation()).asList().isEmpty();
// When
substationService.addSubstation(scd, ssd);
// Then
Expand All @@ -51,7 +51,7 @@ void addSubstation_when_SCD_has_a_substation_should_succeed() {
// Then
assertIsMarshallable(scd);
assertThat(scdSubstation.getName()).isEqualTo(ssdSubstation.getName());
assertThat(scd.getSubstation().size()).isEqualTo(ssd.getSubstation().size());
assertThat(scd.getSubstation()).asList().hasSameSizeAs(ssd.getSubstation());
assertThat(scdSubstation.getVoltageLevel().stream().map(TVoltageLevel::getBay).count()).isEqualTo(2);
}

Expand Down

0 comments on commit 9fe0f18

Please sign in to comment.