Harden yang-model-util test suite
[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 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.runners.MockitoJUnitRunner;
21 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
22
23 @RunWith(MockitoJUnitRunner.class)
24 public class RefcountedRegistrationTest {
25     @Mock
26     private SchemaSourceRegistration<?> reg;
27
28     @Before
29     public void before() {
30         doNothing().when(reg).close();
31     }
32
33     @Test
34     public void refcountDecTrue() {
35         final RefcountedRegistration ref = new RefcountedRegistration(reg);
36         assertTrue(ref.decRef());
37         verify(reg, times(1)).close();
38     }
39
40     @Test
41     public void refcountIncDecFalse() {
42         final RefcountedRegistration ref = new RefcountedRegistration(reg);
43         ref.incRef();
44         assertFalse(ref.decRef());
45         verify(reg, times(0)).close();
46     }
47
48     @Test
49     public void refcountIncDecTrue() {
50         final RefcountedRegistration ref = new RefcountedRegistration(reg);
51         ref.incRef();
52         assertFalse(ref.decRef());
53         assertTrue(ref.decRef());
54         verify(reg, times(1)).close();
55     }
56 }