2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.repo.spi;
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;
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;
22 @RunWith(MockitoJUnitRunner.class)
23 public class RefcountedRegistrationTest {
25 public SchemaSourceRegistration<?> reg;
28 public void before() {
29 doNothing().when(reg).close();
33 public void refcountDecTrue() {
34 final RefcountedRegistration ref = new RefcountedRegistration(reg);
35 assertTrue(ref.decRef());
36 verify(reg, times(1)).close();
40 public void refcountIncDecFalse() {
41 final RefcountedRegistration ref = new RefcountedRegistration(reg);
43 assertFalse(ref.decRef());
44 verify(reg, times(0)).close();
48 public void refcountIncDecTrue() {
49 final RefcountedRegistration ref = new RefcountedRegistration(reg);
51 assertFalse(ref.decRef());
52 assertTrue(ref.decRef());
53 verify(reg, times(1)).close();