-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial demonstration conditions show tests defined,
- Loading branch information
Shawn Hartsock
committed
Mar 18, 2012
1 parent
13adba7
commit 0e73773
Showing
3 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.blogspot.hartsock.functionalthinking; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
/** | ||
* Shawn Hartsock | ||
* [email protected]<p/> | ||
|
@@ -11,8 +11,8 @@ | |
public class LinkedMapTest extends ObjectMapTest { | ||
|
||
@Override | ||
@AfterClass | ||
public void setUp() { | ||
@Before | ||
public void allocateMap() { | ||
map = new LinkedMap(); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/test/java/com/blogspot/hartsock/functionalthinking/ObjectMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.blogspot.hartsock.functionalthinking; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Test; | ||
|
||
public abstract class ObjectMapTest { | ||
ObjectMap map; | ||
|
||
final Object key1 = "key1"; | ||
final Object key2 = "key2"; | ||
final Object val1 = "val1"; | ||
final Object val2 = "val2"; | ||
|
||
|
||
public abstract void allocateMap(); | ||
|
||
/** | ||
* a call to put() will add the input key/value pair to the collection. | ||
*/ | ||
@Test | ||
public void testInput() { | ||
map.put(key1,val1); | ||
Object val = map.get(key1); | ||
assertNotNull(val); | ||
assertEquals(val1,val); | ||
} | ||
|
||
/* | ||
* <p/> | ||
* If the key has already been added to the collection, then the latest value will replace the existing value. | ||
*/ | ||
@Test | ||
public void testInputSameKeyTwice() { | ||
ObjectMap map = new LinkedMap(); | ||
map.put(key1,val1); | ||
Object val = map.get(key1); | ||
assertNotNull(val); | ||
assertEquals(val1,val); | ||
map.put(key1,val2); | ||
val = map.get(key1); | ||
assertNotNull(val); | ||
assertEquals(val2,val); | ||
} | ||
|
||
|
||
/** | ||
* To validate we have not cheated and are actually a collection | ||
*/ | ||
@Test | ||
public void testTwoInputs() { | ||
ObjectMap map = new LinkedMap(); | ||
map.put(key1,val1); | ||
map.put(key2,val2); | ||
Object val = map.get(key1); | ||
assertNotNull(val); | ||
assertEquals(val1,val); | ||
val = map.get(key2); | ||
assertNotNull(val); | ||
assertEquals(val2,val); | ||
} | ||
|
||
/** | ||
* A null "key" is not valid. | ||
*/ | ||
@Test(expected = Throwable.class) | ||
public void testANullKeyIsNotValid() { | ||
ObjectMap map = new LinkedMap(); | ||
map.put(null, val1); | ||
} | ||
|
||
/** | ||
* A null "key" is not valid. | ||
*/ | ||
@Test(expected = Throwable.class) | ||
public void testANullKeyIsNotValidNullObject() { | ||
ObjectMap map = new LinkedMap(); | ||
Object key = null; | ||
map.put(key,val1); | ||
} | ||
|
||
/** | ||
* A null "value" will remove any existing key from the collection. | ||
*/ | ||
@Test | ||
public void testInputThenDelete() { | ||
ObjectMap map = new LinkedMap(); | ||
map.put(key1,val1); | ||
map.put(key2,val2); | ||
Object val = map.get(key1); | ||
assertNotNull(val); | ||
assertEquals(val1,val); | ||
val = map.get(key2); | ||
assertNotNull(val); | ||
assertEquals(val2,val); | ||
map.put(key2,null); | ||
val = map.get(key1); | ||
assertNotNull(val); | ||
assertEquals(val1,val); | ||
val = map.get(key2); | ||
assertNull(val); | ||
map.put(key1,null); | ||
val = map.get(key1); | ||
assertNull(val); | ||
} | ||
|
||
} |