2 * Copyright (c) 2016 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
8 package org.opendaylight.odlparent.bundlestest;
10 import static com.google.common.truth.Truth.assertThat;
12 import com.google.common.collect.Lists;
13 import com.google.common.collect.Maps;
14 import java.util.Arrays;
16 import org.junit.Test;
17 import org.osgi.framework.Bundle;
18 import org.osgi.framework.ServiceReference;
21 * Unit test for ServiceReferenceUtil.
23 * @author Michael Vorburger.ch
25 public class ServiceReferenceUtilTest {
28 public void testGetUsingBundleSymbolicNames() {
29 assertThat(new ServiceReferenceUtil().getUsingBundleSymbolicNames(getServiceReference())).isEmpty();
33 public void testGetProperties() {
34 assertThat(new ServiceReferenceUtil().getProperties(getServiceReference())).containsExactly(
35 "property1", "value1",
36 "property2", Arrays.asList(new String[] { "value2.1", "value2.2" }),
40 private static ServiceReference<?> getServiceReference() {
41 return new TestServiceReference();
44 private static final class TestServiceReference implements ServiceReference<Object> {
46 private Map<String, Object> properties = Maps.newHashMap();
48 TestServiceReference() {
49 properties.put("property1", "value1");
50 properties.put("property2", Lists.newArrayList("value2.1", "value2.2"));
51 properties.put("property3", null);
55 public Object getProperty(String key) {
56 return properties.get(key);
60 public String[] getPropertyKeys() {
61 return properties.keySet().stream().toArray(String[]::new);
65 public Bundle getBundle() {
70 public Bundle[] getUsingBundles() {
75 public boolean isAssignableTo(Bundle bundle, String className) {
80 public int compareTo(Object reference) {