Skip to content

Commit 880bf2a

Browse files
authored
Improve exception messages for unimplemented methods in ModificationInfos class (#106)
Signed-off-by: achour94 <[email protected]>
1 parent 77fd456 commit 880bf2a

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/main/java/org/gridsuite/modification/dto/ModificationInfos.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ public class ModificationInfos {
118118

119119
@JsonIgnore
120120
public ReportNode createSubReportNode(ReportNode reportNode) {
121-
throw new UnsupportedOperationException("TODO");
121+
throw new UnsupportedOperationException("Method createSubReportNode must be implemented in subclass " + this.getClass().getSimpleName());
122122
}
123123

124124
@JsonIgnore
125125
public AbstractModification toModification() {
126-
throw new UnsupportedOperationException("TODO");
126+
throw new UnsupportedOperationException("Method toModification must be implemented in subclass " + this.getClass().getSimpleName());
127127
}
128128

129129
@JsonIgnore
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.modification.dto;
8+
9+
import com.powsybl.commons.report.ReportNode;
10+
import org.junit.jupiter.api.Test;
11+
12+
import static org.junit.jupiter.api.Assertions.*;
13+
14+
/**
15+
* @author Achour BERRAHMA <achour.berrahma at rte-france.com>
16+
* Test class for ModificationInfos base class methods that should be overridden by subclasses.
17+
*/
18+
class ModificationInfosTest {
19+
20+
private static class TestModificationInfos extends ModificationInfos {
21+
// Intentionally does not override createSubReportNode() or toModification()
22+
// to test the UnsupportedOperationException throwing behavior
23+
}
24+
25+
@Test
26+
void testCreateSubReportNodeThrowsUnsupportedOperationException() {
27+
ModificationInfos modificationInfos = new TestModificationInfos();
28+
ReportNode mockReportNode = ReportNode.newRootReportNode().withMessageTemplate("test").build();
29+
30+
UnsupportedOperationException exception = assertThrows(
31+
UnsupportedOperationException.class,
32+
() -> modificationInfos.createSubReportNode(mockReportNode),
33+
"createSubReportNode should throw UnsupportedOperationException when not implemented"
34+
);
35+
36+
String expectedMessage = "Method createSubReportNode must be implemented in subclass TestModificationInfos";
37+
assertEquals(expectedMessage, exception.getMessage(),
38+
"Exception message should indicate which method and class need implementation");
39+
}
40+
41+
@Test
42+
void testToModificationThrowsUnsupportedOperationException() {
43+
ModificationInfos modificationInfos = new TestModificationInfos();
44+
45+
UnsupportedOperationException exception = assertThrows(
46+
UnsupportedOperationException.class,
47+
modificationInfos::toModification,
48+
"toModification should throw UnsupportedOperationException when not implemented"
49+
);
50+
51+
String expectedMessage = "Method toModification must be implemented in subclass TestModificationInfos";
52+
assertEquals(expectedMessage, exception.getMessage(),
53+
"Exception message should indicate which method and class need implementation");
54+
}
55+
}

0 commit comments

Comments
 (0)