*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor;
import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class DataTreeCandidateNodesTest {
+class DataTreeCandidateNodesTest {
@Test
- public void testFromNormalizedNode() {
- final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- final DataTreeCandidateNode dataTreeCandidateNode = DataTreeCandidateNodes.written(mockedNormalizedNode);
- assertNotNull(dataTreeCandidateNode);
+ void testFromNormalizedNode() {
+ assertNotNull(DataTreeCandidateNodes.written(mock(NormalizedNode.class)));
}
@Test
- public void testApplyToCursorWithWriteModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyToCursorWithWriteModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
- final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
+ doReturn(mock(NormalizedNode.class)).when(mockedDataTreeCandidateNode).dataAfter();
DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
}
@Test
- public void testApplyToCursorWithDeleteModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyToCursorWithDeleteModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
}
@Test
- public void testApplyToCursorWithSubtreeModifiedModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyToCursorWithSubtreeModifiedModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
- final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
+ final var mockedChildNode1 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
- final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
+ final var mockedChildNode2 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.WRITE).when(mockedChildNode2).modificationType();
- final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(mockedNormalizedNode).when(mockedChildNode2).dataAfter();
+ doReturn(mock(NormalizedNode.class)).when(mockedChildNode2).dataAfter();
- final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
+ final var mockedChildNode3 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).modificationType();
- final DataTreeCandidateNode mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
+ final var mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).modificationType();
doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).childNodes();
}
@Test
- public void testApplyToCursorWithUnsupportedModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyToCursorWithUnsupportedModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
- final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+ final var ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode));
- assertThat(ex.getMessage(), containsString("Unsupported modification"));
+ assertEquals("Unsupported modification APPEARED", ex.getMessage());
}
@Test
- public void testApplyRootedNodeToCursorWithWriteModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyRootedNodeToCursorWithWriteModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
- final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
+ doReturn(mock(NormalizedNode.class)).when(mockedDataTreeCandidateNode).dataAfter();
DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
}
@Test
- public void testApplyRootedNodeToCursorWithDeleteModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyRootedNodeToCursorWithDeleteModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
}
@Test
- public void testApplyRootedNodeToCursorWithSubtreeModifiedModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyRootedNodeToCursorWithSubtreeModifiedModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
- final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
+ final var mockedChildNode1 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).childNodes();
}
@Test
- public void testApplyRootedNodeToCursorWithUnsupportedModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyRootedNodeToCursorWithUnsupportedModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
- final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+ final var ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
mockedDataTreeCandidateNode));
- assertThat(ex.getMessage(), containsString("Unsupported modification"));
+ assertEquals("Unsupported modification APPEARED", ex.getMessage());
}
@Test
- public void testApplyRootToCursorWithSubtreeModifiedModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyRootToCursorWithSubtreeModifiedModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
- final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
+ final var mockedChildNode1 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).childNodes();
}
@Test
- public void testApplyRootToCursorWithDeleteModificationType() {
+ void testApplyRootToCursorWithDeleteModificationType() {
final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
final var ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
- assertThat(ex.getMessage(), containsString("Can not delete root"));
+ assertEquals("Can not delete root.", ex.getMessage());
}
@Test
- public void testApplyRootToCursorWithUnsupportedModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ void testApplyRootToCursorWithUnsupportedModificationType() {
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
- final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+ final var ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
- assertThat(ex.getMessage(), containsString("Unsupported modification"));
+ assertEquals("Unsupported modification APPEARED", ex.getMessage());
}
}