ec8f6bdf0f763b6f0437312eba9e9218b09680e4
[yangtools.git] / yang / yang-repo-spi / src / test / java / org / opendaylight / yangtools / yang / model / repo / spi / 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.spi;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21
22 @RunWith(MockitoJUnitRunner.class)
23 public class RefcountedRegistrationTest {
24     @Mock
25     public SchemaSourceRegistration<?> reg;
26
27     @Before
28     public void before() {
29         doNothing().when(reg).close();
30     }
31
32     @Test
33     public void refcountDecTrue() {
34         final RefcountedRegistration ref = new RefcountedRegistration(reg);
35         assertTrue(ref.decRef());
36         verify(reg, times(1)).close();
37     }
38
39     @Test
40     public void refcountIncDecFalse() {
41         final RefcountedRegistration ref = new RefcountedRegistration(reg);
42         ref.incRef();
43         assertFalse(ref.decRef());
44         verify(reg, times(0)).close();
45     }
46
47     @Test
48     public void refcountIncDecTrue() {
49         final RefcountedRegistration ref = new RefcountedRegistration(reg);
50         ref.incRef();
51         assertFalse(ref.decRef());
52         assertTrue(ref.decRef());
53         verify(reg, times(1)).close();
54     }
55 }