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
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.model.repo.util;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.mockito.Mockito;
13 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
14
15 public class RefcountedRegistrationTest {
16
17     @Test
18     public void refcountDecTrue() {
19         final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
20         final RefcountedRegistration ref = new RefcountedRegistration(reg);
21         Assert.assertTrue(ref.decRef());
22         Mockito.verify(reg, Mockito.times(1)).close();
23     }
24
25     @Test
26     public void refcountIncDecFalse() {
27         final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
28         final RefcountedRegistration ref = new RefcountedRegistration(reg);
29         ref.incRef();
30         Assert.assertFalse(ref.decRef());
31         Mockito.verify(reg, Mockito.times(0)).close();
32     }
33
34     @Test
35     public void refcountIncDecTrue() {
36         final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
37         final RefcountedRegistration ref = new RefcountedRegistration(reg);
38         ref.incRef();
39         Assert.assertFalse(ref.decRef());
40         Assert.assertTrue(ref.decRef());
41         Mockito.verify(reg, Mockito.times(1)).close();
42     }
43 }