b5761dcc723722db091cc4e049192266c7688d2f
[sdc.git] /
1 /*
2  * Copyright © 2016-2017 European Support Limited
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.openecomp.sdc.notification.dao.types;
18
19 import org.testng.annotations.Test;
20
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Set;
24 import java.util.UUID;
25
26 import static org.testng.Assert.assertEquals;
27 import static org.testng.Assert.assertNotEquals;
28
29 /**
30  * @author EVITALIY
31  * @since 31 Dec 17
32  */
33 public class SubscribersEntityTest {
34
35     private static final Set<String> SUBSCRIBERS;
36
37     static {
38         Set<String> subs = new HashSet<>(2);
39         subs.add(UUID.randomUUID().toString());
40         subs.add(UUID.randomUUID().toString());
41         SUBSCRIBERS = Collections.unmodifiableSet(subs);
42     }
43
44     @Test
45     public void testUninitializedEquals() {
46         assertEquals(new SubscribersEntity(), new SubscribersEntity());
47     }
48
49     @Test
50     public void testEquals() {
51         String entity = UUID.randomUUID().toString();
52         assertEquals(new SubscribersEntity(entity, SUBSCRIBERS), new SubscribersEntity(entity, SUBSCRIBERS));
53     }
54
55     @Test
56     public void testEntityNotEquals() {
57         assertNotEquals(new SubscribersEntity(UUID.randomUUID().toString(), SUBSCRIBERS),
58                 new SubscribersEntity(UUID.randomUUID().toString(), SUBSCRIBERS));
59     }
60
61     @Test
62     public void testSubscribersNotEquals() {
63         String entity = UUID.randomUUID().toString();
64         assertNotEquals(new SubscribersEntity(entity, SUBSCRIBERS),
65                 // not using Collections.emptySet() to use the the same implementation class
66                 new SubscribersEntity(entity, Collections.unmodifiableSet(new HashSet<>(0))));
67     }
68
69     @Test
70     public void testHashCode() {
71         String entity = UUID.randomUUID().toString();
72         assertEquals(new SubscribersEntity(entity, SUBSCRIBERS).hashCode(),
73                 new SubscribersEntity(entity, SUBSCRIBERS).hashCode());
74     }
75 }