|
| 1 | +package com.iluwatar.prototype; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; |
| 5 | +import org.junit.runners.Parameterized; |
| 6 | + |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.Collection; |
| 9 | + |
| 10 | +import static org.junit.Assert.assertEquals; |
| 11 | +import static org.junit.Assert.assertNotNull; |
| 12 | +import static org.junit.Assert.assertNotSame; |
| 13 | +import static org.junit.Assert.assertSame; |
| 14 | + |
| 15 | +/** |
| 16 | + * Date: 12/28/15 - 8:45 PM |
| 17 | + * |
| 18 | + * @author Jeroen Meulemeester |
| 19 | + */ |
| 20 | +@RunWith(Parameterized.class) |
| 21 | +public class PrototypeTest<P extends Prototype> { |
| 22 | + |
| 23 | + @Parameterized.Parameters |
| 24 | + public static Collection<Object[]> data() { |
| 25 | + return Arrays.asList( |
| 26 | + new Object[]{new OrcBeast(), "Orcish wolf"}, |
| 27 | + new Object[]{new OrcMage(), "Orcish mage"}, |
| 28 | + new Object[]{new OrcWarlord(), "Orcish warlord"}, |
| 29 | + new Object[]{new ElfBeast(), "Elven eagle"}, |
| 30 | + new Object[]{new ElfMage(), "Elven mage"}, |
| 31 | + new Object[]{new ElfWarlord(), "Elven warlord"} |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * The tested prototype instance |
| 37 | + */ |
| 38 | + private final Prototype testedPrototype; |
| 39 | + |
| 40 | + /** |
| 41 | + * The expected {@link Prototype#toString()} value |
| 42 | + */ |
| 43 | + private final String expectedToString; |
| 44 | + |
| 45 | + /** |
| 46 | + * Create a new test instance, using the given test object and expected value |
| 47 | + * |
| 48 | + * @param testedPrototype The tested prototype instance |
| 49 | + * @param expectedToString The expected {@link Prototype#toString()} value |
| 50 | + */ |
| 51 | + public PrototypeTest(final Prototype testedPrototype, final String expectedToString) { |
| 52 | + this.expectedToString = expectedToString; |
| 53 | + this.testedPrototype = testedPrototype; |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testPrototype() throws Exception { |
| 58 | + assertEquals(this.expectedToString, this.testedPrototype.toString()); |
| 59 | + |
| 60 | + final Object clone = this.testedPrototype.clone(); |
| 61 | + assertNotNull(clone); |
| 62 | + assertNotSame(clone, this.testedPrototype); |
| 63 | + assertSame(this.testedPrototype.getClass(), clone.getClass()); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments