Skip to content

Commit

Permalink
initial demonstration conditions show tests defined,
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Hartsock committed Mar 18, 2012
1 parent 13adba7 commit 0e73773
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@
*/
public class LinkedMap implements ObjectMap {

@Override
public void put(Object key, Object value) {
// TODO Auto-generated method stub

}

@Override
public Object get(Object key) {
// TODO Auto-generated method stub
return null;
}

}
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/>
Expand All @@ -11,8 +11,8 @@
public class LinkedMapTest extends ObjectMapTest {

@Override
@AfterClass
public void setUp() {
@Before
public void allocateMap() {
map = new LinkedMap();
}
}
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);
}

}

0 comments on commit 0e73773

Please sign in to comment.