From: Jakub Toth Date: Tue, 9 Feb 2016 13:51:34 +0000 (+0100) Subject: Bug 3899: Milestone: Increase test coverage for Yangtools X-Git-Tag: release/beryllium~5 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=6ecb495f3729e75f8e86ab72ffa68eed3d14cc4c Bug 3899: Milestone: Increase test coverage for Yangtools test RefcountedRegistrationTest Change-Id: Ie3053de3422ec5ffe4bb8ae7e7bf23b147ac4a4d Signed-off-by: Jakub Toth (cherry picked from commit 79a6c2ebfeeb92665ae217a9b7423da3ef92b19e) --- 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(); + } +}