From e893599de3477fe6d8e3598bd4036794ca19d40a Mon Sep 17 00:00:00 2001 From: Tristan Chuine <tristan.chuine_externe@rte-france.com> Date: Tue, 15 Oct 2024 10:09:34 +0200 Subject: [PATCH 1/2] Migrate tests to JUnit5 Signed-off-by: Tristan Chuine <tristan.chuine_externe@rte-france.com> --- pom.xml | 19 +-- .../sld/server/GeoDataServiceTest.java | 78 ++-------- .../sld/server/SingleLineDiagramTest.java | 144 +++++++----------- 3 files changed, 74 insertions(+), 167 deletions(-) diff --git a/pom.xml b/pom.xml index 791248d..ef29a86 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,8 @@ <type>pom</type> <scope>import</scope> </dependency> + + <!-- project specific dependencies --> </dependencies> </dependencyManagement> @@ -153,24 +155,9 @@ <artifactId>powsybl-config-test</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-test-autoconfigure</artifactId> + <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java b/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java index f22ba5c..6c9d5eb 100644 --- a/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java +++ b/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java @@ -7,12 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.Country; import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.sld.server.dto.Coordinate; import com.powsybl.sld.server.dto.SubstationGeoData; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -22,83 +22,29 @@ import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; public class GeoDataServiceTest { + private static final String BASE_URI = "http://geo-data-server/"; - private static final String VARIANT_1_ID = "variant_1"; - private static final String VARIANT_2_ID = "variant_2"; - private final String baseUri = "http://geo-data-server/"; @Mock private RestTemplate restTemplate; + @InjectMocks private GeoDataService geoDataService; + @Mock private NetworkStoreService networkStoreService; - public static Network createNetwork() { - Network network = Network.create("test", "test"); - Substation substationFr1 = network.newSubstation() - .setId("subFr1") - .setCountry(Country.FR) - .setTso("RTE") - .add(); - VoltageLevel voltageLevelFr1A = substationFr1.newVoltageLevel() - .setId("vlFr1A") - .setName("vlFr1A") - .setNominalV(440.0) - .setHighVoltageLimit(400.0) - .setLowVoltageLimit(200.0) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - voltageLevelFr1A.getBusBreakerView().newBus() - .setId("busFr1A") - .setName("busFr1A") - .add(); - VoltageLevel voltageLevelFr1B = substationFr1.newVoltageLevel() - .setId("vlFr1B").setName("vlFr1B") - .setNominalV(200.0) - .setHighVoltageLimit(400.0) - .setLowVoltageLimit(200.0) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - voltageLevelFr1B.getBusBreakerView().newBus() - .setId("busFr1B") - .setName("busFr1B") - .add(); - - Substation substationFr2 = network.newSubstation() - .setId("subFr2") - .setCountry(Country.FR) - .setTso("RTE") - .add(); - VoltageLevel voltageLevelFr2A = substationFr2.newVoltageLevel() - .setId("vlFr2A") - .setName("vlFr2A") - .setNominalV(440.0) - .setHighVoltageLimit(400.0) - .setLowVoltageLimit(200.0) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - voltageLevelFr2A.getBusBreakerView().newBus() - .setId("busFr2A") - .setName("busFr2A") - .add(); - network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_1_ID); - network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_2_ID); - - return network; - } - - @Before - public void setUp() { + @BeforeEach + void setUp() { MockitoAnnotations.initMocks(this); - geoDataService.setGeoDataServerBaseUri(baseUri); + geoDataService.setGeoDataServerBaseUri(BASE_URI); } @Test - public void testGetSubstationsGraphics() { + void testGetSubstationsGraphics() { UUID networkUuid = UUID.randomUUID(); String variantId = "variant2"; List<String> substationsIds = List.of("subFr1", "subFr2"); @@ -113,7 +59,7 @@ public void testGetSubstationsGraphics() { } @Test - public void testGetSubstationsGraphicsWithoutVariantId() { + void testGetSubstationsGraphicsWithoutVariantId() { UUID networkUuid = UUID.randomUUID(); List<String> substationsIds = List.of("subFr1"); SubstationGeoData substationGeoData = new SubstationGeoData(); diff --git a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java index cc300dc..80a720f 100644 --- a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java +++ b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java @@ -33,23 +33,20 @@ import com.powsybl.sld.svg.FeederInfo; import com.powsybl.sld.svg.SvgParameters; import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import java.io.IOException; import java.io.StringWriter; -import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.Files; @@ -61,7 +58,7 @@ import static com.powsybl.sld.library.ComponentTypeName.ARROW_ACTIVE; import static com.powsybl.sld.library.ComponentTypeName.ARROW_REACTIVE; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.times; @@ -74,7 +71,6 @@ * @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com> * @author Franck Lecuyer <franck.lecuyer at rte-france.com> */ -@RunWith(SpringRunner.class) @WebMvcTest(SingleLineDiagramController.class) @ContextConfiguration(classes = {SingleLineDiagramApplication.class}) public class SingleLineDiagramTest { @@ -102,22 +98,21 @@ public class SingleLineDiagramTest { private static final String VARIANT_2_ID = "variant_2"; private static final String VARIANT_NOT_FOUND_ID = "variant_notFound"; private FileSystem fileSystem; - private Path tmpDir; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws Exception { MockitoAnnotations.initMocks(this); fileSystem = Jimfs.newFileSystem(Configuration.unix()); - tmpDir = Files.createDirectory(fileSystem.getPath("tmp")); + final Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp")); } - @After - public void tearDown() throws IOException { + @AfterEach + void tearDown() throws Exception { fileSystem.close(); } @Test - public void test() throws Exception { + void test() throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); UUID notFoundNetworkId = UUID.fromString("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); @@ -200,7 +195,7 @@ public void test() throws Exception { } @Test - public void testSubstations() throws Exception { + void testSubstations() throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); UUID notFoundNetworkId = UUID.fromString("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); @@ -281,7 +276,7 @@ public void testSubstations() throws Exception { } @Test - public void testComponentLibraries() throws Exception { + void testComponentLibraries() throws Exception { MvcResult result = mvc.perform(get("/v1/svg-component-libraries")) .andExpect(status().isOk()) .andReturn(); @@ -292,7 +287,7 @@ public void testComponentLibraries() throws Exception { private static final String GEO_DATA_SUBSTATIONS = "/geo_data_substations.json"; @Test - public void testAssignSubstationGeoData() throws Exception { + void testAssignSubstationGeoData() throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork()); Network network = networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION); @@ -306,9 +301,8 @@ public void testAssignSubstationGeoData() throws Exception { String faultSubstationGeoDataJson = "[{\"id\":\"subFr1\",\"coordinate\":{\"lat\":48.8588443,\"long\":2.2943506}}]"; given(geoDataService.getSubstationsGraphics(testNetworkId, VARIANT_1_ID, List.of("subFr1"))).willReturn(faultSubstationGeoDataJson); - PowsyblException exception = assertThrows(PowsyblException.class, () -> { - networkAreaDiagramService.assignGeoDataCoordinates(network, testNetworkId, VARIANT_1_ID, List.of(network.getVoltageLevel("vlFr1A"))); - }); + PowsyblException exception = assertThrows(PowsyblException.class, () -> + networkAreaDiagramService.assignGeoDataCoordinates(network, testNetworkId, VARIANT_1_ID, List.of(network.getVoltageLevel("vlFr1A")))); // Assert the exception message assertEquals("Failed to parse JSON response", exception.getMessage()); @@ -316,7 +310,7 @@ public void testAssignSubstationGeoData() throws Exception { } @Test - public void testNetworkAreaDiagram() throws Exception { + void testNetworkAreaDiagram() throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); UUID notFoundNetworkId = UUID.fromString("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"); @@ -349,7 +343,7 @@ public void testNetworkAreaDiagram() throws Exception { .andExpect(status().isNotFound()); } - public void testGenerateNadBasedOnGeoData(boolean withGeoData) { + private void testGenerateNadBasedOnGeoData(boolean withGeoData) throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork()); given(geoDataService.getSubstationsGraphics(testNetworkId, VARIANT_2_ID, List.of("subFr1"))).willReturn(toString(GEO_DATA_SUBSTATIONS)); @@ -364,17 +358,17 @@ public void testGenerateNadBasedOnGeoData(boolean withGeoData) { } @Test - public void testGenerateNadWithoutGeoData() { + void testGenerateNadWithoutGeoData() throws Exception { testGenerateNadBasedOnGeoData(false); } @Test - public void testGenerateNadWithGeoData() { + void testGenerateNadWithGeoData() throws Exception { testGenerateNadBasedOnGeoData(true); } @Test - public void testNetworkAreaDiagramAdditionalMetadata() { + void testNetworkAreaDiagramAdditionalMetadata() throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork()); @@ -383,11 +377,9 @@ public void testNetworkAreaDiagramAdditionalMetadata() { SvgAndMetadata svgAndMetadata = networkAreaDiagramService.generateNetworkAreaDiagramSvg(testNetworkId, VARIANT_2_ID, List.of("vlFr1A"), 2, true); Object additionalMetadata = svgAndMetadata.getAdditionalMetadata(); assertNotNull(additionalMetadata); - Map<String, Object> convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { - }); + Map<String, Object> convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { }); assertEquals(1, convertedMetadata.get("nbVoltageLevels")); - List<Map<String, String>> voltageLevels = objectMapper.convertValue(convertedMetadata.get("voltageLevels"), new TypeReference<>() { - }); + List<Map<String, String>> voltageLevels = objectMapper.convertValue(convertedMetadata.get("voltageLevels"), new TypeReference<>() { }); assertNotNull(voltageLevels); assertEquals(1, voltageLevels.size()); assertEquals("vlFr1A", voltageLevels.get(0).get("id")); @@ -396,7 +388,7 @@ public void testNetworkAreaDiagramAdditionalMetadata() { } @Test - public void testVoltageLevelSingleLineDiagramAdditionalMetadata() { + void testVoltageLevelSingleLineDiagramAdditionalMetadata() { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, null)).willReturn(createNetwork()); @@ -415,8 +407,7 @@ public void testVoltageLevelSingleLineDiagramAdditionalMetadata() { SvgAndMetadata svgAndMetadata = singleLineDiagramService.generateSvgAndMetadata(testNetworkId, VARIANT_2_ID, "vlFr1A", parameters); Object additionalMetadata = svgAndMetadata.getAdditionalMetadata(); assertNotNull(additionalMetadata); - Map<String, String> convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { - }); + Map<String, String> convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { }); assertEquals("vlFr1A", convertedMetadata.get("id")); assertEquals("vlFr1A", convertedMetadata.get("name")); assertEquals("FR", convertedMetadata.get("country")); @@ -424,7 +415,7 @@ public void testVoltageLevelSingleLineDiagramAdditionalMetadata() { } @Test - public void testSubstationSingleLineDiagramAdditionalMetadata() { + void testSubstationSingleLineDiagramAdditionalMetadata() { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, null)).willReturn(createNetwork()); @@ -443,14 +434,13 @@ public void testSubstationSingleLineDiagramAdditionalMetadata() { SvgAndMetadata svgAndMetadata = singleLineDiagramService.generateSvgAndMetadata(testNetworkId, VARIANT_2_ID, "subFr1", parameters); Object additionalMetadata = svgAndMetadata.getAdditionalMetadata(); assertNotNull(additionalMetadata); - Map<String, String> convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { - }); + Map<String, String> convertedMetadata = objectMapper.convertValue(additionalMetadata, new TypeReference<>() { }); assertEquals("subFr1", convertedMetadata.get("id")); assertNull(convertedMetadata.get("name")); assertEquals("FR", convertedMetadata.get("country")); } - public static Network createNetwork() { + private static Network createNetwork() { Network network = Network.create("test", "test"); Substation substationFr1 = network.newSubstation() .setId("subFr1") @@ -535,7 +525,7 @@ public static Network createNetwork() { } @Test - public void testPositionDiagramLabelProvider() throws IOException { + void testPositionDiagramLabelProvider() throws Exception { var testNetwork = createNetworkWithTwoInjectionAndOneBranchAndOne3twt(); var layoutParameters = new LayoutParameters(); var svgParameters = new SvgParameters(); @@ -576,7 +566,7 @@ public void testPositionDiagramLabelProvider() throws IOException { } @Test - public void testNetworkAreaDiagramWithMissingVoltageLevel() throws Exception { + void testNetworkAreaDiagramWithMissingVoltageLevel() throws Exception { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork()); given(geoDataService.getSubstationsGraphics(testNetworkId, VARIANT_2_ID, List.of("subFr1"))).willReturn(toString(GEO_DATA_SUBSTATIONS)); @@ -594,23 +584,8 @@ public void testNetworkAreaDiagramWithMissingVoltageLevel() throws Exception { .andExpect(status().isNotFound()); } - public static String toString(Path outPath) { - String content; - try { - byte[] encoded = Files.readAllBytes(outPath); - content = new String(encoded, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return content; - } - - public String toString(String resourceName) { - try { - return new String(ByteStreams.toByteArray(Objects.requireNonNull(getClass().getResourceAsStream(resourceName))), StandardCharsets.UTF_8); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + private static String toString(String resourceName) throws IOException { + return new String(ByteStreams.toByteArray(Objects.requireNonNull(SingleLineDiagramTest.class.getResourceAsStream(resourceName))), StandardCharsets.UTF_8); } /* @@ -653,7 +628,7 @@ public Network createNetworkWithTwoInjectionAndOneBranchAndOne3twt() { return network; } - private Substation createSubstation(Network n, String id, String name, Country country) { + private static Substation createSubstation(Network n, String id, String name, Country country) { return n.newSubstation() .setId(id) .setName(name) @@ -661,8 +636,7 @@ private Substation createSubstation(Network n, String id, String name, Country c .add(); } - private VoltageLevel createVoltageLevel(Substation s, String id, String name, - TopologyKind topology, double vNom, int nodeCount) { + private static VoltageLevel createVoltageLevel(Substation s, String id, String name, TopologyKind topology, double vNom, int nodeCount) { VoltageLevel vl = s.newVoltageLevel() .setId(id) .setName(name) @@ -672,8 +646,8 @@ private VoltageLevel createVoltageLevel(Substation s, String id, String name, return vl; } - private void createLoad(VoltageLevel vl, String id, String name, String feederName, Integer feederOrder, - ConnectablePosition.Direction direction, int node, double p0, double q0) { + private static void createLoad(VoltageLevel vl, String id, String name, String feederName, Integer feederOrder, + ConnectablePosition.Direction direction, int node, double p0, double q0) { Load load = vl.newLoad() .setId(id) .setName(name) @@ -684,7 +658,7 @@ private void createLoad(VoltageLevel vl, String id, String name, String feederNa addFeederPosition(load, feederName, feederOrder, direction); } - private void createSwitch(VoltageLevel vl, String id, String name, SwitchKind kind, boolean retained, boolean open, boolean fictitious, int node1, int node2) { + private static void createSwitch(VoltageLevel vl, String id, String name, SwitchKind kind, boolean retained, boolean open, boolean fictitious, int node1, int node2) { vl.getNodeBreakerView().newSwitch() .setId(id) .setName(name) @@ -697,7 +671,7 @@ private void createSwitch(VoltageLevel vl, String id, String name, SwitchKind ki .add(); } - private void createBusBarSection(VoltageLevel vl, String id, String name, int node, int busbarIndex, int sectionIndex) { + private static void createBusBarSection(VoltageLevel vl, String id, String name, int node, int busbarIndex, int sectionIndex) { BusbarSection bbs = vl.getNodeBreakerView().newBusbarSection() .setId(id) .setName(name) @@ -709,13 +683,13 @@ private void createBusBarSection(VoltageLevel vl, String id, String name, int no .add(); } - private void createTwoWindingsTransformer(Substation s, String id, String name, - double r, double x, double g, double b, - double ratedU1, double ratedU2, - int node1, int node2, - String idVoltageLevel1, String idVoltageLevel2, - String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, - String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2) { + private static void createTwoWindingsTransformer(Substation s, String id, String name, + double r, double x, double g, double b, + double ratedU1, double ratedU2, + int node1, int node2, + String idVoltageLevel1, String idVoltageLevel2, + String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, + String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2) { TwoWindingsTransformer t = s.newTwoWindingsTransformer() .setId(id) .setName(name) @@ -733,16 +707,16 @@ private void createTwoWindingsTransformer(Substation s, String id, String name, addTwoFeedersPosition(t, feederName1, feederOrder1, direction1, feederName2, feederOrder2, direction2); } - private void createThreeWindingsTransformer(Substation s, String id, String name, - String vl1, String vl2, String vl3, - double r1, double r2, double r3, - double x1, double x2, double x3, - double g1, double b1, - double ratedU1, double ratedU2, double ratedU3, - int node1, int node2, int node3, - String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, - String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2, - String feederName3, Integer feederOrder3, ConnectablePosition.Direction direction3) { + private static void createThreeWindingsTransformer(Substation s, String id, String name, + String vl1, String vl2, String vl3, + double r1, double r2, double r3, + double x1, double x2, double x3, + double g1, double b1, + double ratedU1, double ratedU2, double ratedU3, + int node1, int node2, int node3, + String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, + String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2, + String feederName3, Integer feederOrder3, ConnectablePosition.Direction direction3) { ThreeWindingsTransformer t = s.newThreeWindingsTransformer() .setId(id) .setName(name) @@ -774,9 +748,9 @@ private void createThreeWindingsTransformer(Substation s, String id, String name addThreeFeedersPosition(t, feederName1, feederOrder1, direction1, feederName2, feederOrder2, direction2, feederName3, feederOrder3, direction3); } - private void addTwoFeedersPosition(Extendable<?> extendable, - String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, - String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2) { + private static void addTwoFeedersPosition(Extendable<?> extendable, + String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, + String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2) { ConnectablePositionAdder extensionAdder = extendable.newExtension(ConnectablePositionAdder.class); ConnectablePositionAdder.FeederAdder feederAdder1 = extensionAdder.newFeeder1(); if (feederOrder1 != null) { @@ -791,7 +765,7 @@ private void addTwoFeedersPosition(Extendable<?> extendable, extensionAdder.add(); } - private void addThreeFeedersPosition(Extendable<?> extendable, + private static void addThreeFeedersPosition(Extendable<?> extendable, String feederName1, Integer feederOrder1, ConnectablePosition.Direction direction1, String feederName2, Integer feederOrder2, ConnectablePosition.Direction direction2, String feederName3, Integer feederOrder3, ConnectablePosition.Direction direction3) { @@ -814,7 +788,7 @@ private void addThreeFeedersPosition(Extendable<?> extendable, extensionAdder.add(); } - private void addFeederPosition(Extendable<?> extendable, String feederName, Integer feederOrder, ConnectablePosition.Direction direction) { + private static void addFeederPosition(Extendable<?> extendable, String feederName, Integer feederOrder, ConnectablePosition.Direction direction) { ConnectablePositionAdder.FeederAdder feederAdder = extendable.newExtension(ConnectablePositionAdder.class).newFeeder(); if (feederOrder != null) { feederAdder.withOrder(feederOrder); From 1572dd9219b702ed55d9c15a0706bf4fdb648b24 Mon Sep 17 00:00:00 2001 From: Tristan Chuine <tristan.chuine_externe@rte-france.com> Date: Thu, 17 Oct 2024 18:09:22 +0200 Subject: [PATCH 2/2] Fix sonar Signed-off-by: Tristan Chuine <tristan.chuine_externe@rte-france.com> --- .../sld/server/GeoDataServiceTest.java | 2 +- .../sld/server/SingleLineDiagramTest.java | 22 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java b/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java index 6c9d5eb..c99e7fb 100644 --- a/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java +++ b/src/test/java/com/powsybl/sld/server/GeoDataServiceTest.java @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -public class GeoDataServiceTest { +class GeoDataServiceTest { private static final String BASE_URI = "http://geo-data-server/"; @Mock diff --git a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java index 80a720f..714cf3b 100644 --- a/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java +++ b/src/test/java/com/powsybl/sld/server/SingleLineDiagramTest.java @@ -50,7 +50,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.Files; -import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.Objects; @@ -73,7 +72,7 @@ */ @WebMvcTest(SingleLineDiagramController.class) @ContextConfiguration(classes = {SingleLineDiagramApplication.class}) -public class SingleLineDiagramTest { +class SingleLineDiagramTest { @Autowired private MockMvc mvc; @@ -103,7 +102,7 @@ public class SingleLineDiagramTest { void setUp() throws Exception { MockitoAnnotations.initMocks(this); fileSystem = Jimfs.newFileSystem(Configuration.unix()); - final Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp")); + Files.createDirectory(fileSystem.getPath("tmp")); } @AfterEach @@ -287,7 +286,7 @@ void testComponentLibraries() throws Exception { private static final String GEO_DATA_SUBSTATIONS = "/geo_data_substations.json"; @Test - void testAssignSubstationGeoData() throws Exception { + void testAssignSubstationGeoData() { UUID testNetworkId = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4"); given(networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION)).willReturn(createNetwork()); Network network = networkStoreService.getNetwork(testNetworkId, PreloadingStrategy.COLLECTION); @@ -591,14 +590,14 @@ private static String toString(String resourceName) throws IOException { /* #TODO replace it with already configured FourSubstationsNodeBreakerWithExtensionsFactory when migrating to next powsybl release */ - public Network createNetworkWithTwoInjectionAndOneBranchAndOne3twt() { + private static Network createNetworkWithTwoInjectionAndOneBranchAndOne3twt() { Network network = Network.create("TestSingleLineDiagram", "test"); Substation substation = createSubstation(network, "s", "s", Country.FR); Substation substation2 = createSubstation(network, "s2", "s2", Country.FR); - VoltageLevel vl1 = createVoltageLevel(substation, "vl1", "vl1", TopologyKind.NODE_BREAKER, 380, 10); - VoltageLevel vl2 = createVoltageLevel(substation, "vl2", "vl2", TopologyKind.NODE_BREAKER, 225, 30); - VoltageLevel vl3 = createVoltageLevel(substation, "vl3", "vl3", TopologyKind.NODE_BREAKER, 225, 30); - VoltageLevel vl4 = createVoltageLevel(substation2, "vl4", "vl4", TopologyKind.NODE_BREAKER, 220, 20); + VoltageLevel vl1 = createVoltageLevel(substation, "vl1", "vl1", TopologyKind.NODE_BREAKER, 380); + VoltageLevel vl2 = createVoltageLevel(substation, "vl2", "vl2", TopologyKind.NODE_BREAKER, 225); + VoltageLevel vl3 = createVoltageLevel(substation, "vl3", "vl3", TopologyKind.NODE_BREAKER, 225); + VoltageLevel vl4 = createVoltageLevel(substation2, "vl4", "vl4", TopologyKind.NODE_BREAKER, 220); createBusBarSection(vl1, "bbs11", "bbs11", 2, 2, 2); createLoad(vl1, "loadA", "loadA", "loadA", 0, ConnectablePosition.Direction.TOP, 4, 10, 10); @@ -636,14 +635,13 @@ private static Substation createSubstation(Network n, String id, String name, Co .add(); } - private static VoltageLevel createVoltageLevel(Substation s, String id, String name, TopologyKind topology, double vNom, int nodeCount) { - VoltageLevel vl = s.newVoltageLevel() + private static VoltageLevel createVoltageLevel(Substation s, String id, String name, TopologyKind topology, double vNom) { + return s.newVoltageLevel() .setId(id) .setName(name) .setTopologyKind(topology) .setNominalV(vNom) .add(); - return vl; } private static void createLoad(VoltageLevel vl, String id, String name, String feederName, Integer feederOrder,