Sho SHIMIZU

Add unit tests for EmptyDiscreteResources

Change-Id: I2dd53e98eb3129607f5faadf3a1f9ecab378d36c
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.store.resource.impl;
18 +
19 +import com.google.common.collect.ImmutableSet;
20 +import org.junit.Test;
21 +import org.onosproject.net.DeviceId;
22 +import org.onosproject.net.resource.DiscreteResource;
23 +import org.onosproject.net.resource.Resources;
24 +
25 +import java.util.Optional;
26 +
27 +import static org.hamcrest.Matchers.is;
28 +import static org.junit.Assert.*;
29 +
30 +public class EmptyDiscreteResourcesTest {
31 + private EmptyDiscreteResources sut = EmptyDiscreteResources.INSTANCE;
32 +
33 + @Test
34 + public void testLookup() {
35 + assertThat(sut.lookup(Resources.discrete(DeviceId.deviceId("a")).id()), is(Optional.empty()));
36 + }
37 +
38 + @Test
39 + public void testDifference() {
40 + DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a")).resource();
41 + DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("b")).resource();
42 +
43 + assertThat(sut.difference(DiscreteResources.of(ImmutableSet.of(res1))),
44 + is(EmptyDiscreteResources.INSTANCE));
45 + assertThat(sut.difference(DiscreteResources.of(ImmutableSet.of(res2))),
46 + is(EmptyDiscreteResources.INSTANCE));
47 + }
48 +
49 + @Test
50 + public void testIsEmpty() {
51 + assertThat(sut.isEmpty(), is(true));
52 + }
53 +
54 + @Test
55 + public void testContainsAny() {
56 + DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a")).resource();
57 + DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("b")).resource();
58 +
59 + assertThat(sut.containsAny(ImmutableSet.of(res1)), is(false));
60 + assertThat(sut.containsAny(ImmutableSet.of(res2)), is(false));
61 + }
62 +
63 + @Test
64 + public void testAdd() {
65 + DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a")).resource();
66 + DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("b")).resource();
67 +
68 + assertThat(sut.add(DiscreteResources.of(ImmutableSet.of(res1))),
69 + is(DiscreteResources.of(ImmutableSet.of(res1))));
70 + assertThat(sut.add(DiscreteResources.of(ImmutableSet.of(res2))),
71 + is(DiscreteResources.of(ImmutableSet.of(res2))));
72 + }
73 +
74 + @Test
75 + public void testValues() {
76 + assertThat(sut.values(), is(ImmutableSet.of()));
77 + }
78 +}