Ray Milkey | 96495ca | 2015-07-07 11:02:10 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 96495ca | 2015-07-07 11:02:10 -0700 | [diff] [blame] | 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 | package org.onosproject.store.cluster.messaging; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | |
| 20 | import com.google.common.testing.EqualsTester; |
| 21 | |
| 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for MessageSubject class. |
| 28 | */ |
| 29 | public class MessageSubjectTest { |
| 30 | private final MessageSubject subject1 = new MessageSubject("Message 1"); |
| 31 | private final MessageSubject sameAsSubject1 = new MessageSubject("Message 1"); |
| 32 | private final MessageSubject subject2 = new MessageSubject("Message 2"); |
| 33 | private final MessageSubject subject3 = new MessageSubject("Message 3"); |
| 34 | |
| 35 | /** |
| 36 | * Checks that the MessageSubject class is immutable. |
| 37 | */ |
| 38 | @Test |
| 39 | public void testImmutability() { |
| 40 | assertThatClassIsImmutable(MessageSubject.class); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 45 | */ |
| 46 | @Test |
| 47 | public void testEquals() { |
| 48 | new EqualsTester() |
| 49 | .addEqualityGroup(subject1, sameAsSubject1) |
| 50 | .addEqualityGroup(subject2) |
| 51 | .addEqualityGroup(subject3) |
| 52 | .testEquals(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Checks the construction of a MessageSubject object. |
| 57 | */ |
| 58 | @Test |
| 59 | public void testConstruction() { |
| 60 | assertThat(subject3.value(), is("Message 3")); |
| 61 | MessageSubject serializerObject = new MessageSubject(); |
| 62 | assertThat(serializerObject.value(), is("")); |
| 63 | } |
| 64 | } |