2 * Copyright (C) 2015 Red Hat, 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
10 package org.opendaylight.ovsdb.utils.servicehelper;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.mockito.Matchers.any;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.osgi.framework.Bundle;
19 import org.osgi.framework.FrameworkUtil;
20 import org.powermock.api.mockito.PowerMockito;
21 import org.powermock.core.classloader.annotations.PrepareForTest;
22 import org.powermock.modules.junit4.PowerMockRunner;
23 import org.springframework.osgi.mock.MockBundle;
27 * {@link ServiceHelper}
29 @RunWith(PowerMockRunner.class)
30 @PrepareForTest(FrameworkUtil.class)
31 public class ServiceHelperTest {
35 * {@link ServiceHelper#getGlobalInstance(Class, Object)}
37 public void getGlobalInstanceTest () {
38 Bundle bundle = new MockBundle();
40 PowerMockito.mockStatic(FrameworkUtil.class);
42 PowerMockito.when(FrameworkUtil.getBundle(any(Class.class)))
44 Object object = ServiceHelper.getGlobalInstance(Test.class, this);
45 assertNull("Service should be null", object);
47 PowerMockito.when(FrameworkUtil.getBundle(any(Class.class)))
49 object = ServiceHelper.getGlobalInstance(Test.class, this);
50 assertNotNull("Service should not be null", object);