<groupId>${project.groupId}</groupId>
<artifactId>yang-model-api</artifactId>
</dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
package org.opendaylight.yangtools.yang.model.repo.util;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import com.google.common.base.MoreObjects;
@Before
public void setUp() throws Exception {
- doReturn(this.registration).when(this.registry).registerSchemaSource(any(SchemaSourceProvider.class),
+ doNothing().when(registration).close();
+ doReturn(registration).when(registry).registerSchemaSource(any(SchemaSourceProvider.class),
any(PotentialSchemaSource.class));
}
}
@Test
- public void inMemorySchemaSourceCache3test() throws Exception {
+ public void inMemorySchemaSourceCache3test() throws InterruptedException, ExecutionException {
final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache =
InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION);
final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache2 =
*/
package org.opendaylight.yangtools.yang.model.repo.util;
-import org.junit.Assert;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
+@RunWith(MockitoJUnitRunner.class)
public class RefcountedRegistrationTest {
+ @Mock
+ private SchemaSourceRegistration<?> reg;
+
+ @Before
+ public void before() {
+ doNothing().when(reg).close();
+ }
@Test
public void refcountDecTrue() {
- final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
final RefcountedRegistration ref = new RefcountedRegistration(reg);
- Assert.assertTrue(ref.decRef());
- Mockito.verify(reg, Mockito.times(1)).close();
+ assertTrue(ref.decRef());
+ verify(reg, times(1)).close();
}
@Test
public void refcountIncDecFalse() {
- final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
final RefcountedRegistration ref = new RefcountedRegistration(reg);
ref.incRef();
- Assert.assertFalse(ref.decRef());
- Mockito.verify(reg, Mockito.times(0)).close();
+ assertFalse(ref.decRef());
+ verify(reg, times(0)).close();
}
@Test
public void refcountIncDecTrue() {
- final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
final RefcountedRegistration ref = new RefcountedRegistration(reg);
ref.incRef();
- Assert.assertFalse(ref.decRef());
- Assert.assertTrue(ref.decRef());
- Mockito.verify(reg, Mockito.times(1)).close();
+ assertFalse(ref.decRef());
+ assertTrue(ref.decRef());
+ verify(reg, times(1)).close();
}
}
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
import java.util.Arrays;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
@Override
public ListenableFuture<? extends YangSchemaSourceRepresentation> getSource(
final SourceIdentifier sourceIdentifier) {
- return Mockito.mock(ListenableFuture.class);
+ return SettableFuture.create();
}
}
import java.util.Collections;
import java.util.Optional;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+@RunWith(MockitoJUnitRunner.class)
public class BitsTypeTest {
-
@Mock
private BitsTypeDefinition.Bit bit;
@Test
public void canCreateBitsType() {
- MockitoAnnotations.initMocks(this);
doReturn("test").when(bit).getName();
+ doReturn(0L).when(bit).getPosition();
+ doReturn("toString").when(bit).toString();
QName qname = QName.create("namespace", "localname");
SchemaPath schemaPath = SchemaPath.create(true, qname);
assertNotEquals("bitsType shouldn't equal to null", null, bitsType);
assertEquals("bitsType should equals to itself", bitsType, bitsType);
assertNotEquals("bitsType shouldn't equal to object of other type", "str", bitsType);
-
}
-
}
import java.util.SortedMap;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.CopyableNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+@RunWith(MockitoJUnitRunner.class)
public class DataNodeIteratorTest {
-
private DataNodeIterator dataNodeIterator;
@Before
- public void setUp() {
- DataNodeContainer dataNodeContainer = mock(DataNodeContainer.class);
- this.dataNodeIterator = new DataNodeIterator(dataNodeContainer);
+ public void before() {
+ this.dataNodeIterator = new DataNodeIterator(mockDataNodeContainer(DataNodeContainer.class));
+ }
+
+ private static <T extends DataNodeContainer> T mockDataNodeContainer(final Class<T> clazz) {
+ final T mock = mock(clazz);
+ doReturn(Collections.emptyList()).when(mock).getChildNodes();
+ doReturn(Collections.emptySet()).when(mock).getGroupings();
+ doReturn(Collections.emptySet()).when(mock).getTypeDefinitions();
+ return mock;
+ }
+
+ private static <T extends OperationDefinition> T mockOperationDefinition(final T mock) {
+ doReturn(Collections.emptySet()).when(mock).getGroupings();
+ doReturn(Collections.emptySet()).when(mock).getTypeDefinitions();
+ doReturn(mockDataNodeContainer(ContainerSchemaNode.class)).when(mock).getInput();
+ doReturn(mockDataNodeContainer(ContainerSchemaNode.class)).when(mock).getOutput();
+ return mock;
+ }
+
+ @Deprecated
+ private static <T extends CopyableNode> T mockCopyableNode(final boolean augmenting, final T node) {
+ doReturn(augmenting).when(node).isAugmenting();
+ return node;
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testTraversal() {
- final Module mockedModule = mock(Module.class);
-
- final ContainerSchemaNode mockedAugmentingContainer = mock(ContainerSchemaNode.class);
- doReturn(true).when(mockedAugmentingContainer).isAugmenting();
+ final Module mockedModule = mockDataNodeContainer(Module.class);
- final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class);
+ final ContainerSchemaNode mockedAugmentingContainer = mockCopyableNode(true, mock(ContainerSchemaNode.class));
+ final ContainerSchemaNode mockedContainer = mockCopyableNode(false, mockDataNodeContainer(
+ ContainerSchemaNode.class));
- final ListSchemaNode mockedList = mock(ListSchemaNode.class);
+ final ListSchemaNode mockedList = mockCopyableNode(false, mockDataNodeContainer(ListSchemaNode.class));
- final ChoiceSchemaNode mockedChoice = mock(ChoiceSchemaNode.class);
- final CaseSchemaNode mockedCase1 = mock(CaseSchemaNode.class);
+ final ChoiceSchemaNode mockedChoice = mockCopyableNode(false, mock(ChoiceSchemaNode.class));
+ final CaseSchemaNode mockedCase1 = mockDataNodeContainer(CaseSchemaNode.class);
final QName mockedCase1QName = QName.create("", "case1");
- final CaseSchemaNode mockedCase2 = mock(CaseSchemaNode.class);
+ final CaseSchemaNode mockedCase2 = mockDataNodeContainer(CaseSchemaNode.class);
final QName mockedCase2QName = QName.create("", "case2");
final SortedMap<QName, CaseSchemaNode> cases = ImmutableSortedMap.of(mockedCase1QName, mockedCase1,
mockedCase2QName, mockedCase2);
mockedChoice);
doReturn(childNodes).when(mockedModule).getChildNodes();
- final NotificationDefinition mockedNotification = mock(NotificationDefinition.class);
- final ContainerSchemaNode mockedContainerInNotification = mock(ContainerSchemaNode.class);
+ final NotificationDefinition mockedNotification = mockDataNodeContainer(NotificationDefinition.class);
+ final ContainerSchemaNode mockedContainerInNotification = mockCopyableNode(false,
+ mockDataNodeContainer(ContainerSchemaNode.class));
final Set<DataSchemaNode> notificationChildNodes = ImmutableSet.of(mockedContainerInNotification);
doReturn(notificationChildNodes).when(mockedNotification).getChildNodes();
final Set<NotificationDefinition> notifications = ImmutableSet.of(mockedNotification);
doReturn(notifications).when(mockedModule).getNotifications();
- final RpcDefinition mockedRpc = mock(RpcDefinition.class);
- final ContainerSchemaNode mockedContainerInRpcInput = mock(ContainerSchemaNode.class);
- final ListSchemaNode mockedListInRpcInputContainer = mock(ListSchemaNode.class);
+ final RpcDefinition mockedRpc = mockOperationDefinition(mock(RpcDefinition.class));
+ final ContainerSchemaNode mockedContainerInRpcInput = mockDataNodeContainer(ContainerSchemaNode.class);
+ final ListSchemaNode mockedListInRpcInputContainer = mockCopyableNode(false,
+ mockDataNodeContainer(ListSchemaNode.class));
final Set<DataSchemaNode> rpcInputChildNodes = ImmutableSet.of(mockedListInRpcInputContainer);
doReturn(rpcInputChildNodes).when(mockedContainerInRpcInput).getChildNodes();
doReturn(mockedContainerInRpcInput).when(mockedRpc).getInput();
doReturn(rpcs).when(mockedModule).getRpcs();
- final GroupingDefinition mockedGrouping = mock(GroupingDefinition.class);
+ final GroupingDefinition mockedGrouping = mockDataNodeContainer(GroupingDefinition.class);
final Set<GroupingDefinition> groupings = ImmutableSet.of(mockedGrouping);
doReturn(groupings).when(mockedModule).getGroupings();
MockitoAnnotations.initMocks(this);
doReturn(Optional.empty()).when(mockSchemaContext).findModule(any(QNameModule.class));
+ doReturn("test").when(mockModule).getName();
doReturn("test").when(mockModule).getPrefix();
doReturn(NAMESPACE).when(mockModule).getNamespace();
doReturn(QNameModule.create(NAMESPACE)).when(mockModule).getQNameModule();
doReturn(mod.getRevision()).when(ret).getRevision();
doReturn(mod).when(ret).getQNameModule();
doReturn(mod.toString()).when(ret).toString();
+ doReturn(ImmutableSet.of()).when(ret).getImports();
return ret;
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableList;
public void identityrefTypeTest() {
final IdentityrefTypeBuilder identityrefTypeBuilder1 = BaseTypes.identityrefTypeBuilder(SCHEMA_PATH);
final IdentitySchemaNode identitySchemaNode = mock(IdentitySchemaNode.class);
+ doReturn("identitySchemaNode").when(identitySchemaNode).toString();
identityrefTypeBuilder1.addIdentity(identitySchemaNode);
final IdentityrefTypeDefinition identityrefTypeDefinition1 = identityrefTypeBuilder1.build();
final IdentityrefTypeBuilder identityrefTypeBuilder2 = BaseTypes.identityrefTypeBuilder(SCHEMA_PATH);