REOPENED - BATCH-900: Retreive null values from the ExecutionContext

putting null value now equals removing entry for given key
This commit is contained in:
robokaso
2008-11-04 16:29:33 +00:00
parent aae3e2ecce
commit 2bfe9c0fc3
2 changed files with 53 additions and 66 deletions

View File

@@ -27,7 +27,7 @@ import org.junit.Test;
/**
* @author Lucas Ward
*
*
*/
public class ExecutionContextTests {
@@ -37,15 +37,15 @@ public class ExecutionContextTests {
public void setUp() throws Exception {
context = new ExecutionContext();
}
@Test
public void testNormalUsage(){
public void testNormalUsage() {
context.putString("1", "testString1");
context.putString("2", "testString2");
context.putLong("3", 3);
context.putDouble("4", 4.4);
assertEquals("testString1", context.getString("1"));
assertEquals("testString2", context.getString("2"));
assertEquals("defaultString", context.getString("5", "defaultString"));
@@ -54,96 +54,99 @@ public class ExecutionContextTests {
assertEquals(3, context.getLong("3"));
assertEquals(5, context.getLong("5", 5));
}
@Test
public void testInvalidCast(){
public void testInvalidCast() {
context.putLong("1", 1);
try{
try {
context.getDouble("1");
fail();
}
catch(ClassCastException ex){
//expected
catch (ClassCastException ex) {
// expected
}
}
@Test
public void testIsEmpty(){
public void testIsEmpty() {
assertTrue(context.isEmpty());
context.putString("1", "test");
assertFalse(context.isEmpty());
}
@Test
public void testDirtyFlag(){
public void testDirtyFlag() {
assertFalse(context.isDirty());
context.putString("1", "test");
assertTrue(context.isDirty());
context.clearDirtyFlag();
assertFalse(context.isDirty());
}
@Test
public void testContains(){
public void testContains() {
context.putString("1", "testString");
assertTrue(context.containsKey("1"));
assertTrue(context.containsValue("testString"));
}
@Test
public void testEquals(){
public void testEquals() {
context.putString("1", "testString");
ExecutionContext tempContext = new ExecutionContext();
assertFalse(tempContext.equals(context));
tempContext.putString("1", "testString");
assertTrue(tempContext.equals(context));
}
@Test
public void testSerializationCheck(){
//adding a non serializable object should cause an error.
try{
public void testSerializationCheck() {
// adding a non serializable object should cause an error.
try {
context.put("1", new Object());
fail();
}
catch(IllegalArgumentException ex){
//expected
catch (IllegalArgumentException ex) {
// expected
}
}
/**
* Putting null value is equivalent to removing the entry for the given key.
*/
@Test
public void testPutNull(){
//putting null should work
public void testPutNull() {
context.put("1", null);
assertNull(context.get("1"));
assertFalse(context.containsKey("1"));
}
@Test
public void testGetNull() {
assertNull(context.get("does not exist"));
}
@Test
public void testSerialization() {
TestSerializable s = new TestSerializable();
s.value = 7;
context.putString("1", "testString1");
context.putString("2", "testString2");
context.putLong("3", 3);
context.putDouble("4", 4.4);
context.put("5", s);
byte[] serialized = SerializationUtils.serialize(context);
ExecutionContext deserialized = (ExecutionContext) SerializationUtils.deserialize(serialized);
assertEquals(context, deserialized);
assertEquals(7, ((TestSerializable)deserialized.get("5")).value);
assertEquals(7, ((TestSerializable) deserialized.get("5")).value);
}
@Test
public void testCopyConstructor() throws Exception {
ExecutionContext context = new ExecutionContext();
@@ -151,13 +154,13 @@ public class ExecutionContextTests {
ExecutionContext copy = new ExecutionContext(context);
assertEquals(copy, context);
}
@Test
public void testCopyConstructorNullnNput() throws Exception {
ExecutionContext context = new ExecutionContext((ExecutionContext)null);
ExecutionContext context = new ExecutionContext((ExecutionContext) null);
assertTrue(context.isEmpty());
}
/**
* Value object for testing serialization
*/
@@ -172,9 +175,7 @@ public class ExecutionContextTests {
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
}