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 org.junit.Assert;
11 import org.junit.Test;
12 import org.mockito.Mockito;
13 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
15 public class RefcountedRegistrationTest {
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();
26 public void refcountIncDecFalse() {
27 final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
28 final RefcountedRegistration ref = new RefcountedRegistration(reg);
30 Assert.assertFalse(ref.decRef());
31 Mockito.verify(reg, Mockito.times(0)).close();
35 public void refcountIncDecTrue() {
36 final SchemaSourceRegistration<?> reg = Mockito.mock(SchemaSourceRegistration.class);
37 final RefcountedRegistration ref = new RefcountedRegistration(reg);
39 Assert.assertFalse(ref.decRef());
40 Assert.assertTrue(ref.decRef());
41 Mockito.verify(reg, Mockito.times(1)).close();