From 79a6c2ebfeeb92665ae217a9b7423da3ef92b19e Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Tue, 9 Feb 2016 14:51:34 +0100 Subject: [PATCH] Bug 3899: Milestone: Increase test coverage for Yangtools test RefcountedRegistrationTest Change-Id: Ie3053de3422ec5ffe4bb8ae7e7bf23b147ac4a4d Signed-off-by: Jakub Toth --- .../repo/util/RefcountedRegistrationTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 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 index 0000000000..4cdb023357 --- /dev/null +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/RefcountedRegistrationTest.java @@ -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(); + } +} -- 2.36.6