Bug 3899: Milestone: Increase test coverage for Yangtools
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / repo / util / RefcountedRegistrationTest.java
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();
+    }
+}