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.util;
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;
21 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
23 @RunWith(MockitoJUnitRunner.class)
24 public class RefcountedRegistrationTest {
26 public SchemaSourceRegistration<?> reg;
29 public void before() {
30 doNothing().when(reg).close();
34 public void refcountDecTrue() {
35 final RefcountedRegistration ref = new RefcountedRegistration(reg);
36 assertTrue(ref.decRef());
37 verify(reg, times(1)).close();
41 public void refcountIncDecFalse() {
42 final RefcountedRegistration ref = new RefcountedRegistration(reg);
44 assertFalse(ref.decRef());
45 verify(reg, times(0)).close();
49 public void refcountIncDecTrue() {
50 final RefcountedRegistration ref = new RefcountedRegistration(reg);
52 assertFalse(ref.decRef());
53 assertTrue(ref.decRef());
54 verify(reg, times(1)).close();