|
| 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