Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 18 | import org.junit.Ignore; |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 19 | import org.junit.Test; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 20 | |
| 21 | import java.util.Arrays; |
| 22 | import java.util.HashSet; |
| 23 | import java.util.Set; |
| 24 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 25 | import static org.junit.Assert.*; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Base facilities to test various intent tests. |
| 29 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 30 | public abstract class IntentTest extends AbstractIntentTest { |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Produces a set of items from the supplied items. |
| 33 | * |
| 34 | * @param items items to be placed in set |
| 35 | * @param <T> item type |
| 36 | * @return set of items |
| 37 | */ |
| 38 | protected static <T> Set<T> itemSet(T[] items) { |
| 39 | return new HashSet<>(Arrays.asList(items)); |
| 40 | } |
| 41 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 42 | @Test @Ignore("Equality is based on ids, which will be different") |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 43 | public void equalsAndHashCode() { |
| 44 | Intent one = createOne(); |
| 45 | Intent like = createOne(); |
| 46 | Intent another = createAnother(); |
| 47 | |
| 48 | assertTrue("should be equal", one.equals(like)); |
| 49 | assertEquals("incorrect hashCode", one.hashCode(), like.hashCode()); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 50 | assertFalse("should not be equal", one.equals(another)); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 53 | //@Test FIXME |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 54 | public void testToString() { |
| 55 | Intent one = createOne(); |
| 56 | Intent like = createOne(); |
| 57 | assertEquals("incorrect toString", one.toString(), like.toString()); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new intent, but always a like intent, i.e. all instances will |
| 62 | * be equal, but should not be the same. |
| 63 | * |
| 64 | * @return intent |
| 65 | */ |
| 66 | protected abstract Intent createOne(); |
| 67 | |
| 68 | /** |
| 69 | * Creates another intent, not equals to the one created by |
| 70 | * {@link #createOne()} and with a different hash code. |
| 71 | * |
| 72 | * @return another intent |
| 73 | */ |
| 74 | protected abstract Intent createAnother(); |
| 75 | } |