mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-03 00:00:04 -04:00
New code style. No functional changes.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.twelvemonkeys.lang;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -19,7 +20,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureNoMehtod() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put("noSuchMethod", "jaffa");
|
||||
|
||||
@@ -34,7 +35,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureNoMethodArgs() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("doubleValue", new Object()); // Should not be able to convert this
|
||||
|
||||
@@ -52,7 +53,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureNullValue() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("stringValue", null);
|
||||
|
||||
@@ -69,11 +70,11 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureSimple() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", "one");
|
||||
map.put("intValue", new Integer(2));
|
||||
map.put("doubleValue", new Double(.3));
|
||||
map.put("intValue", 2);
|
||||
map.put("doubleValue", .3);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
@@ -84,15 +85,15 @@ public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
assertEquals("one", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(new Double(.3), bean.getDoubleValue());
|
||||
assertEquals(.3, bean.getDoubleValue());
|
||||
}
|
||||
|
||||
public void testConfigureConvert() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String,Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", new Integer(1));
|
||||
map.put("stringValue", 1);
|
||||
map.put("intValue", "2");
|
||||
map.put("doubleValue", NumberFormat.getNumberInstance().format(0.3)); // Note, format is locale specific...
|
||||
|
||||
@@ -105,13 +106,13 @@ public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
assertEquals("1", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(new Double(.3), bean.getDoubleValue());
|
||||
assertEquals(.3, bean.getDoubleValue());
|
||||
}
|
||||
|
||||
public void testConfigureAmbigious1() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
String value = "one";
|
||||
map.put("ambigious", value);
|
||||
@@ -133,9 +134,9 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureAmbigious2() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
|
||||
Integer value = new Integer(2);
|
||||
Integer value = 2;
|
||||
map.put("ambigious", value);
|
||||
|
||||
try {
|
||||
@@ -147,7 +148,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
assertNotNull(bean.getAmbigious());
|
||||
assertEquals("Integer converted rather than invoking setAmbigiouos(Integer), ordering not predictable",
|
||||
new Integer(2), bean.getAmbigious());
|
||||
2, bean.getAmbigious());
|
||||
assertSame("Integer converted rather than invoking setAmbigiouos(Integer), ordering not predictable",
|
||||
value, bean.getAmbigious());
|
||||
}
|
||||
@@ -155,9 +156,9 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureAmbigious3() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Double> map = new HashMap<String, Double>();
|
||||
|
||||
Double value = new Double(.3);
|
||||
Double value = .3;
|
||||
map.put("ambigious", value);
|
||||
|
||||
try {
|
||||
@@ -175,54 +176,54 @@ public class BeanUtilTestCase extends TestCase {
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
private String mString;
|
||||
private int mInt;
|
||||
private Double mDouble;
|
||||
private String stringVal;
|
||||
private int intVal;
|
||||
private Double doubleVal;
|
||||
|
||||
private Object mAmbigious;
|
||||
private Object ambigious;
|
||||
|
||||
public Double getDoubleValue() {
|
||||
return mDouble;
|
||||
return doubleVal;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return mInt;
|
||||
return intVal;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return mString;
|
||||
return stringVal;
|
||||
}
|
||||
|
||||
public void setStringValue(String pString) {
|
||||
mString = pString;
|
||||
stringVal = pString;
|
||||
}
|
||||
|
||||
public void setIntValue(int pInt) {
|
||||
mInt = pInt;
|
||||
intVal = pInt;
|
||||
}
|
||||
|
||||
public void setDoubleValue(Double pDouble) {
|
||||
mDouble = pDouble;
|
||||
doubleVal = pDouble;
|
||||
}
|
||||
|
||||
public void setAmbigious(String pString) {
|
||||
mAmbigious = pString;
|
||||
ambigious = pString;
|
||||
}
|
||||
|
||||
public void setAmbigious(Object pObject) {
|
||||
mAmbigious = pObject;
|
||||
ambigious = pObject;
|
||||
}
|
||||
|
||||
public void setAmbigious(Integer pInteger) {
|
||||
mAmbigious = pInteger;
|
||||
ambigious = pInteger;
|
||||
}
|
||||
|
||||
public void setAmbigious(int pInt) {
|
||||
mAmbigious = new Long(pInt); // Just to differentiate...
|
||||
ambigious = (long) pInt; // Just to differentiate...
|
||||
}
|
||||
|
||||
public Object getAmbigious() {
|
||||
return mAmbigious;
|
||||
return ambigious;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class ObjectAbstractTestCase extends TestCase {
|
||||
clone.setAccessible(true);
|
||||
}
|
||||
|
||||
Object cloned = clone.invoke(obj, null);
|
||||
Object cloned = clone.invoke(obj);
|
||||
|
||||
assertNotNull("Cloned object should never be null", cloned);
|
||||
|
||||
|
||||
@@ -34,17 +34,16 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Map makeEmptyMap() {
|
||||
LRUMap map = new LRUMap();
|
||||
return map;
|
||||
return new LRUMap();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testRemoveLRU() {
|
||||
LRUMap map2 = new LRUMap(3);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"foo");
|
||||
map2.put(new Integer(3),"foo");
|
||||
map2.put(new Integer(4),"foo"); // removes 1 since max size exceeded
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"foo");
|
||||
map2.put(3,"foo");
|
||||
map2.put(4,"foo"); // removes 1 since max size exceeded
|
||||
map2.removeLRU(); // should be Integer(2)
|
||||
|
||||
assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo"));
|
||||
@@ -52,11 +51,11 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
}
|
||||
|
||||
public void testMultiplePuts() {
|
||||
LRUMap map2 = new LRUMap(2);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"bar");
|
||||
map2.put(new Integer(3),"foo");
|
||||
map2.put(new Integer(4),"bar");
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(2);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"bar");
|
||||
map2.put(3,"foo");
|
||||
map2.put(4,"bar");
|
||||
|
||||
assertTrue("last value should exist",map2.get(new Integer(4)).equals("bar"));
|
||||
assertTrue("LRU should not exist", map2.get(new Integer(1)) == null);
|
||||
@@ -67,13 +66,13 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
* to exceed its maxiumum size.
|
||||
*/
|
||||
public void testPutAll() {
|
||||
LRUMap map2 = new LRUMap(3);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"foo");
|
||||
map2.put(new Integer(3),"foo");
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"foo");
|
||||
map2.put(3,"foo");
|
||||
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put(new Integer(4),"foo");
|
||||
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
|
||||
hashMap.put(4,"foo");
|
||||
|
||||
map2.putAll(hashMap);
|
||||
|
||||
@@ -88,7 +87,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
* when setMaximumSize(int) is called
|
||||
*/
|
||||
public void testSetMaximumSize() {
|
||||
LRUMap map = new LRUMap(6);
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(6);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
@@ -102,7 +101,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
}
|
||||
|
||||
public void testGetPromotion() {
|
||||
LRUMap map = new LRUMap(3);
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(3);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
@@ -116,7 +115,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
// 2 should be evicted (then 3,1,4)
|
||||
map.put("4","4");
|
||||
|
||||
Iterator keyIterator = map.keySet().iterator();
|
||||
Iterator<String> keyIterator = map.keySet().iterator();
|
||||
Object[] keys = new Object[3];
|
||||
for (int i = 0; keyIterator.hasNext() ; ++i) {
|
||||
keys[i] = keyIterator.next();
|
||||
@@ -134,7 +133,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
* by the LRU algorithm (the removeLRU() method).
|
||||
*/
|
||||
public void testLRUSubclass() {
|
||||
LRUCounter counter = new LRUCounter(3);
|
||||
LRUCounter<String, String> counter = new LRUCounter<String, String>(3);
|
||||
// oldest <--> newest
|
||||
// 1
|
||||
counter.put("1","foo");
|
||||
@@ -165,9 +164,9 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
//assertTrue("newest key is '2'",counter.get(1).equals("2"));
|
||||
}
|
||||
|
||||
private class LRUCounter extends LRUMap {
|
||||
private class LRUCounter<K, V> extends LRUMap<K, V> {
|
||||
int removedCount = 0;
|
||||
List list = new ArrayList(3);
|
||||
List<Object> list = new ArrayList<Object>(3);
|
||||
|
||||
LRUCounter(int i) {
|
||||
super(i);
|
||||
|
||||
Reference in New Issue
Block a user