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
9 package org.opendaylight.yanglib.impl;
11 import static junit.framework.TestCase.assertTrue;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.eq;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17 import static org.mockito.Mockito.when;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.BDDMockito;
23 import org.opendaylight.yanglib.api.YangLibRestAppService;
24 import org.osgi.framework.Bundle;
25 import org.osgi.framework.BundleContext;
26 import org.osgi.framework.FrameworkUtil;
27 import org.powermock.api.mockito.PowerMockito;
28 import org.powermock.core.classloader.annotations.PrepareForTest;
29 import org.powermock.modules.junit4.PowerMockRunner;
31 @RunWith(PowerMockRunner.class)
32 @PrepareForTest(FrameworkUtil.class)
33 public class YangLibRestAppTest {
36 public void testYangLibRestApp() {
37 PowerMockito.mockStatic(FrameworkUtil.class);
39 final BundleContext bundleContext = mock(BundleContext.class);
40 final Bundle bundle = mock(Bundle.class);
42 BDDMockito.given(FrameworkUtil.getBundle(any())).willReturn(bundle);
43 when(bundle.getBundleContext()).thenReturn(bundleContext);
45 final YangLibRestApp yangLibRestApp = new YangLibRestApp();
46 final Set singleton = yangLibRestApp.getSingletons();
48 assertTrue(singleton.contains(yangLibRestApp.getYangLibService()));
50 verify(bundleContext, times(1)).registerService(eq(YangLibRestAppService.class.getName()), eq(yangLibRestApp), eq(null));