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