Bug 3899: Milestone: Increase test coverage for Yangtools 79/34379/1
authorJakub Toth <jatoth@cisco.com>
Tue, 9 Feb 2016 13:51:34 +0000 (14:51 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 10 Feb 2016 10:28:45 +0000 (10:28 +0000)
test RefcountedRegistrationTest

Change-Id: Ie3053de3422ec5ffe4bb8ae7e7bf23b147ac4a4d
Signed-off-by: Jakub Toth <jatoth@cisco.com>
(cherry picked from commit 79a6c2ebfeeb92665ae217a9b7423da3ef92b19e)

yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/RefcountedRegistrationTest.java [new file with mode: 0644]

diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/RefcountedRegistrationTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/RefcountedRegistrationTest.java
new file mode 100644 (file)
index 0000000..4cdb023
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.repo.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
+
+public class RefcountedRegistrationTest {
+
+    @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();
+    }
+
+    @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();
+    }
+
+    @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();
+    }
+}