mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
#311 Updated license headers to be the same as in the LICENSE.txt
This commit is contained in:
+274
-235
@@ -1,235 +1,274 @@
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* BeanUtilTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/lang/BeanUtilTestCase.java#1 $
|
||||
*/
|
||||
public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
public void testConfigureNoMehtod() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put("noSuchMethod", "jaffa");
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testConfigureNoMethodArgs() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("doubleValue", new Object()); // Should not be able to convert this
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNull(bean.getDoubleValue());
|
||||
|
||||
}
|
||||
|
||||
public void testConfigureNullValue() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("stringValue", null);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNull(bean.getStringValue());
|
||||
}
|
||||
|
||||
public void testConfigureSimple() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", "one");
|
||||
map.put("intValue", 2);
|
||||
map.put("doubleValue", .3);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals("one", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(.3, bean.getDoubleValue());
|
||||
}
|
||||
|
||||
public void testConfigureConvert() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String,Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", 1);
|
||||
map.put("intValue", "2");
|
||||
map.put("doubleValue", ".3");
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals("1", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(0.3, bean.getDoubleValue());
|
||||
}
|
||||
|
||||
public void testConfigureAmbiguous1() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
String value = "one";
|
||||
map.put("ambiguous", value);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
"one", bean.getAmbiguous());
|
||||
assertSame("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
}
|
||||
|
||||
public void testConfigureAmbiguous2() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
|
||||
Integer value = 2;
|
||||
map.put("ambiguous", value);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
2, bean.getAmbiguous());
|
||||
assertSame("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
}
|
||||
|
||||
public void testConfigureAmbiguous3() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Double> map = new HashMap<String, Double>();
|
||||
|
||||
Double value = .3;
|
||||
map.put("ambiguous", value);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value.getClass(), bean.getAmbiguous().getClass());
|
||||
assertSame("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
private String stringVal;
|
||||
private int intVal;
|
||||
private Double doubleVal;
|
||||
|
||||
private Object ambiguous;
|
||||
|
||||
public Double getDoubleValue() {
|
||||
return doubleVal;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intVal;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringVal;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setStringValue(String pString) {
|
||||
stringVal = pString;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setIntValue(int pInt) {
|
||||
intVal = pInt;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setDoubleValue(Double pDouble) {
|
||||
doubleVal = pDouble;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(String pString) {
|
||||
ambiguous = pString;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(Object pObject) {
|
||||
ambiguous = pObject;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(Integer pInteger) {
|
||||
ambiguous = pInteger;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(int pInt) {
|
||||
ambiguous = (long) pInt; // Just to differentiate...
|
||||
}
|
||||
|
||||
public Object getAmbiguous() {
|
||||
return ambiguous;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* BeanUtilTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/lang/BeanUtilTestCase.java#1 $
|
||||
*/
|
||||
public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void testConfigureNoMehtod() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put("noSuchMethod", "jaffa");
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureNoMethodArgs() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("doubleValue", new Object()); // Should not be able to convert this
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNull(bean.getDoubleValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureNullValue() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("stringValue", null);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNull(bean.getStringValue());
|
||||
}
|
||||
|
||||
public void testConfigureSimple() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", "one");
|
||||
map.put("intValue", 2);
|
||||
map.put("doubleValue", .3);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals("one", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(.3, bean.getDoubleValue(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureConvert() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String,Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", 1);
|
||||
map.put("intValue", "2");
|
||||
map.put("doubleValue", ".3");
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals("1", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(0.3, bean.getDoubleValue(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureAmbiguous1() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
String value = "one";
|
||||
map.put("ambiguous", value);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
"one", bean.getAmbiguous());
|
||||
assertSame("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureAmbiguous2() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
|
||||
Integer value = 2;
|
||||
map.put("ambiguous", value);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
2, bean.getAmbiguous());
|
||||
assertSame("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigureAmbiguous3() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map<String, Double> map = new HashMap<String, Double>();
|
||||
|
||||
Double value = .3;
|
||||
map.put("ambiguous", value);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value.getClass(), bean.getAmbiguous().getClass());
|
||||
assertSame("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
private String stringVal;
|
||||
private int intVal;
|
||||
private Double doubleVal;
|
||||
|
||||
private Object ambiguous;
|
||||
|
||||
public Double getDoubleValue() {
|
||||
return doubleVal;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intVal;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringVal;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setStringValue(String pString) {
|
||||
stringVal = pString;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setIntValue(int pInt) {
|
||||
intVal = pInt;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setDoubleValue(Double pDouble) {
|
||||
doubleVal = pDouble;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(String pString) {
|
||||
ambiguous = pString;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(Object pObject) {
|
||||
ambiguous = pObject;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(Integer pInteger) {
|
||||
ambiguous = pInteger;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setAmbiguous(int pInt) {
|
||||
ambiguous = (long) pInt; // Just to differentiate...
|
||||
}
|
||||
|
||||
public Object getAmbiguous() {
|
||||
return ambiguous;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
+339
-309
@@ -1,309 +1,339 @@
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* AbstractObjectTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java#1 $
|
||||
*/
|
||||
public abstract class ObjectAbstractTestCase {
|
||||
// TODO: See com.tm.util.ObjectAbstractTestCase
|
||||
// TODO: The idea is that this should be some generic base-class that
|
||||
// implements the basic object tests
|
||||
|
||||
// TODO: Create Serializable test similar way
|
||||
// TODO: Create Comparable test similar way
|
||||
|
||||
/**
|
||||
* Returns an instance of the class we are testing.
|
||||
* Implement this method to return the object to test.
|
||||
*
|
||||
* @return the object to test
|
||||
*/
|
||||
protected abstract Object makeObject();
|
||||
|
||||
// TODO: Can we really do serious testing with just one object?
|
||||
// TODO: How can we make sure we create equal or different objects?!
|
||||
//protected abstract Object makeDifferentObject(Object pObject);
|
||||
//protected abstract Object makeEqualObject(Object pObject);
|
||||
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertNotNull(makeObject().toString());
|
||||
// TODO: What more can we test?
|
||||
}
|
||||
|
||||
// TODO: assert that either BOTH or NONE of equals/hashcode is overridden
|
||||
@Test
|
||||
public void testEqualsHashCode(){
|
||||
Object obj = makeObject();
|
||||
|
||||
Class cl = obj.getClass();
|
||||
if (isEqualsOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements equals but not hashCode", isHashCodeOverriden(cl));
|
||||
}
|
||||
else if (isHashCodeOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements hashCode but not equals", isEqualsOverriden(cl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static boolean isEqualsOverriden(Class pClass) {
|
||||
return getDeclaredMethod(pClass, "equals", new Class[]{Object.class}) != null;
|
||||
}
|
||||
|
||||
protected static boolean isHashCodeOverriden(Class pClass) {
|
||||
return getDeclaredMethod(pClass, "hashCode", null) != null;
|
||||
}
|
||||
|
||||
private static Method getDeclaredMethod(Class pClass, String pName, Class[] pArameters) {
|
||||
try {
|
||||
return pClass.getDeclaredMethod(pName, pArameters);
|
||||
}
|
||||
catch (NoSuchMethodException ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("An Object should equal itself", obj, obj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsNull() {
|
||||
Object obj = makeObject();
|
||||
// NOTE: Makes sure this doesn't throw NPE either
|
||||
//noinspection ObjectEqualsNull
|
||||
assertFalse("An object should never equal null", obj.equals(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
}
|
||||
// TODO: Make sure we create at least one equal object, and one different object
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void testFinalize() {
|
||||
// TODO: Implement
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Cloneable interface
|
||||
@Test
|
||||
public void testClone() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Cloneable) {
|
||||
Class cl = obj.getClass();
|
||||
|
||||
Method clone = findMethod(cl, "clone");
|
||||
|
||||
// Disregard protected modifier
|
||||
// NOTE: This will throw a SecurityException if a SecurityManager
|
||||
// disallows access, but should not happen in a test context
|
||||
if (!clone.isAccessible()) {
|
||||
clone.setAccessible(true);
|
||||
}
|
||||
|
||||
Object cloned = clone.invoke(obj);
|
||||
|
||||
assertNotNull("Cloned object should never be null", cloned);
|
||||
|
||||
// TODO: This can only be asserted if equals() test is based on
|
||||
// value equality, not reference (identity) equality
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isHashCodeOverriden(cl)) {
|
||||
assertEquals("Cloned object not equal", obj, cloned);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Method findMethod(Class pClass, String pName) throws NoSuchMethodException {
|
||||
if (pClass == null) {
|
||||
throw new IllegalArgumentException("class == null");
|
||||
}
|
||||
if (pName == null) {
|
||||
throw new IllegalArgumentException("name == null");
|
||||
}
|
||||
|
||||
Class cl = pClass;
|
||||
|
||||
while (cl != null) {
|
||||
try {
|
||||
return cl.getDeclaredMethod(pName, new Class[0]);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
}
|
||||
|
||||
cl = cl.getSuperclass();
|
||||
}
|
||||
|
||||
throw new NoSuchMethodException(pName + " in class " + pClass.getName());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Serializable interface
|
||||
@Test
|
||||
public void testSerializeDeserializeThenCompare() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Serializable) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
||||
try {
|
||||
out.writeObject(obj);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
Object dest;
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
try {
|
||||
dest = in.readObject();
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
|
||||
// TODO: This can only be asserted if equals() test is based on
|
||||
// value equality, not reference (identity) equality
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isEqualsOverriden(obj.getClass())) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check method, makes sure that any {@code Serializable}
|
||||
* class can be serialized and de-serialized in memory,
|
||||
* using the handy makeObject() method
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@Test
|
||||
public void testSimpleSerialization() throws Exception {
|
||||
Object o = makeObject();
|
||||
if (o instanceof Serializable) {
|
||||
byte[] object = writeExternalFormToBytes((Serializable) o);
|
||||
readExternalFormFromBytes(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a Serializable or Externalizable object as
|
||||
* a file at the given path.
|
||||
* <em>NOT USEFUL as part
|
||||
* of a unit test; this is just a utility method
|
||||
* for creating disk-based objects in CVS that can become
|
||||
* the basis for compatibility tests using
|
||||
* readExternalFormFromDisk(String path)</em>
|
||||
*
|
||||
* @param o Object to serialize
|
||||
* @param path path to write the serialized Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected void writeExternalFormToDisk(Serializable o, String path) throws IOException {
|
||||
FileOutputStream fileStream = new FileOutputStream(path);
|
||||
writeExternalFormToStream(o, fileStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Serializable or Externalizable object to
|
||||
* bytes. Useful for in-memory tests of serialization
|
||||
*
|
||||
* @param o Object to convert to bytes
|
||||
* @return serialized form of the Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected byte[] writeExternalFormToBytes(Serializable o) throws IOException {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
writeExternalFormToStream(o, byteStream);
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Serialized or Externalized Object from disk.
|
||||
* Useful for creating compatibility tests between
|
||||
* different CVS versions of the same class
|
||||
*
|
||||
* @param path path to the serialized Object
|
||||
* @return the Object at the given path
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromDisk(String path) throws IOException, ClassNotFoundException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a Serialized or Externalized Object from bytes.
|
||||
* Useful for verifying serialization in memory.
|
||||
*
|
||||
* @param b byte array containing a serialized Object
|
||||
* @return Object contained in the bytes
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromBytes(byte[] b) throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(b);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
// private implementation
|
||||
//-----------------------------------------------------------------------
|
||||
private Object readExternalFormFromStream(InputStream stream) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream oStream = new ObjectInputStream(stream);
|
||||
return oStream.readObject();
|
||||
}
|
||||
|
||||
private void writeExternalFormToStream(Serializable o, OutputStream stream) throws IOException {
|
||||
ObjectOutputStream oStream = new ObjectOutputStream(stream);
|
||||
oStream.writeObject(o);
|
||||
}
|
||||
|
||||
public static final class SanityTestTestCase extends ObjectAbstractTestCase {
|
||||
protected Object makeObject() {
|
||||
return new Cloneable() {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* AbstractObjectTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/lang/ObjectAbstractTestCase.java#1 $
|
||||
*/
|
||||
public abstract class ObjectAbstractTest {
|
||||
// TODO: See com.tm.util.ObjectAbstractTestCase
|
||||
// TODO: The idea is that this should be some generic base-class that
|
||||
// implements the basic object tests
|
||||
|
||||
// TODO: Create Serializable test similar way
|
||||
// TODO: Create Comparable test similar way
|
||||
|
||||
/**
|
||||
* Returns an instance of the class we are testing.
|
||||
* Implement this method to return the object to test.
|
||||
*
|
||||
* @return the object to test
|
||||
*/
|
||||
protected abstract Object makeObject();
|
||||
|
||||
// TODO: Can we really do serious testing with just one object?
|
||||
// TODO: How can we make sure we create equal or different objects?!
|
||||
//protected abstract Object makeDifferentObject(Object pObject);
|
||||
//protected abstract Object makeEqualObject(Object pObject);
|
||||
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertNotNull(makeObject().toString());
|
||||
// TODO: What more can we test?
|
||||
}
|
||||
|
||||
// TODO: assert that either BOTH or NONE of equals/hashcode is overridden
|
||||
@Test
|
||||
public void testEqualsHashCode(){
|
||||
Object obj = makeObject();
|
||||
|
||||
Class cl = obj.getClass();
|
||||
if (isEqualsOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements equals but not hashCode", isHashCodeOverriden(cl));
|
||||
}
|
||||
else if (isHashCodeOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements hashCode but not equals", isEqualsOverriden(cl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static boolean isEqualsOverriden(Class pClass) {
|
||||
return getDeclaredMethod(pClass, "equals", new Class[]{Object.class}) != null;
|
||||
}
|
||||
|
||||
protected static boolean isHashCodeOverriden(Class pClass) {
|
||||
return getDeclaredMethod(pClass, "hashCode", null) != null;
|
||||
}
|
||||
|
||||
private static Method getDeclaredMethod(Class pClass, String pName, Class[] pArameters) {
|
||||
try {
|
||||
return pClass.getDeclaredMethod(pName, pArameters);
|
||||
}
|
||||
catch (NoSuchMethodException ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("An Object should equal itself", obj, obj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsNull() {
|
||||
Object obj = makeObject();
|
||||
// NOTE: Makes sure this doesn't throw NPE either
|
||||
//noinspection ObjectEqualsNull
|
||||
assertFalse("An object should never equal null", obj.equals(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
}
|
||||
// TODO: Make sure we create at least one equal object, and one different object
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void testFinalize() {
|
||||
// TODO: Implement
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Cloneable interface
|
||||
@Test
|
||||
public void testClone() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Cloneable) {
|
||||
Class cl = obj.getClass();
|
||||
|
||||
Method clone = findMethod(cl, "clone");
|
||||
|
||||
// Disregard protected modifier
|
||||
// NOTE: This will throw a SecurityException if a SecurityManager
|
||||
// disallows access, but should not happen in a test context
|
||||
if (!clone.isAccessible()) {
|
||||
clone.setAccessible(true);
|
||||
}
|
||||
|
||||
Object cloned = clone.invoke(obj);
|
||||
|
||||
assertNotNull("Cloned object should never be null", cloned);
|
||||
|
||||
// TODO: This can only be asserted if equals() test is based on
|
||||
// value equality, not reference (identity) equality
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isHashCodeOverriden(cl)) {
|
||||
assertEquals("Cloned object not equal", obj, cloned);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Method findMethod(Class pClass, String pName) throws NoSuchMethodException {
|
||||
if (pClass == null) {
|
||||
throw new IllegalArgumentException("class == null");
|
||||
}
|
||||
if (pName == null) {
|
||||
throw new IllegalArgumentException("name == null");
|
||||
}
|
||||
|
||||
Class cl = pClass;
|
||||
|
||||
while (cl != null) {
|
||||
try {
|
||||
return cl.getDeclaredMethod(pName, new Class[0]);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
}
|
||||
|
||||
cl = cl.getSuperclass();
|
||||
}
|
||||
|
||||
throw new NoSuchMethodException(pName + " in class " + pClass.getName());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Serializable interface
|
||||
@Test
|
||||
public void testSerializeDeserializeThenCompare() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Serializable) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
||||
try {
|
||||
out.writeObject(obj);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
Object dest;
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
try {
|
||||
dest = in.readObject();
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
|
||||
// TODO: This can only be asserted if equals() test is based on
|
||||
// value equality, not reference (identity) equality
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isEqualsOverriden(obj.getClass())) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check method, makes sure that any {@code Serializable}
|
||||
* class can be serialized and de-serialized in memory,
|
||||
* using the handy makeObject() method
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@Test
|
||||
public void testSimpleSerialization() throws Exception {
|
||||
Object o = makeObject();
|
||||
if (o instanceof Serializable) {
|
||||
byte[] object = writeExternalFormToBytes((Serializable) o);
|
||||
readExternalFormFromBytes(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a Serializable or Externalizable object as
|
||||
* a file at the given path.
|
||||
* <em>NOT USEFUL as part
|
||||
* of a unit test; this is just a utility method
|
||||
* for creating disk-based objects in CVS that can become
|
||||
* the basis for compatibility tests using
|
||||
* readExternalFormFromDisk(String path)</em>
|
||||
*
|
||||
* @param o Object to serialize
|
||||
* @param path path to write the serialized Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected void writeExternalFormToDisk(Serializable o, String path) throws IOException {
|
||||
FileOutputStream fileStream = new FileOutputStream(path);
|
||||
writeExternalFormToStream(o, fileStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Serializable or Externalizable object to
|
||||
* bytes. Useful for in-memory tests of serialization
|
||||
*
|
||||
* @param o Object to convert to bytes
|
||||
* @return serialized form of the Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected byte[] writeExternalFormToBytes(Serializable o) throws IOException {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
writeExternalFormToStream(o, byteStream);
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Serialized or Externalized Object from disk.
|
||||
* Useful for creating compatibility tests between
|
||||
* different CVS versions of the same class
|
||||
*
|
||||
* @param path path to the serialized Object
|
||||
* @return the Object at the given path
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromDisk(String path) throws IOException, ClassNotFoundException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a Serialized or Externalized Object from bytes.
|
||||
* Useful for verifying serialization in memory.
|
||||
*
|
||||
* @param b byte array containing a serialized Object
|
||||
* @return Object contained in the bytes
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromBytes(byte[] b) throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(b);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
// private implementation
|
||||
//-----------------------------------------------------------------------
|
||||
private Object readExternalFormFromStream(InputStream stream) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream oStream = new ObjectInputStream(stream);
|
||||
return oStream.readObject();
|
||||
}
|
||||
|
||||
private void writeExternalFormToStream(Serializable o, OutputStream stream) throws IOException {
|
||||
ObjectOutputStream oStream = new ObjectOutputStream(stream);
|
||||
oStream.writeObject(o);
|
||||
}
|
||||
|
||||
public static final class SanityTestTest extends ObjectAbstractTest {
|
||||
protected Object makeObject() {
|
||||
return new Cloneable() {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
@@ -33,7 +35,8 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* PlatformTest
|
||||
|
||||
+947
-858
File diff suppressed because it is too large
Load Diff
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
+176
-146
@@ -1,146 +1,176 @@
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* BeanMapTestCase
|
||||
* <p/>
|
||||
* @todo Extend with BeanMap specific tests
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/BeanMapTestCase.java#2 $
|
||||
*/
|
||||
public class BeanMapTestCase extends MapAbstractTestCase {
|
||||
|
||||
public boolean isPutAddSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRemoveSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSetValueSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAllowNullKey() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object[] getSampleKeys() {
|
||||
return new Object[] {
|
||||
"blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee"
|
||||
};
|
||||
}
|
||||
|
||||
public Object[] getSampleValues() {
|
||||
return new Object[] {
|
||||
"blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev"
|
||||
};
|
||||
}
|
||||
|
||||
public Object[] getNewSampleValues() {
|
||||
return new Object[] {
|
||||
"newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv", "newgollyv", "newgeev"
|
||||
};
|
||||
}
|
||||
|
||||
public Map makeEmptyMap() {
|
||||
try {
|
||||
return new BeanMap(new NullBean());
|
||||
}
|
||||
catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Map makeFullMap() {
|
||||
try {
|
||||
return new BeanMap(new MyBean());
|
||||
}
|
||||
catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyBean implements Serializable {
|
||||
Object blah = "blahv";
|
||||
Object foo = "foov";
|
||||
Object bar = "barv";
|
||||
Object baz = "bazv";
|
||||
Object tmp = "tmpv";
|
||||
Object gosh = "goshv";
|
||||
Object golly = "gollyv";
|
||||
Object gee = "geev";
|
||||
|
||||
public Object getBar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
public void setBar(Object pBar) {
|
||||
bar = pBar;
|
||||
}
|
||||
|
||||
public Object getBaz() {
|
||||
return baz;
|
||||
}
|
||||
|
||||
public void setBaz(Object pBaz) {
|
||||
baz = pBaz;
|
||||
}
|
||||
|
||||
public Object getBlah() {
|
||||
return blah;
|
||||
}
|
||||
|
||||
public void setBlah(Object pBlah) {
|
||||
blah = pBlah;
|
||||
}
|
||||
|
||||
public Object getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(Object pFoo) {
|
||||
foo = pFoo;
|
||||
}
|
||||
|
||||
public Object getGee() {
|
||||
return gee;
|
||||
}
|
||||
|
||||
public void setGee(Object pGee) {
|
||||
gee = pGee;
|
||||
}
|
||||
|
||||
public Object getGolly() {
|
||||
return golly;
|
||||
}
|
||||
|
||||
public void setGolly(Object pGolly) {
|
||||
golly = pGolly;
|
||||
}
|
||||
|
||||
public Object getGosh() {
|
||||
return gosh;
|
||||
}
|
||||
|
||||
public void setGosh(Object pGosh) {
|
||||
gosh = pGosh;
|
||||
}
|
||||
|
||||
public Object getTmp() {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void setTmp(Object pTmp) {
|
||||
tmp = pTmp;
|
||||
}
|
||||
}
|
||||
|
||||
static class NullBean implements Serializable { }
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* BeanMapTestCase
|
||||
* <p/>
|
||||
* @todo Extend with BeanMap specific tests
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/BeanMapTestCase.java#2 $
|
||||
*/
|
||||
public class BeanMapTest extends MapAbstractTest {
|
||||
|
||||
public boolean isPutAddSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRemoveSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSetValueSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAllowNullKey() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object[] getSampleKeys() {
|
||||
return new Object[] {
|
||||
"blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee"
|
||||
};
|
||||
}
|
||||
|
||||
public Object[] getSampleValues() {
|
||||
return new Object[] {
|
||||
"blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev"
|
||||
};
|
||||
}
|
||||
|
||||
public Object[] getNewSampleValues() {
|
||||
return new Object[] {
|
||||
"newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv", "newgollyv", "newgeev"
|
||||
};
|
||||
}
|
||||
|
||||
public Map makeEmptyMap() {
|
||||
try {
|
||||
return new BeanMap(new NullBean());
|
||||
}
|
||||
catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Map makeFullMap() {
|
||||
try {
|
||||
return new BeanMap(new MyBean());
|
||||
}
|
||||
catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyBean implements Serializable {
|
||||
Object blah = "blahv";
|
||||
Object foo = "foov";
|
||||
Object bar = "barv";
|
||||
Object baz = "bazv";
|
||||
Object tmp = "tmpv";
|
||||
Object gosh = "goshv";
|
||||
Object golly = "gollyv";
|
||||
Object gee = "geev";
|
||||
|
||||
public Object getBar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
public void setBar(Object pBar) {
|
||||
bar = pBar;
|
||||
}
|
||||
|
||||
public Object getBaz() {
|
||||
return baz;
|
||||
}
|
||||
|
||||
public void setBaz(Object pBaz) {
|
||||
baz = pBaz;
|
||||
}
|
||||
|
||||
public Object getBlah() {
|
||||
return blah;
|
||||
}
|
||||
|
||||
public void setBlah(Object pBlah) {
|
||||
blah = pBlah;
|
||||
}
|
||||
|
||||
public Object getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(Object pFoo) {
|
||||
foo = pFoo;
|
||||
}
|
||||
|
||||
public Object getGee() {
|
||||
return gee;
|
||||
}
|
||||
|
||||
public void setGee(Object pGee) {
|
||||
gee = pGee;
|
||||
}
|
||||
|
||||
public Object getGolly() {
|
||||
return golly;
|
||||
}
|
||||
|
||||
public void setGolly(Object pGolly) {
|
||||
golly = pGolly;
|
||||
}
|
||||
|
||||
public Object getGosh() {
|
||||
return gosh;
|
||||
}
|
||||
|
||||
public void setGosh(Object pGosh) {
|
||||
gosh = pGosh;
|
||||
}
|
||||
|
||||
public Object getTmp() {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void setTmp(Object pTmp) {
|
||||
tmp = pTmp;
|
||||
}
|
||||
}
|
||||
|
||||
static class NullBean implements Serializable { }
|
||||
}
|
||||
+1359
-1308
File diff suppressed because it is too large
Load Diff
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
@@ -34,7 +36,6 @@ import org.junit.Test;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* CollectionUtilTest
|
||||
|
||||
+221
-181
@@ -1,181 +1,221 @@
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Tests LRUMap.
|
||||
*
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author James Strachan
|
||||
* @author Morgan Delagrange
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
|
||||
public boolean isGetStructuralModify() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Map makeEmptyMap() {
|
||||
return new LRUMap();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testRemoveLRU() {
|
||||
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"));
|
||||
assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null);
|
||||
}
|
||||
|
||||
public void testMultiplePuts() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that putAll(Map) does not cause the LRUMap
|
||||
* to exceed its maxiumum size.
|
||||
*/
|
||||
public void testPutAll() {
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"foo");
|
||||
map2.put(3,"foo");
|
||||
|
||||
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
|
||||
hashMap.put(4,"foo");
|
||||
|
||||
map2.putAll(hashMap);
|
||||
|
||||
assertTrue("max size is 3, but actual size is " + map2.size(),
|
||||
map2.size() == 3);
|
||||
assertTrue("map should contain the Integer(4) object",
|
||||
map2.containsKey(new Integer(4)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the size of the map is reduced immediately
|
||||
* when setMaximumSize(int) is called
|
||||
*/
|
||||
public void testSetMaximumSize() {
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(6);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
map.put("4","4");
|
||||
map.put("5","5");
|
||||
map.put("6","6");
|
||||
map.setMaxSize(3);
|
||||
|
||||
assertTrue("map should have size = 3, but actually = " + map.size(),
|
||||
map.size() == 3);
|
||||
}
|
||||
|
||||
public void testGetPromotion() {
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(3);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
// LRU is now 1 (then 2 then 3)
|
||||
|
||||
// promote 1 to top
|
||||
// eviction order is now 2,3,1
|
||||
map.get("1");
|
||||
|
||||
// add another value, forcing a remove
|
||||
// 2 should be evicted (then 3,1,4)
|
||||
map.put("4","4");
|
||||
|
||||
Iterator<String> keyIterator = map.keySet().iterator();
|
||||
Object[] keys = new Object[3];
|
||||
for (int i = 0; keyIterator.hasNext() ; ++i) {
|
||||
keys[i] = keyIterator.next();
|
||||
}
|
||||
|
||||
assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3"));
|
||||
assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1"));
|
||||
assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* You should be able to subclass LRUMap and perform a
|
||||
* custom action when items are removed automatically
|
||||
* by the LRU algorithm (the removeLRU() method).
|
||||
*/
|
||||
public void testLRUSubclass() {
|
||||
LRUCounter<String, String> counter = new LRUCounter<String, String>(3);
|
||||
// oldest <--> newest
|
||||
// 1
|
||||
counter.put("1","foo");
|
||||
// 1 2
|
||||
counter.put("2","foo");
|
||||
// 1 2 3
|
||||
counter.put("3","foo");
|
||||
// 2 3 1
|
||||
counter.put("1","foo");
|
||||
// 3 1 4 (2 goes out)
|
||||
counter.put("4","foo");
|
||||
// 1 4 5 (3 goes out)
|
||||
counter.put("5","foo");
|
||||
// 4 5 2 (1 goes out)
|
||||
counter.put("2","foo");
|
||||
// 4 2
|
||||
counter.remove("5");
|
||||
|
||||
assertTrue("size should be 2, but was " + counter.size(), counter.size() == 2);
|
||||
assertTrue("removedCount should be 3 but was " + counter.removedCount,
|
||||
counter.removedCount == 3);
|
||||
|
||||
assertTrue("first removed was '2'",counter.list.get(0).equals("2"));
|
||||
assertTrue("second removed was '3'",counter.list.get(1).equals("3"));
|
||||
assertTrue("third removed was '1'",counter.list.get(2).equals("1"));
|
||||
|
||||
//assertTrue("oldest key is '4'",counter.get(0).equals("4"));
|
||||
//assertTrue("newest key is '2'",counter.get(1).equals("2"));
|
||||
}
|
||||
|
||||
private class LRUCounter<K, V> extends LRUMap<K, V> {
|
||||
int removedCount = 0;
|
||||
List<Object> list = new ArrayList<Object>(3);
|
||||
|
||||
LRUCounter(int i) {
|
||||
super(i);
|
||||
}
|
||||
|
||||
public void processRemoved(Entry pEntry) {
|
||||
++removedCount;
|
||||
list.add(pEntry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests LRUMap.
|
||||
*
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author James Strachan
|
||||
* @author Morgan Delagrange
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class LRUMapTest extends LinkedMapTest {
|
||||
|
||||
public boolean isGetStructuralModify() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Map makeEmptyMap() {
|
||||
return new LRUMap();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testRemoveLRU() {
|
||||
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"));
|
||||
assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplePuts() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that putAll(Map) does not cause the LRUMap
|
||||
* to exceed its maxiumum size.
|
||||
*/
|
||||
@Test
|
||||
public void testPutAll() {
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"foo");
|
||||
map2.put(3,"foo");
|
||||
|
||||
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
|
||||
hashMap.put(4,"foo");
|
||||
|
||||
map2.putAll(hashMap);
|
||||
|
||||
assertTrue("max size is 3, but actual size is " + map2.size(),
|
||||
map2.size() == 3);
|
||||
assertTrue("map should contain the Integer(4) object",
|
||||
map2.containsKey(new Integer(4)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the size of the map is reduced immediately
|
||||
* when setMaximumSize(int) is called
|
||||
*/
|
||||
@Test
|
||||
public void testSetMaximumSize() {
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(6);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
map.put("4","4");
|
||||
map.put("5","5");
|
||||
map.put("6","6");
|
||||
map.setMaxSize(3);
|
||||
|
||||
assertTrue("map should have size = 3, but actually = " + map.size(),
|
||||
map.size() == 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPromotion() {
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(3);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
// LRU is now 1 (then 2 then 3)
|
||||
|
||||
// promote 1 to top
|
||||
// eviction order is now 2,3,1
|
||||
map.get("1");
|
||||
|
||||
// add another value, forcing a remove
|
||||
// 2 should be evicted (then 3,1,4)
|
||||
map.put("4","4");
|
||||
|
||||
Iterator<String> keyIterator = map.keySet().iterator();
|
||||
Object[] keys = new Object[3];
|
||||
for (int i = 0; keyIterator.hasNext() ; ++i) {
|
||||
keys[i] = keyIterator.next();
|
||||
}
|
||||
|
||||
assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3"));
|
||||
assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1"));
|
||||
assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* You should be able to subclass LRUMap and perform a
|
||||
* custom action when items are removed automatically
|
||||
* by the LRU algorithm (the removeLRU() method).
|
||||
*/
|
||||
@Test
|
||||
public void testLRUSubclass() {
|
||||
LRUCounter<String, String> counter = new LRUCounter<String, String>(3);
|
||||
// oldest <--> newest
|
||||
// 1
|
||||
counter.put("1","foo");
|
||||
// 1 2
|
||||
counter.put("2","foo");
|
||||
// 1 2 3
|
||||
counter.put("3","foo");
|
||||
// 2 3 1
|
||||
counter.put("1","foo");
|
||||
// 3 1 4 (2 goes out)
|
||||
counter.put("4","foo");
|
||||
// 1 4 5 (3 goes out)
|
||||
counter.put("5","foo");
|
||||
// 4 5 2 (1 goes out)
|
||||
counter.put("2","foo");
|
||||
// 4 2
|
||||
counter.remove("5");
|
||||
|
||||
assertTrue("size should be 2, but was " + counter.size(), counter.size() == 2);
|
||||
assertTrue("removedCount should be 3 but was " + counter.removedCount,
|
||||
counter.removedCount == 3);
|
||||
|
||||
assertTrue("first removed was '2'",counter.list.get(0).equals("2"));
|
||||
assertTrue("second removed was '3'",counter.list.get(1).equals("3"));
|
||||
assertTrue("third removed was '1'",counter.list.get(2).equals("1"));
|
||||
|
||||
//assertTrue("oldest key is '4'",counter.get(0).equals("4"));
|
||||
//assertTrue("newest key is '2'",counter.get(1).equals("2"));
|
||||
}
|
||||
|
||||
private class LRUCounter<K, V> extends LRUMap<K, V> {
|
||||
int removedCount = 0;
|
||||
List<Object> list = new ArrayList<Object>(3);
|
||||
|
||||
LRUCounter(int i) {
|
||||
super(i);
|
||||
}
|
||||
|
||||
public void processRemoved(Entry pEntry) {
|
||||
++removedCount;
|
||||
list.add(pEntry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+214
-175
@@ -1,175 +1,214 @@
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Unit tests
|
||||
* {@link org.apache.commons.collections.SequencedHashMap}.
|
||||
* Be sure to use the "labRat" instance whenever possible,
|
||||
* so that subclasses will be tested correctly.
|
||||
*
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author Morgan Delagrange
|
||||
* @author Daniel Rall
|
||||
* @author Henning P. Schmiedehausen
|
||||
* @author James Strachan
|
||||
*/
|
||||
public class LinkedMapTestCase extends MapAbstractTestCase {
|
||||
/**
|
||||
* The instance to experiment on.
|
||||
*/
|
||||
protected LinkedMap labRat;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// use makeMap and cast the result to a SeqHashMap
|
||||
// so that subclasses of SeqHashMap can share these tests
|
||||
labRat = (LinkedMap) makeEmptyMap();
|
||||
}
|
||||
|
||||
public Map makeEmptyMap() {
|
||||
return new LinkedMap();
|
||||
}
|
||||
|
||||
protected Object[] getKeys() {
|
||||
return new Object[] { "foo", "baz", "eek" };
|
||||
}
|
||||
|
||||
protected Object[] getValues() {
|
||||
return new Object[] { "bar", "frob", new Object() };
|
||||
}
|
||||
|
||||
public void testSequenceMap() throws Throwable {
|
||||
Object[] keys = getKeys();
|
||||
int expectedSize = keys.length;
|
||||
Object[] values = getValues();
|
||||
for (int i = 0; i < expectedSize; i++) {
|
||||
labRat.put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
// Test size().
|
||||
assertEquals("size() does not match expected size",
|
||||
expectedSize, labRat.size());
|
||||
|
||||
// Test clone(), iterator(), and get(Object).
|
||||
LinkedMap clone = (LinkedMap) labRat.clone();
|
||||
assertEquals("Size of clone does not match original",
|
||||
labRat.size(), clone.size());
|
||||
Iterator origEntries = labRat.entrySet().iterator();
|
||||
Iterator copiedEntries = clone.entrySet().iterator();
|
||||
while (origEntries.hasNext()) {
|
||||
Map.Entry origEntry = (Map.Entry)origEntries.next();
|
||||
Map.Entry copiedEntry = (Map.Entry)copiedEntries.next();
|
||||
assertEquals("Cloned key does not match original",
|
||||
origEntry.getKey(), copiedEntry.getKey());
|
||||
assertEquals("Cloned value does not match original",
|
||||
origEntry.getValue(), copiedEntry.getValue());
|
||||
assertEquals("Cloned entry does not match original",
|
||||
origEntry, copiedEntry);
|
||||
}
|
||||
assertTrue("iterator() returned different number of elements than keys()",
|
||||
!copiedEntries.hasNext());
|
||||
|
||||
// Test sequence()
|
||||
/*
|
||||
List seq = labRat.sequence();
|
||||
assertEquals("sequence() returns more keys than in the Map",
|
||||
expectedSize, seq.size());
|
||||
|
||||
for (int i = 0; i < seq.size(); i++) {
|
||||
assertEquals("Key " + i + " is not the same as the key in the Map",
|
||||
keys[i], seq.get(i));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
public void testYoungest() {
|
||||
labRat.put(new Integer(1),"foo");
|
||||
labRat.put(new Integer(2),"bar");
|
||||
assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
|
||||
labRat.put(new Integer(1),"boo");
|
||||
assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
|
||||
}
|
||||
|
||||
public void testYoungestReplaceNullWithValue() {
|
||||
labRat.put(new Integer(1),null);
|
||||
labRat.put(new Integer(2),"foo");
|
||||
assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
|
||||
labRat.put(new Integer(1),"bar");
|
||||
assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
|
||||
}
|
||||
|
||||
public void testYoungestReplaceValueWithNull() {
|
||||
labRat.put(new Integer(1),"bar");
|
||||
labRat.put(new Integer(2),"foo");
|
||||
assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
|
||||
labRat.put(new Integer(1),null);
|
||||
assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
|
||||
}
|
||||
*/
|
||||
|
||||
// override TestMap method with more specific tests
|
||||
/*
|
||||
public void testFullMapSerialization()
|
||||
throws IOException, ClassNotFoundException {
|
||||
LinkedMap map = (LinkedMap) makeFullMap();
|
||||
|
||||
if (!(map instanceof Serializable)) return;
|
||||
|
||||
byte[] objekt = writeExternalFormToBytes((Serializable) map);
|
||||
LinkedMap map2 = (LinkedMap) readExternalFormFromBytes(objekt);
|
||||
|
||||
assertEquals("Both maps are same size",map.size(), getSampleKeys().length);
|
||||
assertEquals("Both maps are same size",map2.size(),getSampleKeys().length);
|
||||
|
||||
assertEquals("Both maps have the same first key",
|
||||
map.getFirstKey(),getSampleKeys()[0]);
|
||||
assertEquals("Both maps have the same first key",
|
||||
map2.getFirstKey(),getSampleKeys()[0]);
|
||||
assertEquals("Both maps have the same last key",
|
||||
map.getLastKey(),getSampleKeys()[getSampleKeys().length - 1]);
|
||||
assertEquals("Both maps have the same last key",
|
||||
map2.getLastKey(),getSampleKeys()[getSampleKeys().length - 1]);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public void testIndexOf() throws Exception {
|
||||
Object[] keys = getKeys();
|
||||
int expectedSize = keys.length;
|
||||
Object[] values = getValues();
|
||||
for (int i = 0; i < expectedSize; i++) {
|
||||
labRat.put(keys[i], values[i]);
|
||||
}
|
||||
// test that the index returned are in the same order that they were
|
||||
// placed in the map
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
assertEquals("indexOf with existing key failed", i, labRat.indexOf(keys[i]));
|
||||
}
|
||||
// test non existing key..
|
||||
assertEquals("test with non-existing key failed", -1, labRat.indexOf("NonExistingKey"));
|
||||
}
|
||||
*/
|
||||
public void tearDown() throws Exception {
|
||||
labRat = null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests
|
||||
* {@link org.apache.commons.collections.SequencedHashMap}.
|
||||
* Be sure to use the "labRat" instance whenever possible,
|
||||
* so that subclasses will be tested correctly.
|
||||
*
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author Morgan Delagrange
|
||||
* @author Daniel Rall
|
||||
* @author Henning P. Schmiedehausen
|
||||
* @author James Strachan
|
||||
*/
|
||||
public class LinkedMapTest extends MapAbstractTest {
|
||||
/**
|
||||
* The instance to experiment on.
|
||||
*/
|
||||
protected LinkedMap labRat;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// use makeMap and cast the result to a SeqHashMap
|
||||
// so that subclasses of SeqHashMap can share these tests
|
||||
labRat = (LinkedMap) makeEmptyMap();
|
||||
}
|
||||
|
||||
public Map makeEmptyMap() {
|
||||
return new LinkedMap();
|
||||
}
|
||||
|
||||
protected Object[] getKeys() {
|
||||
return new Object[] { "foo", "baz", "eek" };
|
||||
}
|
||||
|
||||
protected Object[] getValues() {
|
||||
return new Object[] { "bar", "frob", new Object() };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceMap() throws Throwable {
|
||||
Object[] keys = getKeys();
|
||||
int expectedSize = keys.length;
|
||||
Object[] values = getValues();
|
||||
for (int i = 0; i < expectedSize; i++) {
|
||||
labRat.put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
// Test size().
|
||||
assertEquals("size() does not match expected size",
|
||||
expectedSize, labRat.size());
|
||||
|
||||
// Test clone(), iterator(), and get(Object).
|
||||
LinkedMap clone = (LinkedMap) labRat.clone();
|
||||
assertEquals("Size of clone does not match original",
|
||||
labRat.size(), clone.size());
|
||||
Iterator origEntries = labRat.entrySet().iterator();
|
||||
Iterator copiedEntries = clone.entrySet().iterator();
|
||||
while (origEntries.hasNext()) {
|
||||
Map.Entry origEntry = (Map.Entry)origEntries.next();
|
||||
Map.Entry copiedEntry = (Map.Entry)copiedEntries.next();
|
||||
assertEquals("Cloned key does not match original",
|
||||
origEntry.getKey(), copiedEntry.getKey());
|
||||
assertEquals("Cloned value does not match original",
|
||||
origEntry.getValue(), copiedEntry.getValue());
|
||||
assertEquals("Cloned entry does not match original",
|
||||
origEntry, copiedEntry);
|
||||
}
|
||||
assertTrue("iterator() returned different number of elements than keys()",
|
||||
!copiedEntries.hasNext());
|
||||
|
||||
// Test sequence()
|
||||
/*
|
||||
List seq = labRat.sequence();
|
||||
assertEquals("sequence() returns more keys than in the Map",
|
||||
expectedSize, seq.size());
|
||||
|
||||
for (int i = 0; i < seq.size(); i++) {
|
||||
assertEquals("Key " + i + " is not the same as the key in the Map",
|
||||
keys[i], seq.get(i));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
public void testYoungest() {
|
||||
labRat.put(new Integer(1),"foo");
|
||||
labRat.put(new Integer(2),"bar");
|
||||
assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
|
||||
labRat.put(new Integer(1),"boo");
|
||||
assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
|
||||
}
|
||||
|
||||
public void testYoungestReplaceNullWithValue() {
|
||||
labRat.put(new Integer(1),null);
|
||||
labRat.put(new Integer(2),"foo");
|
||||
assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
|
||||
labRat.put(new Integer(1),"bar");
|
||||
assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
|
||||
}
|
||||
|
||||
public void testYoungestReplaceValueWithNull() {
|
||||
labRat.put(new Integer(1),"bar");
|
||||
labRat.put(new Integer(2),"foo");
|
||||
assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
|
||||
labRat.put(new Integer(1),null);
|
||||
assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
|
||||
}
|
||||
*/
|
||||
|
||||
// override TestMap method with more specific tests
|
||||
/*
|
||||
public void testFullMapSerialization()
|
||||
throws IOException, ClassNotFoundException {
|
||||
LinkedMap map = (LinkedMap) makeFullMap();
|
||||
|
||||
if (!(map instanceof Serializable)) return;
|
||||
|
||||
byte[] objekt = writeExternalFormToBytes((Serializable) map);
|
||||
LinkedMap map2 = (LinkedMap) readExternalFormFromBytes(objekt);
|
||||
|
||||
assertEquals("Both maps are same size",map.size(), getSampleKeys().length);
|
||||
assertEquals("Both maps are same size",map2.size(),getSampleKeys().length);
|
||||
|
||||
assertEquals("Both maps have the same first key",
|
||||
map.getFirstKey(),getSampleKeys()[0]);
|
||||
assertEquals("Both maps have the same first key",
|
||||
map2.getFirstKey(),getSampleKeys()[0]);
|
||||
assertEquals("Both maps have the same last key",
|
||||
map.getLastKey(),getSampleKeys()[getSampleKeys().length - 1]);
|
||||
assertEquals("Both maps have the same last key",
|
||||
map2.getLastKey(),getSampleKeys()[getSampleKeys().length - 1]);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public void testIndexOf() throws Exception {
|
||||
Object[] keys = getKeys();
|
||||
int expectedSize = keys.length;
|
||||
Object[] values = getValues();
|
||||
for (int i = 0; i < expectedSize; i++) {
|
||||
labRat.put(keys[i], values[i]);
|
||||
}
|
||||
// test that the index returned are in the same order that they were
|
||||
// placed in the map
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
assertEquals("indexOf with existing key failed", i, labRat.indexOf(keys[i]));
|
||||
}
|
||||
// test non existing key..
|
||||
assertEquals("test with non-existing key failed", -1, labRat.indexOf("NonExistingKey"));
|
||||
}
|
||||
*/
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
labRat = null;
|
||||
}
|
||||
}
|
||||
+1714
-1648
File diff suppressed because it is too large
Load Diff
+260
-187
@@ -1,187 +1,260 @@
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* NOTE: This TestCase is written especially for NullMap, and is full of dirty
|
||||
* tricks. A good indication that NullMap is not a good, general-purpose Map
|
||||
* implementation...
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/NullMapTestCase.java#2 $
|
||||
*/
|
||||
public class NullMapTestCase extends MapAbstractTestCase {
|
||||
private boolean empty = true;
|
||||
|
||||
public Map makeEmptyMap() {
|
||||
return new NullMap();
|
||||
}
|
||||
|
||||
public Map makeFullMap() {
|
||||
return new NullMap();
|
||||
}
|
||||
|
||||
public Map makeConfirmedMap() {
|
||||
// Always empty
|
||||
return new HashMap();
|
||||
}
|
||||
|
||||
public void resetEmpty() {
|
||||
empty = true;
|
||||
super.resetEmpty();
|
||||
}
|
||||
|
||||
public void resetFull() {
|
||||
empty = false;
|
||||
super.resetFull();
|
||||
}
|
||||
|
||||
public void verifyAll() {
|
||||
if (empty) {
|
||||
super.verifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
// Overriden, as this map is always empty
|
||||
public void testMapIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.isEmpty() should return true with an empty map",
|
||||
true, map.isEmpty());
|
||||
verifyAll();
|
||||
resetFull();
|
||||
assertEquals("Map.isEmpty() should return true with a full map",
|
||||
true, map.isEmpty());
|
||||
}
|
||||
|
||||
// Overriden, as this map is always empty
|
||||
public void testMapSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.size() should be 0 with an empty map",
|
||||
0, map.size());
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.size() should equal the number of entries " +
|
||||
"in the map", 0, map.size());
|
||||
}
|
||||
|
||||
public void testMapContainsKey() {
|
||||
Object[] keys = getSampleKeys();
|
||||
|
||||
resetEmpty();
|
||||
for(int i = 0; i < keys.length; i++) {
|
||||
assertTrue("Map must not contain key when map is empty",
|
||||
!map.containsKey(keys[i]));
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
public void testMapContainsValue() {
|
||||
Object[] values = getSampleValues();
|
||||
|
||||
resetEmpty();
|
||||
for(int i = 0; i < values.length; i++) {
|
||||
assertTrue("Empty map must not contain value",
|
||||
!map.containsValue(values[i]));
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
public void testMapEquals() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps unequal.", map.equals(confirmed));
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
public void testMapHashCode() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps have different hashCodes.",
|
||||
map.hashCode() == confirmed.hashCode());
|
||||
}
|
||||
|
||||
public void testMapGet() {
|
||||
resetEmpty();
|
||||
|
||||
Object[] keys = getSampleKeys();
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
assertTrue("Empty map.get() should return null.",
|
||||
map.get(keys[i]) == null);
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
public void testMapPut() {
|
||||
resetEmpty();
|
||||
Object[] keys = getSampleKeys();
|
||||
Object[] values = getSampleValues();
|
||||
Object[] newValues = getNewSampleValues();
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object o = map.put(keys[i], values[i]);
|
||||
//confirmed.put(keys[i], values[i]);
|
||||
verifyAll();
|
||||
assertTrue("First map.put should return null", o == null);
|
||||
}
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
map.put(keys[i], newValues[i]);
|
||||
//confirmed.put(keys[i], newValues[i]);
|
||||
verifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void testMapToString() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty map toString() should not return null",
|
||||
map.toString() != null);
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
public void testMapPutAll() {
|
||||
// TODO: Find a menaingful way to test this
|
||||
}
|
||||
|
||||
public void testMapRemove() {
|
||||
resetEmpty();
|
||||
|
||||
Object[] keys = getSampleKeys();
|
||||
for(int i = 0; i < keys.length; i++) {
|
||||
Object o = map.remove(keys[i]);
|
||||
assertTrue("First map.remove should return null", o == null);
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testEntrySetClearChangesMap() {
|
||||
}
|
||||
|
||||
public void testKeySetClearChangesMap() {
|
||||
}
|
||||
|
||||
public void testKeySetRemoveChangesMap() {
|
||||
}
|
||||
|
||||
public void testValuesClearChangesMap() {
|
||||
}
|
||||
|
||||
public void testEntrySetContains1() {
|
||||
}
|
||||
|
||||
public void testEntrySetContains2() {
|
||||
}
|
||||
|
||||
public void testEntrySetContains3() {
|
||||
}
|
||||
|
||||
public void testEntrySetRemove1() {
|
||||
}
|
||||
|
||||
public void testEntrySetRemove2() {
|
||||
}
|
||||
|
||||
public void testEntrySetRemove3() {
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* NOTE: This TestCase is written especially for NullMap, and is full of dirty
|
||||
* tricks. A good indication that NullMap is not a good, general-purpose Map
|
||||
* implementation...
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/NullMapTestCase.java#2 $
|
||||
*/
|
||||
public class NullMapTest extends MapAbstractTest {
|
||||
private boolean empty = true;
|
||||
|
||||
public Map makeEmptyMap() {
|
||||
return new NullMap();
|
||||
}
|
||||
|
||||
public Map makeFullMap() {
|
||||
return new NullMap();
|
||||
}
|
||||
|
||||
public Map makeConfirmedMap() {
|
||||
// Always empty
|
||||
return new HashMap();
|
||||
}
|
||||
|
||||
public void resetEmpty() {
|
||||
empty = true;
|
||||
super.resetEmpty();
|
||||
}
|
||||
|
||||
public void resetFull() {
|
||||
empty = false;
|
||||
super.resetFull();
|
||||
}
|
||||
|
||||
public void verifyAll() {
|
||||
if (empty) {
|
||||
super.verifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
// Overriden, as this map is always empty
|
||||
@Test
|
||||
@Override
|
||||
public void testMapIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.isEmpty() should return true with an empty map",
|
||||
true, map.isEmpty());
|
||||
verifyAll();
|
||||
resetFull();
|
||||
assertEquals("Map.isEmpty() should return true with a full map",
|
||||
true, map.isEmpty());
|
||||
}
|
||||
|
||||
// Overriden, as this map is always empty
|
||||
@Test
|
||||
@Override
|
||||
public void testMapSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.size() should be 0 with an empty map",
|
||||
0, map.size());
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.size() should equal the number of entries " +
|
||||
"in the map", 0, map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapContainsKey() {
|
||||
Object[] keys = getSampleKeys();
|
||||
|
||||
resetEmpty();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must not contain key when map is empty", !map.containsKey(key));
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapContainsValue() {
|
||||
Object[] values = getSampleValues();
|
||||
|
||||
resetEmpty();
|
||||
for (Object value : values) {
|
||||
assertTrue("Empty map must not contain value", !map.containsValue(value));
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapEquals() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps unequal.", map.equals(confirmed));
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapHashCode() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps have different hashCodes.",
|
||||
map.hashCode() == confirmed.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapGet() {
|
||||
resetEmpty();
|
||||
|
||||
Object[] keys = getSampleKeys();
|
||||
|
||||
for (Object key : keys) {
|
||||
assertTrue("Empty map.get() should return null.", map.get(key) == null);
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapPut() {
|
||||
resetEmpty();
|
||||
Object[] keys = getSampleKeys();
|
||||
Object[] values = getSampleValues();
|
||||
Object[] newValues = getNewSampleValues();
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object o = map.put(keys[i], values[i]);
|
||||
//confirmed.put(keys[i], values[i]);
|
||||
verifyAll();
|
||||
assertTrue("First map.put should return null", o == null);
|
||||
}
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
map.put(keys[i], newValues[i]);
|
||||
//confirmed.put(keys[i], newValues[i]);
|
||||
verifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapToString() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty map toString() should not return null",
|
||||
map.toString() != null);
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapPutAll() {
|
||||
// TODO: Find a menaingful way to test this
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testMapRemove() {
|
||||
resetEmpty();
|
||||
|
||||
Object[] keys = getSampleKeys();
|
||||
for(int i = 0; i < keys.length; i++) {
|
||||
Object o = map.remove(keys[i]);
|
||||
assertTrue("First map.remove should return null", o == null);
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetClearChangesMap() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testKeySetClearChangesMap() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testKeySetRemoveChangesMap() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testValuesClearChangesMap() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetContains1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetContains2() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetContains3() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetRemove1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetRemove2() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEntrySetRemove3() {
|
||||
}
|
||||
}
|
||||
+347
-307
@@ -1,307 +1,347 @@
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Object} methods and contracts.
|
||||
* <p>
|
||||
* To use, simply extend this class, and implement
|
||||
* the {@link #makeObject()} method.
|
||||
* <p>
|
||||
* If your {@link Object} fails one of these tests by design,
|
||||
* you may still use this base set of cases. Simply override the
|
||||
* test case (method) your {@link Object} fails.
|
||||
*
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
* @author Stephen Colebourne
|
||||
* @author Anonymous
|
||||
*/
|
||||
public abstract class ObjectAbstractTestCase extends TestCase {
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Implement this method to return the object to test.
|
||||
*
|
||||
* @return the object to test
|
||||
*/
|
||||
public abstract Object makeObject();
|
||||
|
||||
/**
|
||||
* Override this method if a subclass is testing an object
|
||||
* that cannot serialize an "empty" Collection.
|
||||
* (e.g. Comparators have no contents)
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsEmptyCollections() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method if a subclass is testing an object
|
||||
* that cannot serialize a "full" Collection.
|
||||
* (e.g. Comparators have no contents)
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsFullCollections() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is serialization testing supported.
|
||||
* Default is true.
|
||||
*/
|
||||
public boolean isTestSerialization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to indicate that the collection supports equals() comparisons.
|
||||
* This implementation returns true;
|
||||
*/
|
||||
public boolean isEqualsCheckable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("A Object should equal itself", obj, obj);
|
||||
}
|
||||
|
||||
public void testEqualsNull() {
|
||||
Object obj = makeObject();
|
||||
assertEquals(false, obj.equals(null)); // make sure this doesn't throw NPE either
|
||||
}
|
||||
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
}
|
||||
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
}
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSerializeDeserializeThenCompare() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Serializable && isTestSerialization()) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
||||
out.writeObject(obj);
|
||||
out.close();
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
Object dest = in.readObject();
|
||||
in.close();
|
||||
if (isEqualsCheckable()) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check method, makes sure that any Serializable
|
||||
* class can be serialized and de-serialized in memory,
|
||||
* using the handy makeObject() method
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public void testSimpleSerialization() throws Exception {
|
||||
Object o = makeObject();
|
||||
if (o instanceof Serializable && isTestSerialization()) {
|
||||
byte[] objekt = writeExternalFormToBytes((Serializable) o);
|
||||
Object p = readExternalFormFromBytes(objekt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests serialization by comparing against a previously stored version in CVS.
|
||||
* If the test object is serializable, confirm that a canonical form exists.
|
||||
*/
|
||||
public void testCanonicalEmptyCollectionExists() {
|
||||
if (supportsEmptyCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
|
||||
Object object = makeObject();
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalEmptyCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical empty collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests serialization by comparing against a previously stored version in CVS.
|
||||
* If the test object is serializable, confirm that a canonical form exists.
|
||||
*/
|
||||
public void testCanonicalFullCollectionExists() {
|
||||
if (supportsFullCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
|
||||
Object object = makeObject();
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalFullCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical full collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protected implementation
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Get the version of Collections that this object tries to
|
||||
* maintain serialization compatibility with. Defaults to 1, the
|
||||
* earliest Collections version. (Note: some collections did not
|
||||
* even exist in this version).
|
||||
*
|
||||
* This constant makes it possible for TestMap (and other subclasses,
|
||||
* if necessary) to automatically check CVS for a versionX copy of a
|
||||
* Serialized object, so we can make sure that compatibility is maintained.
|
||||
* See, for example, TestMap.getCanonicalFullMapName(Map map).
|
||||
* Subclasses can override this variable, indicating compatibility
|
||||
* with earlier Collections versions.
|
||||
*
|
||||
* @return The version, or {@code null} if this object shouldn't be
|
||||
* tested for compatibility with previous versions.
|
||||
*/
|
||||
public String getCompatibilityVersion() {
|
||||
return "1";
|
||||
}
|
||||
|
||||
protected String getCanonicalEmptyCollectionName(Object object) {
|
||||
StringBuilder retval = new StringBuilder();
|
||||
retval.append("data/test/");
|
||||
String colName = object.getClass().getName();
|
||||
colName = colName.substring(colName.lastIndexOf(".") + 1, colName.length());
|
||||
retval.append(colName);
|
||||
retval.append(".emptyCollection.version");
|
||||
retval.append(getCompatibilityVersion());
|
||||
retval.append(".obj");
|
||||
return retval.toString();
|
||||
}
|
||||
|
||||
protected String getCanonicalFullCollectionName(Object object) {
|
||||
StringBuilder retval = new StringBuilder();
|
||||
retval.append("data/test/");
|
||||
String colName = object.getClass().getName();
|
||||
colName = colName.substring(colName.lastIndexOf(".") + 1, colName.length());
|
||||
retval.append(colName);
|
||||
retval.append(".fullCollection.version");
|
||||
retval.append(getCompatibilityVersion());
|
||||
retval.append(".obj");
|
||||
return retval.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a Serializable or Externalizable object as
|
||||
* a file at the given path. NOT USEFUL as part
|
||||
* of a unit test; this is just a utility method
|
||||
* for creating disk-based objects in CVS that can become
|
||||
* the basis for compatibility tests using
|
||||
* readExternalFormFromDisk(String path)
|
||||
*
|
||||
* @param o Object to serialize
|
||||
* @param path path to write the serialized Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected void writeExternalFormToDisk(Serializable o, String path) throws IOException {
|
||||
FileOutputStream fileStream = new FileOutputStream(path);
|
||||
writeExternalFormToStream(o, fileStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Serializable or Externalizable object to
|
||||
* bytes. Useful for in-memory tests of serialization
|
||||
*
|
||||
* @param o Object to convert to bytes
|
||||
* @return serialized form of the Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected byte[] writeExternalFormToBytes(Serializable o) throws IOException {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
writeExternalFormToStream(o, byteStream);
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Serialized or Externalized Object from disk.
|
||||
* Useful for creating compatibility tests between
|
||||
* different CVS versions of the same class
|
||||
*
|
||||
* @param path path to the serialized Object
|
||||
* @return the Object at the given path
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromDisk(String path) throws IOException, ClassNotFoundException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a Serialized or Externalized Object from bytes.
|
||||
* Useful for verifying serialization in memory.
|
||||
*
|
||||
* @param b byte array containing a serialized Object
|
||||
* @return Object contained in the bytes
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromBytes(byte[] b) throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(b);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
protected boolean skipSerializedCanonicalTests() {
|
||||
return Boolean.getBoolean("org.apache.commons.collections:with-clover");
|
||||
}
|
||||
|
||||
// private implementation
|
||||
//-----------------------------------------------------------------------
|
||||
private Object readExternalFormFromStream(InputStream stream) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream oStream = new ObjectInputStream(stream);
|
||||
return oStream.readObject();
|
||||
}
|
||||
|
||||
private void writeExternalFormToStream(Serializable o, OutputStream stream) throws IOException {
|
||||
ObjectOutputStream oStream = new ObjectOutputStream(stream);
|
||||
oStream.writeObject(o);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Object} methods and contracts.
|
||||
* <p>
|
||||
* To use, simply extend this class, and implement
|
||||
* the {@link #makeObject()} method.
|
||||
* <p>
|
||||
* If your {@link Object} fails one of these tests by design,
|
||||
* you may still use this base set of cases. Simply override the
|
||||
* test case (method) your {@link Object} fails.
|
||||
*
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
* @author Stephen Colebourne
|
||||
* @author Anonymous
|
||||
*/
|
||||
public abstract class ObjectAbstractTest {
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Implement this method to return the object to test.
|
||||
*
|
||||
* @return the object to test
|
||||
*/
|
||||
public abstract Object makeObject();
|
||||
|
||||
/**
|
||||
* Override this method if a subclass is testing an object
|
||||
* that cannot serialize an "empty" Collection.
|
||||
* (e.g. Comparators have no contents)
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsEmptyCollections() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method if a subclass is testing an object
|
||||
* that cannot serialize a "full" Collection.
|
||||
* (e.g. Comparators have no contents)
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsFullCollections() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is serialization testing supported.
|
||||
* Default is true.
|
||||
*/
|
||||
public boolean isTestSerialization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to indicate that the collection supports equals() comparisons.
|
||||
* This implementation returns true;
|
||||
*/
|
||||
public boolean isEqualsCheckable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("A Object should equal itself", obj, obj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsNull() {
|
||||
Object obj = makeObject();
|
||||
assertEquals(false, obj.equals(null)); // make sure this doesn't throw NPE either
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
}
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeDeserializeThenCompare() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Serializable && isTestSerialization()) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
||||
out.writeObject(obj);
|
||||
out.close();
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
Object dest = in.readObject();
|
||||
in.close();
|
||||
if (isEqualsCheckable()) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check method, makes sure that any Serializable
|
||||
* class can be serialized and de-serialized in memory,
|
||||
* using the handy makeObject() method
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@Test
|
||||
public void testSimpleSerialization() throws Exception {
|
||||
Object o = makeObject();
|
||||
if (o instanceof Serializable && isTestSerialization()) {
|
||||
byte[] objekt = writeExternalFormToBytes((Serializable) o);
|
||||
Object p = readExternalFormFromBytes(objekt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests serialization by comparing against a previously stored version in CVS.
|
||||
* If the test object is serializable, confirm that a canonical form exists.
|
||||
*/
|
||||
@Test
|
||||
public void testCanonicalEmptyCollectionExists() {
|
||||
if (supportsEmptyCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
|
||||
Object object = makeObject();
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalEmptyCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical empty collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests serialization by comparing against a previously stored version in CVS.
|
||||
* If the test object is serializable, confirm that a canonical form exists.
|
||||
*/
|
||||
@Test
|
||||
public void testCanonicalFullCollectionExists() {
|
||||
if (supportsFullCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
|
||||
Object object = makeObject();
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalFullCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical full collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protected implementation
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Get the version of Collections that this object tries to
|
||||
* maintain serialization compatibility with. Defaults to 1, the
|
||||
* earliest Collections version. (Note: some collections did not
|
||||
* even exist in this version).
|
||||
*
|
||||
* This constant makes it possible for TestMap (and other subclasses,
|
||||
* if necessary) to automatically check CVS for a versionX copy of a
|
||||
* Serialized object, so we can make sure that compatibility is maintained.
|
||||
* See, for example, TestMap.getCanonicalFullMapName(Map map).
|
||||
* Subclasses can override this variable, indicating compatibility
|
||||
* with earlier Collections versions.
|
||||
*
|
||||
* @return The version, or {@code null} if this object shouldn't be
|
||||
* tested for compatibility with previous versions.
|
||||
*/
|
||||
public String getCompatibilityVersion() {
|
||||
return "1";
|
||||
}
|
||||
|
||||
protected String getCanonicalEmptyCollectionName(Object object) {
|
||||
StringBuilder retval = new StringBuilder();
|
||||
retval.append("data/test/");
|
||||
String colName = object.getClass().getName();
|
||||
colName = colName.substring(colName.lastIndexOf(".") + 1, colName.length());
|
||||
retval.append(colName);
|
||||
retval.append(".emptyCollection.version");
|
||||
retval.append(getCompatibilityVersion());
|
||||
retval.append(".obj");
|
||||
return retval.toString();
|
||||
}
|
||||
|
||||
protected String getCanonicalFullCollectionName(Object object) {
|
||||
StringBuilder retval = new StringBuilder();
|
||||
retval.append("data/test/");
|
||||
String colName = object.getClass().getName();
|
||||
colName = colName.substring(colName.lastIndexOf(".") + 1, colName.length());
|
||||
retval.append(colName);
|
||||
retval.append(".fullCollection.version");
|
||||
retval.append(getCompatibilityVersion());
|
||||
retval.append(".obj");
|
||||
return retval.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a Serializable or Externalizable object as
|
||||
* a file at the given path. NOT USEFUL as part
|
||||
* of a unit test; this is just a utility method
|
||||
* for creating disk-based objects in CVS that can become
|
||||
* the basis for compatibility tests using
|
||||
* readExternalFormFromDisk(String path)
|
||||
*
|
||||
* @param o Object to serialize
|
||||
* @param path path to write the serialized Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected void writeExternalFormToDisk(Serializable o, String path) throws IOException {
|
||||
FileOutputStream fileStream = new FileOutputStream(path);
|
||||
writeExternalFormToStream(o, fileStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Serializable or Externalizable object to
|
||||
* bytes. Useful for in-memory tests of serialization
|
||||
*
|
||||
* @param o Object to convert to bytes
|
||||
* @return serialized form of the Object
|
||||
* @exception java.io.IOException
|
||||
*/
|
||||
protected byte[] writeExternalFormToBytes(Serializable o) throws IOException {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
writeExternalFormToStream(o, byteStream);
|
||||
return byteStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Serialized or Externalized Object from disk.
|
||||
* Useful for creating compatibility tests between
|
||||
* different CVS versions of the same class
|
||||
*
|
||||
* @param path path to the serialized Object
|
||||
* @return the Object at the given path
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromDisk(String path) throws IOException, ClassNotFoundException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a Serialized or Externalized Object from bytes.
|
||||
* Useful for verifying serialization in memory.
|
||||
*
|
||||
* @param b byte array containing a serialized Object
|
||||
* @return Object contained in the bytes
|
||||
* @exception java.io.IOException
|
||||
* @exception ClassNotFoundException
|
||||
*/
|
||||
protected Object readExternalFormFromBytes(byte[] b) throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(b);
|
||||
return readExternalFormFromStream(stream);
|
||||
}
|
||||
|
||||
protected boolean skipSerializedCanonicalTests() {
|
||||
return Boolean.getBoolean("org.apache.commons.collections:with-clover");
|
||||
}
|
||||
|
||||
// private implementation
|
||||
//-----------------------------------------------------------------------
|
||||
private Object readExternalFormFromStream(InputStream stream) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream oStream = new ObjectInputStream(stream);
|
||||
return oStream.readObject();
|
||||
}
|
||||
|
||||
private void writeExternalFormToStream(Serializable o, OutputStream stream) throws IOException {
|
||||
ObjectOutputStream oStream = new ObjectOutputStream(stream);
|
||||
oStream.writeObject(o);
|
||||
}
|
||||
|
||||
}
|
||||
+215
-183
@@ -1,183 +1,215 @@
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Set} methods and contracts.
|
||||
* <p>
|
||||
* Since {@link Set} doesn't stipulate much new behavior that isn't already
|
||||
* found in {@link Collection}, this class basically just adds tests for
|
||||
* {@link Set#equals} and {@link Set#hashCode()} along with an updated
|
||||
* {@link #verifyAll()} that ensures elements do not appear more than once in the
|
||||
* set.
|
||||
* <p>
|
||||
* To use, subclass and override the {@link #makeEmptySet()}
|
||||
* method. You may have to override other protected methods if your
|
||||
* set is not modifiable, or if your set restricts what kinds of
|
||||
* elements may be added; see {@link CollectionAbstractTestCase} for more details.
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author Paul Jack
|
||||
*/
|
||||
public abstract class SetAbstractTestCase extends CollectionAbstractTestCase {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Provides additional verifications for sets.
|
||||
*/
|
||||
public void verifyAll() {
|
||||
super.verifyAll();
|
||||
|
||||
assertEquals("Sets should be equal", confirmed, collection);
|
||||
assertEquals("Sets should have equal hashCodes",
|
||||
confirmed.hashCode(), collection.hashCode());
|
||||
Collection set = makeConfirmedCollection();
|
||||
Iterator iterator = collection.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
assertTrue("Set.iterator should only return unique elements",
|
||||
set.add(iterator.next()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Set equals method is defined.
|
||||
*/
|
||||
public boolean isEqualsCheckable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty Set for use in modification testing.
|
||||
*
|
||||
* @return a confirmed empty collection
|
||||
*/
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new HashSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full Set for use in modification testing.
|
||||
*
|
||||
* @return a confirmed full collection
|
||||
*/
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
Collection set = makeConfirmedCollection();
|
||||
set.addAll(Arrays.asList(getFullElements()));
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an empty set. The returned set should have no elements.
|
||||
*
|
||||
* @return an empty set
|
||||
*/
|
||||
public abstract Set makeEmptySet();
|
||||
|
||||
/**
|
||||
* Makes a full set by first creating an empty set and then adding
|
||||
* all the elements returned by {@link #getFullElements()}.
|
||||
*
|
||||
* Override if your set does not support the add operation.
|
||||
*
|
||||
* @return a full set
|
||||
*/
|
||||
public Set makeFullSet() {
|
||||
Set set = makeEmptySet();
|
||||
set.addAll(Arrays.asList(getFullElements()));
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an empty collection by invoking {@link #makeEmptySet()}.
|
||||
*
|
||||
* @return an empty collection
|
||||
*/
|
||||
public final Collection makeCollection() {
|
||||
return makeEmptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a full collection by invoking {@link #makeFullSet()}.
|
||||
*
|
||||
* @return a full collection
|
||||
*/
|
||||
public final Collection makeFullCollection() {
|
||||
return makeFullSet();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Return the {@link CollectionAbstractTestCase#collection} fixture, but cast as a Set.
|
||||
*/
|
||||
public Set getSet() {
|
||||
return (Set)collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link CollectionAbstractTestCase#confirmed} fixture, but cast as a Set.
|
||||
*/
|
||||
public Set getConfirmedSet() {
|
||||
return (Set)confirmed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests {@link Set#equals(Object)}.
|
||||
*/
|
||||
public void testSetEquals() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets should be equal",
|
||||
getSet(), getConfirmedSet());
|
||||
verifyAll();
|
||||
|
||||
Collection set2 = makeConfirmedCollection();
|
||||
set2.add("foo");
|
||||
assertTrue("Empty set shouldn't equal nonempty set",
|
||||
!getSet().equals(set2));
|
||||
|
||||
resetFull();
|
||||
assertEquals("Full sets should be equal", getSet(), getConfirmedSet());
|
||||
verifyAll();
|
||||
|
||||
set2.clear();
|
||||
set2.addAll(Arrays.asList(getOtherElements()));
|
||||
assertTrue("Sets with different contents shouldn't be equal",
|
||||
!getSet().equals(set2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link Set#hashCode()}.
|
||||
*/
|
||||
public void testSetHashCode() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
|
||||
resetFull();
|
||||
assertEquals("Equal sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Set} methods and contracts.
|
||||
* <p>
|
||||
* Since {@link Set} doesn't stipulate much new behavior that isn't already
|
||||
* found in {@link Collection}, this class basically just adds tests for
|
||||
* {@link Set#equals} and {@link Set#hashCode()} along with an updated
|
||||
* {@link #verifyAll()} that ensures elements do not appear more than once in the
|
||||
* set.
|
||||
* <p>
|
||||
* To use, subclass and override the {@link #makeEmptySet()}
|
||||
* method. You may have to override other protected methods if your
|
||||
* set is not modifiable, or if your set restricts what kinds of
|
||||
* elements may be added; see {@link CollectionAbstractTest} for more details.
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision: #2 $ $Date: 2008/07/15 $
|
||||
*
|
||||
* @author Paul Jack
|
||||
*/
|
||||
public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Provides additional verifications for sets.
|
||||
*/
|
||||
public void verifyAll() {
|
||||
super.verifyAll();
|
||||
|
||||
assertEquals("Sets should be equal", confirmed, collection);
|
||||
assertEquals("Sets should have equal hashCodes",
|
||||
confirmed.hashCode(), collection.hashCode());
|
||||
Collection set = makeConfirmedCollection();
|
||||
Iterator iterator = collection.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
assertTrue("Set.iterator should only return unique elements",
|
||||
set.add(iterator.next()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Set equals method is defined.
|
||||
*/
|
||||
public boolean isEqualsCheckable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty Set for use in modification testing.
|
||||
*
|
||||
* @return a confirmed empty collection
|
||||
*/
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new HashSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full Set for use in modification testing.
|
||||
*
|
||||
* @return a confirmed full collection
|
||||
*/
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
Collection set = makeConfirmedCollection();
|
||||
set.addAll(Arrays.asList(getFullElements()));
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an empty set. The returned set should have no elements.
|
||||
*
|
||||
* @return an empty set
|
||||
*/
|
||||
public abstract Set makeEmptySet();
|
||||
|
||||
/**
|
||||
* Makes a full set by first creating an empty set and then adding
|
||||
* all the elements returned by {@link #getFullElements()}.
|
||||
*
|
||||
* Override if your set does not support the add operation.
|
||||
*
|
||||
* @return a full set
|
||||
*/
|
||||
public Set makeFullSet() {
|
||||
Set set = makeEmptySet();
|
||||
set.addAll(Arrays.asList(getFullElements()));
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an empty collection by invoking {@link #makeEmptySet()}.
|
||||
*
|
||||
* @return an empty collection
|
||||
*/
|
||||
public final Collection makeCollection() {
|
||||
return makeEmptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a full collection by invoking {@link #makeFullSet()}.
|
||||
*
|
||||
* @return a full collection
|
||||
*/
|
||||
@Override
|
||||
public final Collection makeFullCollection() {
|
||||
return makeFullSet();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Return the {@link CollectionAbstractTest#collection} fixture, but cast as a Set.
|
||||
*/
|
||||
public Set getSet() {
|
||||
return (Set)collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link CollectionAbstractTest#confirmed} fixture, but cast as a Set.
|
||||
*/
|
||||
public Set getConfirmedSet() {
|
||||
return (Set)confirmed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Tests {@link Set#equals(Object)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetEquals() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets should be equal",
|
||||
getSet(), getConfirmedSet());
|
||||
verifyAll();
|
||||
|
||||
Collection set2 = makeConfirmedCollection();
|
||||
set2.add("foo");
|
||||
assertTrue("Empty set shouldn't equal nonempty set",
|
||||
!getSet().equals(set2));
|
||||
|
||||
resetFull();
|
||||
assertEquals("Full sets should be equal", getSet(), getConfirmedSet());
|
||||
verifyAll();
|
||||
|
||||
set2.clear();
|
||||
set2.addAll(Arrays.asList(getOtherElements()));
|
||||
assertTrue("Sets with different contents shouldn't be equal",
|
||||
!getSet().equals(set2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link Set#hashCode()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetHashCode() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
|
||||
resetFull();
|
||||
assertEquals("Equal sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
}
|
||||
}
|
||||
+143
-111
@@ -1,111 +1,143 @@
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
* <p/>
|
||||
* <!-- To change this template use Options | File Templates. -->
|
||||
* <!-- Created by IntelliJ IDEA. -->
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/StringTokenIteratorTestCase.java#1 $
|
||||
*/
|
||||
public class StringTokenIteratorTestCase extends TokenIteratorAbstractTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString) {
|
||||
return new StringTokenIterator(pString);
|
||||
}
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString, String pDelimiters) {
|
||||
return new StringTokenIterator(pString, pDelimiters);
|
||||
}
|
||||
|
||||
public void testEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("", "");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleTokenEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", " ,.;:");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
* <p/>
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/StringTokenIteratorTestCase.java#1 $
|
||||
*/
|
||||
public class StringTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString) {
|
||||
return new StringTokenIterator(pString);
|
||||
}
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString, String pDelimiters) {
|
||||
return new StringTokenIterator(pString, pDelimiters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("", "");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", " ,.;:");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
}
|
||||
+655
-632
File diff suppressed because it is too large
Load Diff
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* TokenIteratorAbstractTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/TokenIteratorAbstractTestCase.java#1 $
|
||||
*/
|
||||
public abstract class TokenIteratorAbstractTest {
|
||||
protected abstract TokenIterator createTokenIterator(String pString);
|
||||
|
||||
protected abstract TokenIterator createTokenIterator(String pString, String pDelimiters);
|
||||
|
||||
@Test
|
||||
public void testNullString() {
|
||||
try {
|
||||
createTokenIterator(null);
|
||||
fail("Null string parameter not allowed");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// okay!
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail(t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullDelimmiter() {
|
||||
try {
|
||||
createTokenIterator("", null);
|
||||
fail("Null delimiter parameter not allowed");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// okay!
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail(t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyString() {
|
||||
Iterator iterator = createTokenIterator("");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* TokenIteratorAbstractTestCase
|
||||
* <p/>
|
||||
* <!-- To change this template use Options | File Templates. -->
|
||||
* <!-- Created by IntelliJ IDEA. -->
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/TokenIteratorAbstractTestCase.java#1 $
|
||||
*/
|
||||
public abstract class TokenIteratorAbstractTestCase extends TestCase {
|
||||
protected abstract TokenIterator createTokenIterator(String pString);
|
||||
|
||||
protected abstract TokenIterator createTokenIterator(String pString, String pDelimiters);
|
||||
|
||||
public void testNullString() {
|
||||
try {
|
||||
createTokenIterator(null);
|
||||
fail("Null string parameter not allowed");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// okay!
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail(t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testNullDelimmiter() {
|
||||
try {
|
||||
createTokenIterator("", null);
|
||||
fail("Null delimiter parameter not allowed");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// okay!
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail(t.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testEmptyString() {
|
||||
Iterator iterator = createTokenIterator("");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* ConverterTest
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/ConverterTestCase.java#1 $
|
||||
*/
|
||||
public class ConverterTest {
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@Test
|
||||
public void testMe() {
|
||||
// TODO: Implement tests
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* ConverterTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/ConverterTestCase.java#1 $
|
||||
*/
|
||||
public class ConverterTestCase extends TestCase {
|
||||
|
||||
public void testMe() {
|
||||
// TODO: Implement tests
|
||||
}
|
||||
}
|
||||
+92
-60
@@ -1,61 +1,93 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.DateUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* DateConverterTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/DateConverterTestCase.java#2 $
|
||||
*/
|
||||
public class DateConverterTestCase extends PropertyConverterAbstractTestCase {
|
||||
protected final static String FORMAT_STR_1 = "dd.MM.yyyy HH:mm:ss";
|
||||
protected final static String FORMAT_STR_2 = "dd-MM-yyyy hh:mm:ss a";
|
||||
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new DateConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
// The default format doesn't contain milliseconds, so we have to round
|
||||
long time = System.currentTimeMillis();
|
||||
final Date now = new Date(DateUtil.roundToSecond(time));
|
||||
DateFormat df = DateFormat.getDateTimeInstance();
|
||||
|
||||
return new Conversion[] {
|
||||
new Conversion("01.11.2006 15:26:23", new GregorianCalendar(2006, 10, 1, 15, 26, 23).getTime(), FORMAT_STR_1),
|
||||
|
||||
// This doesn't really work.. But close enough
|
||||
new Conversion(df.format(now), now),
|
||||
|
||||
// This format is really stupid
|
||||
new Conversion("01-11-2006 03:27:44 pm", new GregorianCalendar(2006, 10, 1, 15, 27, 44).getTime(), FORMAT_STR_2, "01-11-2006 03:27:44 PM"),
|
||||
|
||||
// These seems to be an hour off (no timezone?)...
|
||||
new Conversion("42", new Date(42l), "S"),
|
||||
new Conversion(String.valueOf(time % 1000l), new Date(time % 1000l), "S"),
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testConvert() {
|
||||
// Custom setup, to make test cases stable: Always use GMT
|
||||
TimeZone oldTZ = TimeZone.getDefault();
|
||||
|
||||
try {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
super.testConvert();
|
||||
}
|
||||
finally {
|
||||
// Restore
|
||||
TimeZone.setDefault(oldTZ);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.DateUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* DateConverterTest
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/DateConverterTestCase.java#2 $
|
||||
*/
|
||||
public class DateConverterTest extends PropertyConverterAbstractTest {
|
||||
protected final static String FORMAT_STR_1 = "dd.MM.yyyy HH:mm:ss";
|
||||
protected final static String FORMAT_STR_2 = "dd-MM-yyyy hh:mm:ss a";
|
||||
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new DateConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
// The default format doesn't contain milliseconds, so we have to round
|
||||
long time = System.currentTimeMillis();
|
||||
final Date now = new Date(DateUtil.roundToSecond(time));
|
||||
DateFormat df = DateFormat.getDateTimeInstance();
|
||||
|
||||
return new Conversion[] {
|
||||
new Conversion("01.11.2006 15:26:23", new GregorianCalendar(2006, 10, 1, 15, 26, 23).getTime(), FORMAT_STR_1),
|
||||
|
||||
// This doesn't really work.. But close enough
|
||||
new Conversion(df.format(now), now),
|
||||
|
||||
// This format is really stupid
|
||||
new Conversion("01-11-2006 03:27:44 pm", new GregorianCalendar(2006, 10, 1, 15, 27, 44).getTime(), FORMAT_STR_2, "01-11-2006 03:27:44 PM"),
|
||||
|
||||
// These seems to be an hour off (no timezone?)...
|
||||
new Conversion("42", new Date(42l), "S"),
|
||||
new Conversion(String.valueOf(time % 1000l), new Date(time % 1000l), "S"),
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testConvert() {
|
||||
// Custom setup, to make test cases stable: Always use GMT
|
||||
TimeZone oldTZ = TimeZone.getDefault();
|
||||
|
||||
try {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
super.testConvert();
|
||||
}
|
||||
finally {
|
||||
// Restore
|
||||
TimeZone.setDefault(oldTZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
+180
-150
@@ -1,150 +1,180 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* DefaultConverterTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/DefaultConverterTestCase.java#1 $
|
||||
*/
|
||||
public class DefaultConverterTestCase extends PropertyConverterAbstractTestCase {
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new DefaultConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
//noinspection BooleanConstructorCall
|
||||
return new Conversion[] {
|
||||
// Booleans
|
||||
new Conversion("true", Boolean.TRUE),
|
||||
new Conversion("TRUE", Boolean.TRUE, null, "true"),
|
||||
new Conversion("false", Boolean.FALSE),
|
||||
new Conversion("FALSE", false, null, "false"),
|
||||
|
||||
new Conversion("2", 2),
|
||||
|
||||
// Stupid but valid
|
||||
new Conversion("fooBar", "fooBar"),
|
||||
//new Conversion("fooBar", new StringBuilder("fooBar")), - StringBuilder does not impl equals()...
|
||||
|
||||
// Stupid test class that reveres chars
|
||||
new Conversion("fooBar", new FooBar("fooBar")),
|
||||
|
||||
// String array tests
|
||||
new Conversion("foo, bar, baz", new String[] {"foo", "bar", "baz"}),
|
||||
new Conversion("foo", new String[] {"foo"}),
|
||||
new Conversion("foo;bar; baz", new String[] {"foo", "bar", "baz"}, "; ", "foo; bar; baz"),
|
||||
|
||||
// Native array tests
|
||||
new Conversion("1, 2, 3", new int[] {1, 2, 3}),
|
||||
new Conversion("-1, 42, 0", new long[] {-1, 42, 0}),
|
||||
new Conversion("true, true, false", new boolean[] {true, true, false}),
|
||||
new Conversion(".3, 4E7, .97", new float[] {.3f, 4e7f, .97f}, ", ", "0.3, 4.0E7, 0.97"),
|
||||
|
||||
// Object array test
|
||||
new Conversion("foo, bar", new FooBar[] {new FooBar("foo"), new FooBar("bar")}),
|
||||
new Conversion("/temp, /usr/local/bin".replace('/', File.separatorChar), new File[] {new File("/temp"), new File("/usr/local/bin")}),
|
||||
new Conversion("file:/temp, http://java.net/", new URI[] {URI.create("file:/temp"), URI.create("http://java.net/")}),
|
||||
|
||||
// TODO: More tests
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertBooleanPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertTrue((Boolean) converter.toObject("true", boolean.class, null));
|
||||
assertFalse((Boolean) converter.toObject("FalsE", Boolean.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (short) (Short) converter.toObject("1", short.class, null));
|
||||
assertEquals(-2, (short) (Short) converter.toObject("-2", Short.TYPE, null));
|
||||
}
|
||||
@Test
|
||||
public void testConvertIntPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (int) (Integer) converter.toObject("1", int.class, null));
|
||||
assertEquals(-2, (int) (Integer) converter.toObject("-2", Integer.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(Long.MAX_VALUE, (long) (Long) converter.toObject("9223372036854775807", long.class, null));
|
||||
assertEquals(-2, (long) (Long) converter.toObject("-2", Long.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertBytePrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (byte) (Byte) converter.toObject("1", byte.class, null));
|
||||
assertEquals(-2, (byte) (Byte) converter.toObject("-2", Byte.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFloatPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1f, (Float) converter.toObject("1.0", float.class, null), 0);
|
||||
assertEquals(-2.3456f, (Float) converter.toObject("-2.3456", Float.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertDoublePrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1d, (Double) converter.toObject("1.0", double.class, null), 0);
|
||||
assertEquals(-2.3456, (Double) converter.toObject("-2.3456", Double.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Ignore("Known issue. Why would anyone do something like this?")
|
||||
@Test
|
||||
public void testConvertCharPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals('A', (char) (Character) converter.toObject("A", char.class, null));
|
||||
assertEquals('Z', (char) (Character) converter.toObject("Z", Character.TYPE, null));
|
||||
}
|
||||
|
||||
public static class FooBar {
|
||||
private final String bar;
|
||||
|
||||
public FooBar(String pFoo) {
|
||||
Validate.notNull(pFoo, "foo");
|
||||
|
||||
bar = reverse(pFoo);
|
||||
}
|
||||
|
||||
private String reverse(String pFoo) {
|
||||
StringBuilder buffer = new StringBuilder(pFoo.length());
|
||||
|
||||
for (int i = pFoo.length() - 1; i >= 0; i--) {
|
||||
buffer.append(pFoo.charAt(i));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return reverse(bar);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this || (obj != null && obj.getClass() == getClass() && ((FooBar) obj).bar.equals(bar));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 7 * bar.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* DefaultConverterTest
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/DefaultConverterTestCase.java#1 $
|
||||
*/
|
||||
public class DefaultConverterTest extends PropertyConverterAbstractTest {
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new DefaultConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
//noinspection BooleanConstructorCall
|
||||
return new Conversion[] {
|
||||
// Booleans
|
||||
new Conversion("true", Boolean.TRUE),
|
||||
new Conversion("TRUE", Boolean.TRUE, null, "true"),
|
||||
new Conversion("false", Boolean.FALSE),
|
||||
new Conversion("FALSE", false, null, "false"),
|
||||
|
||||
new Conversion("2", 2),
|
||||
|
||||
// Stupid but valid
|
||||
new Conversion("fooBar", "fooBar"),
|
||||
//new Conversion("fooBar", new StringBuilder("fooBar")), - StringBuilder does not impl equals()...
|
||||
|
||||
// Stupid test class that reveres chars
|
||||
new Conversion("fooBar", new FooBar("fooBar")),
|
||||
|
||||
// String array tests
|
||||
new Conversion("foo, bar, baz", new String[] {"foo", "bar", "baz"}),
|
||||
new Conversion("foo", new String[] {"foo"}),
|
||||
new Conversion("foo;bar; baz", new String[] {"foo", "bar", "baz"}, "; ", "foo; bar; baz"),
|
||||
|
||||
// Native array tests
|
||||
new Conversion("1, 2, 3", new int[] {1, 2, 3}),
|
||||
new Conversion("-1, 42, 0", new long[] {-1, 42, 0}),
|
||||
new Conversion("true, true, false", new boolean[] {true, true, false}),
|
||||
new Conversion(".3, 4E7, .97", new float[] {.3f, 4e7f, .97f}, ", ", "0.3, 4.0E7, 0.97"),
|
||||
|
||||
// Object array test
|
||||
new Conversion("foo, bar", new FooBar[] {new FooBar("foo"), new FooBar("bar")}),
|
||||
new Conversion("/temp, /usr/local/bin".replace('/', File.separatorChar), new File[] {new File("/temp"), new File("/usr/local/bin")}),
|
||||
new Conversion("file:/temp, http://java.net/", new URI[] {URI.create("file:/temp"), URI.create("http://java.net/")}),
|
||||
|
||||
// TODO: More tests
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertBooleanPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertTrue((Boolean) converter.toObject("true", boolean.class, null));
|
||||
assertFalse((Boolean) converter.toObject("FalsE", Boolean.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (short) (Short) converter.toObject("1", short.class, null));
|
||||
assertEquals(-2, (short) (Short) converter.toObject("-2", Short.TYPE, null));
|
||||
}
|
||||
@Test
|
||||
public void testConvertIntPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (int) (Integer) converter.toObject("1", int.class, null));
|
||||
assertEquals(-2, (int) (Integer) converter.toObject("-2", Integer.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(Long.MAX_VALUE, (long) (Long) converter.toObject("9223372036854775807", long.class, null));
|
||||
assertEquals(-2, (long) (Long) converter.toObject("-2", Long.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertBytePrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (byte) (Byte) converter.toObject("1", byte.class, null));
|
||||
assertEquals(-2, (byte) (Byte) converter.toObject("-2", Byte.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFloatPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1f, (Float) converter.toObject("1.0", float.class, null), 0);
|
||||
assertEquals(-2.3456f, (Float) converter.toObject("-2.3456", Float.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertDoublePrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1d, (Double) converter.toObject("1.0", double.class, null), 0);
|
||||
assertEquals(-2.3456, (Double) converter.toObject("-2.3456", Double.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Ignore("Known issue. Why would anyone do something like this?")
|
||||
@Test
|
||||
public void testConvertCharPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals('A', (char) (Character) converter.toObject("A", char.class, null));
|
||||
assertEquals('Z', (char) (Character) converter.toObject("Z", Character.TYPE, null));
|
||||
}
|
||||
|
||||
public static class FooBar {
|
||||
private final String bar;
|
||||
|
||||
public FooBar(String pFoo) {
|
||||
Validate.notNull(pFoo, "foo");
|
||||
|
||||
bar = reverse(pFoo);
|
||||
}
|
||||
|
||||
private String reverse(String pFoo) {
|
||||
StringBuilder buffer = new StringBuilder(pFoo.length());
|
||||
|
||||
for (int i = pFoo.length() - 1; i >= 0; i--) {
|
||||
buffer.append(pFoo.charAt(i));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return reverse(bar);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this || (obj != null && obj.getClass() == getClass() && ((FooBar) obj).bar.equals(bar));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 7 * bar.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
-42
@@ -1,42 +1,72 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
/**
|
||||
* NumberConverterTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/NumberConverterTestCase.java#2 $
|
||||
*/
|
||||
public class NumberConverterTestCase extends PropertyConverterAbstractTestCase {
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new NumberConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
return new Conversion[] {
|
||||
new Conversion("0", 0),
|
||||
new Conversion("1", 1),
|
||||
new Conversion("-1001", -1001),
|
||||
new Conversion("1E3", 1000, null, "1000"),
|
||||
|
||||
new Conversion("-2", -2l),
|
||||
new Conversion("2000651651854", 2000651651854l),
|
||||
new Conversion("2E10", 20000000000l, null, "20000000000"),
|
||||
|
||||
new Conversion("3", 3.0f),
|
||||
new Conversion("3.1", 3.1f),
|
||||
new Conversion("3.2", 3.2f, "#.#"),
|
||||
//new Conversion("3,3", new Float(3), "#", "3"), // Seems to need parseIntegerOnly
|
||||
new Conversion("-3.4", -3.4f),
|
||||
new Conversion("-3.5E10", -3.5e10f, null, "-35000000512"),
|
||||
|
||||
new Conversion("4", 4.0),
|
||||
new Conversion("4.1", 4.1),
|
||||
new Conversion("4.2", 4.2, "#.#"),
|
||||
//new Conversion("4,3", new Double(4), "#", "4"), // Seems to need parseIntegerOnly
|
||||
new Conversion("-4.4", -4.4),
|
||||
new Conversion("-4.5E97", -4.5e97, null, "-45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
||||
};
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
/**
|
||||
* NumberConverterTest
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/NumberConverterTestCase.java#2 $
|
||||
*/
|
||||
public class NumberConverterTest extends PropertyConverterAbstractTest {
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new NumberConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
return new Conversion[] {
|
||||
new Conversion("0", 0),
|
||||
new Conversion("1", 1),
|
||||
new Conversion("-1001", -1001),
|
||||
new Conversion("1E3", 1000, null, "1000"),
|
||||
|
||||
new Conversion("-2", -2l),
|
||||
new Conversion("2000651651854", 2000651651854l),
|
||||
new Conversion("2E10", 20000000000l, null, "20000000000"),
|
||||
|
||||
new Conversion("3", 3.0f),
|
||||
new Conversion("3.1", 3.1f),
|
||||
new Conversion("3.2", 3.2f, "#.#"),
|
||||
//new Conversion("3,3", new Float(3), "#", "3"), // Seems to need parseIntegerOnly
|
||||
new Conversion("-3.4", -3.4f),
|
||||
new Conversion("-3.5E10", -3.5e10f, null, "-35000000512"),
|
||||
|
||||
new Conversion("4", 4.0),
|
||||
new Conversion("4.1", 4.1),
|
||||
new Conversion("4.2", 4.2, "#.#"),
|
||||
//new Conversion("4,3", new Double(4), "#", "4"), // Seems to need parseIntegerOnly
|
||||
new Conversion("-4.4", -4.4),
|
||||
new Conversion("-4.5E97", -4.5e97, null, "-45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
||||
};
|
||||
}
|
||||
}
|
||||
+184
-154
@@ -1,154 +1,184 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTestCase;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* PropertyConverterAbstractTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java#2 $
|
||||
*/
|
||||
public abstract class PropertyConverterAbstractTestCase extends ObjectAbstractTestCase {
|
||||
protected Object makeObject() {
|
||||
return makePropertyConverter();
|
||||
}
|
||||
|
||||
protected abstract PropertyConverter makePropertyConverter();
|
||||
|
||||
protected abstract Conversion[] getTestConversions();
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
|
||||
Conversion[] tests = getTestConversions();
|
||||
|
||||
for (Conversion test : tests) {
|
||||
Object obj;
|
||||
try {
|
||||
obj = converter.toObject(test.original(), test.type(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
}
|
||||
|
||||
String result = converter.toString(test.value(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' does not match", test.converted()), test.converted(), result);
|
||||
|
||||
obj = converter.toObject(result, test.type(), test.format());
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
}
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
failBecause(String.format("Converting '%s' to %s failed", test.original(), test.type()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertArrayEquals0(final String message, final Object left, final Object right) {
|
||||
Class<?> componentType = left.getClass().getComponentType();
|
||||
if (componentType.isPrimitive()) {
|
||||
if (int.class == componentType) {
|
||||
assertArrayEquals(message, (int[]) left, (int[]) right);
|
||||
}
|
||||
else if (short.class == componentType) {
|
||||
assertArrayEquals(message, (short[]) left, (short[]) right);
|
||||
}
|
||||
else if (long.class == componentType) {
|
||||
assertArrayEquals(message, (long[]) left, (long[]) right);
|
||||
}
|
||||
else if (float.class == componentType) {
|
||||
assertArrayEquals(message, (float[]) left, (float[]) right, 0f);
|
||||
}
|
||||
else if (double.class == componentType) {
|
||||
assertArrayEquals(message, (double[]) left, (double[]) right, 0d);
|
||||
}
|
||||
else if (boolean.class == componentType) {
|
||||
assertTrue(message, Arrays.equals((boolean[]) left, (boolean[]) right));
|
||||
}
|
||||
else if (byte.class == componentType) {
|
||||
assertArrayEquals(message, (byte[]) left, (byte[]) right);
|
||||
}
|
||||
else if (char.class == componentType) {
|
||||
assertArrayEquals(message, (char[]) left, (char[]) right);
|
||||
}
|
||||
else {
|
||||
fail(String.format("Unknown primitive type: %s", componentType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
assertArrayEquals(message, (Object[]) left, (Object[]) right);
|
||||
}
|
||||
}
|
||||
|
||||
private static void failBecause(String message, Throwable exception) {
|
||||
AssertionError error = new AssertionError(message);
|
||||
error.initCause(exception);
|
||||
throw error;
|
||||
}
|
||||
|
||||
public static final class Conversion {
|
||||
private final String strVal;
|
||||
private final Object objVal;
|
||||
private final String format;
|
||||
private final String convertedStrVal;
|
||||
|
||||
public Conversion(String pStrVal, Object pObjVal) {
|
||||
this(pStrVal, pObjVal, null);
|
||||
}
|
||||
|
||||
public Conversion(String pStrVal, Object pObjVal, String pFormat) {
|
||||
this(pStrVal, pObjVal, pFormat, pStrVal);
|
||||
}
|
||||
|
||||
public Conversion(String pStrVal, Object pObjVal, String pFormat, String pConvertedStrVal) {
|
||||
Validate.notNull(pStrVal, "strVal");
|
||||
Validate.notNull(pObjVal, "objVal");
|
||||
Validate.notNull(pConvertedStrVal, "convertedStrVal");
|
||||
|
||||
strVal = pStrVal;
|
||||
objVal = pObjVal;
|
||||
format = pFormat;
|
||||
convertedStrVal = pConvertedStrVal;
|
||||
}
|
||||
|
||||
public String original() {
|
||||
return strVal;
|
||||
}
|
||||
|
||||
public Object value() {
|
||||
return objVal;
|
||||
}
|
||||
|
||||
public Class type() {
|
||||
return objVal.getClass();
|
||||
}
|
||||
|
||||
public String format() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public String converted() {
|
||||
return convertedStrVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* PropertyConverterAbstractTest
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/PropertyConverterAbstractTestCase.java#2 $
|
||||
*/
|
||||
public abstract class PropertyConverterAbstractTest extends ObjectAbstractTest {
|
||||
protected Object makeObject() {
|
||||
return makePropertyConverter();
|
||||
}
|
||||
|
||||
protected abstract PropertyConverter makePropertyConverter();
|
||||
|
||||
protected abstract Conversion[] getTestConversions();
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
|
||||
Conversion[] tests = getTestConversions();
|
||||
|
||||
for (Conversion test : tests) {
|
||||
Object obj;
|
||||
try {
|
||||
obj = converter.toObject(test.original(), test.type(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
}
|
||||
|
||||
String result = converter.toString(test.value(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' does not match", test.converted()), test.converted(), result);
|
||||
|
||||
obj = converter.toObject(result, test.type(), test.format());
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
}
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
failBecause(String.format("Converting '%s' to %s failed", test.original(), test.type()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertArrayEquals0(final String message, final Object left, final Object right) {
|
||||
Class<?> componentType = left.getClass().getComponentType();
|
||||
if (componentType.isPrimitive()) {
|
||||
if (int.class == componentType) {
|
||||
assertArrayEquals(message, (int[]) left, (int[]) right);
|
||||
}
|
||||
else if (short.class == componentType) {
|
||||
assertArrayEquals(message, (short[]) left, (short[]) right);
|
||||
}
|
||||
else if (long.class == componentType) {
|
||||
assertArrayEquals(message, (long[]) left, (long[]) right);
|
||||
}
|
||||
else if (float.class == componentType) {
|
||||
assertArrayEquals(message, (float[]) left, (float[]) right, 0f);
|
||||
}
|
||||
else if (double.class == componentType) {
|
||||
assertArrayEquals(message, (double[]) left, (double[]) right, 0d);
|
||||
}
|
||||
else if (boolean.class == componentType) {
|
||||
assertTrue(message, Arrays.equals((boolean[]) left, (boolean[]) right));
|
||||
}
|
||||
else if (byte.class == componentType) {
|
||||
assertArrayEquals(message, (byte[]) left, (byte[]) right);
|
||||
}
|
||||
else if (char.class == componentType) {
|
||||
assertArrayEquals(message, (char[]) left, (char[]) right);
|
||||
}
|
||||
else {
|
||||
fail(String.format("Unknown primitive type: %s", componentType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
assertArrayEquals(message, (Object[]) left, (Object[]) right);
|
||||
}
|
||||
}
|
||||
|
||||
private static void failBecause(String message, Throwable exception) {
|
||||
AssertionError error = new AssertionError(message);
|
||||
error.initCause(exception);
|
||||
throw error;
|
||||
}
|
||||
|
||||
public static final class Conversion {
|
||||
private final String strVal;
|
||||
private final Object objVal;
|
||||
private final String format;
|
||||
private final String convertedStrVal;
|
||||
|
||||
public Conversion(String pStrVal, Object pObjVal) {
|
||||
this(pStrVal, pObjVal, null);
|
||||
}
|
||||
|
||||
public Conversion(String pStrVal, Object pObjVal, String pFormat) {
|
||||
this(pStrVal, pObjVal, pFormat, pStrVal);
|
||||
}
|
||||
|
||||
public Conversion(String pStrVal, Object pObjVal, String pFormat, String pConvertedStrVal) {
|
||||
Validate.notNull(pStrVal, "strVal");
|
||||
Validate.notNull(pObjVal, "objVal");
|
||||
Validate.notNull(pConvertedStrVal, "convertedStrVal");
|
||||
|
||||
strVal = pStrVal;
|
||||
objVal = pObjVal;
|
||||
format = pFormat;
|
||||
convertedStrVal = pConvertedStrVal;
|
||||
}
|
||||
|
||||
public String original() {
|
||||
return strVal;
|
||||
}
|
||||
|
||||
public Object value() {
|
||||
return objVal;
|
||||
}
|
||||
|
||||
public Class type() {
|
||||
return objVal.getClass();
|
||||
}
|
||||
|
||||
public String format() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public String converted() {
|
||||
return convertedStrVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
/**
|
||||
* TimeConverterTest
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/TimeConverterTestCase.java#1 $
|
||||
*/
|
||||
public class TimeConverterTest extends PropertyConverterAbstractTest {
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new TimeConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
return new Conversion[0];// TODO: Implement
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
/**
|
||||
* TimeConverterTestCase
|
||||
* <p/>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haku $
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/convert/TimeConverterTestCase.java#1 $
|
||||
*/
|
||||
public class TimeConverterTestCase extends PropertyConverterAbstractTestCase {
|
||||
protected PropertyConverter makePropertyConverter() {
|
||||
return new TimeConverter();
|
||||
}
|
||||
|
||||
protected Conversion[] getTestConversions() {
|
||||
return new Conversion[0];// TODO: Implement
|
||||
}
|
||||
}
|
||||
+153
-122
@@ -1,122 +1,153 @@
|
||||
package com.twelvemonkeys.util.regex;
|
||||
|
||||
import com.twelvemonkeys.util.TokenIterator;
|
||||
import com.twelvemonkeys.util.TokenIteratorAbstractTestCase;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
* <p/>
|
||||
* <!-- To change this template use Options | File Templates. -->
|
||||
* <!-- Created by IntelliJ IDEA. -->
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/regex/RegExTokenIteratorTestCase.java#1 $
|
||||
*/
|
||||
public class RegExTokenIteratorTestCase extends TokenIteratorAbstractTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString) {
|
||||
return new RegExTokenIterator(pString);
|
||||
}
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString, String pDelimiters) {
|
||||
return new RegExTokenIterator(pString, pDelimiters);
|
||||
}
|
||||
|
||||
public void testEmptyDelimiter() {
|
||||
// TODO: What is it supposed to match?
|
||||
/*
|
||||
Iterator iterator = createTokenIterator("", ".*");
|
||||
assertTrue("Empty string has no elements", iterator.hasNext());
|
||||
iterator.next();
|
||||
assertFalse("Empty string has more then one element", iterator.hasNext());
|
||||
*/
|
||||
}
|
||||
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleTokenEmptyDelimiter() {
|
||||
// TODO: What is it supposed to match?
|
||||
/*
|
||||
Iterator iterator = createTokenIterator("A", ".*");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
*/
|
||||
}
|
||||
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", "[^ ,.;:]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
Object o = iterator.next();
|
||||
assertEquals("A", o);
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.regex;
|
||||
|
||||
import com.twelvemonkeys.util.TokenIterator;
|
||||
import com.twelvemonkeys.util.TokenIteratorAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
* <p/>
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/test/java/com/twelvemonkeys/util/regex/RegExTokenIteratorTestCase.java#1 $
|
||||
*/
|
||||
public class RegExTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString) {
|
||||
return new RegExTokenIterator(pString);
|
||||
}
|
||||
|
||||
protected TokenIterator createTokenIterator(String pString, String pDelimiters) {
|
||||
return new RegExTokenIterator(pString, pDelimiters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyDelimiter() {
|
||||
// TODO: What is it supposed to match?
|
||||
/*
|
||||
Iterator iterator = createTokenIterator("", ".*");
|
||||
assertTrue("Empty string has no elements", iterator.hasNext());
|
||||
iterator.next();
|
||||
assertFalse("Empty string has more then one element", iterator.hasNext());
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenEmptyDelimiter() {
|
||||
// TODO: What is it supposed to match?
|
||||
/*
|
||||
Iterator iterator = createTokenIterator("A", ".*");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", "[^ ,.;:]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
Object o = iterator.next();
|
||||
assertEquals("A", o);
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.service;
|
||||
|
||||
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.service;
|
||||
|
||||
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.service;
|
||||
|
||||
+21
-19
@@ -4,26 +4,28 @@
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name "TwelveMonkeys" nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.util.service;
|
||||
|
||||
Reference in New Issue
Block a user