diff options
Diffstat (limited to 'israfil-foundation-core')
12 files changed, 885 insertions, 0 deletions
diff --git a/israfil-foundation-core/pom.xml b/israfil-foundation-core/pom.xml new file mode 100644 index 0000000..5bf65f4 --- /dev/null +++ b/israfil-foundation-core/pom.xml @@ -0,0 +1,21 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.israfil.foundation</groupId> + <artifactId>israfil-foundation-all</artifactId> + <version>5-SNAPSHOT</version> + </parent> + <artifactId>israfil-foundation-core</artifactId> + <name>Israfil Foundation Core Classes</name> + <version>1.0.2-SNAPSHOT</version> + <url>http://www.israfil.net/projects/foundation/${artifactId}</url> + <inceptionYear>2003</inceptionYear> + <licenses> + <license> + <name>BSD</name> + <distribution>repo</distribution> + <url>http://www.israfil.net/israfil-license-bsd.txt</url> + <comments>A simple open-source license with minimal restrictions</comments> + </license> + </licenses> + </project>
\ No newline at end of file diff --git a/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Copyright.java b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Copyright.java new file mode 100755 index 0000000..203793c --- /dev/null +++ b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Copyright.java @@ -0,0 +1,59 @@ +/*
+ * Copyright (c) 2006-2009 Israfil Consulting Services Corporation
+ * Copyright (c) 2006-2009 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: Copyright.java 640 2009-01-04 16:48:31Z christianedwardgruber $
+ */
+package net.israfil.foundation.core;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * An attribute used to tag the copyright year, owner, and license. This
+ * is purely for documentation purposes, and it has only a SOURCE scope.
+ *
+ * For example:
+ * <pre>
+ * @Copyright(years={"2003","2004","2005"} owner="Israfil Consulting Services Corporation" license="BSD")
+ * </pre>
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ *
+ * @deprecated
+ */
+@Documented
+@Retention(RetentionPolicy.SOURCE)
+public @interface Copyright {
+ String[] years();
+ String owner();
+ String license();
+}
diff --git a/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Counter.java b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Counter.java new file mode 100644 index 0000000..e87b86a --- /dev/null +++ b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Counter.java @@ -0,0 +1,52 @@ +/*
+ * Copyright (c) 2006 Israfil Consulting Services Corporation
+ * Copyright (c) 2006 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: Counter.java 618 2008-04-14 14:03:03Z christianedwardgruber $
+ */
+package net.israfil.foundation.core;
+
+
+/**
+ * A simple counter interface
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ */
+public interface Counter {
+
+ public int getCount();
+
+ public void increment();
+
+ public void decrement();
+
+ public void reset();
+
+}
diff --git a/israfil-foundation-core/src/main/java/net/israfil/foundation/core/SimpleCounter.java b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/SimpleCounter.java new file mode 100644 index 0000000..042f623 --- /dev/null +++ b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/SimpleCounter.java @@ -0,0 +1,54 @@ +/*
+ * Copyright (c) 2006 Israfil Consulting Services Corporation
+ * Copyright (c) 2006 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: SimpleCounter.java 618 2008-04-14 14:03:03Z christianedwardgruber $
+ */
+package net.israfil.foundation.core;
+
+
+/**
+ * A simple counter interface
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
+ */
+public class SimpleCounter implements Counter {
+
+ private int count = 0;
+
+ public int getCount() { return count; }
+
+ public void increment() { count++; }
+
+ public void decrement() { count--; }
+
+ public void reset() { count = 0; }
+
+}
diff --git a/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Strings.java b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Strings.java new file mode 100644 index 0000000..edde901 --- /dev/null +++ b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Strings.java @@ -0,0 +1,58 @@ +/*
+ * Copyright (c) 2006 Israfil Consulting Services Corporation
+ * Copyright (c) 2006 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * $Id: Strings.java 617 2008-04-14 13:46:15Z christianedwardgruber $
+ */
+package net.israfil.foundation.core;
+
+import java.util.Arrays;
+
+/**
+ * A Utility class that provides general string manipulation help.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber</a>
+ * @author Latest: $Author: christianedwardgruber $
+ * @version $Revision: 617 $
+ */
+public class Strings {
+
+ public static String camel(String string) {
+ if (string == null) return null;
+ if (string.length() < 1) return string;
+ StringBuffer sb = new StringBuffer(string);
+ sb.replace(0,1,sb.substring(0,1).toUpperCase());
+ return sb.toString();
+ }
+
+ public static String camelAllWords(String string, String separator) {
+ StringBuffer sb = new StringBuffer();
+ boolean first = true;
+ for (String _string : string.split(separator)) {
+ if (!first) sb.append(separator);
+ else first = false;
+ sb.append(camel(_string));
+ }
+ return sb.toString();
+ }
+
+ public static String concatenate(String separator, Iterable<String> strings) {
+ if (strings == null) return "";
+ boolean first = true;
+ StringBuffer sb = new StringBuffer();
+ for (String string : strings) {
+ if (first) {
+ first = false;
+ sb.append(string);
+ } else {
+ sb.append(separator).append(string);
+ }
+ }
+ return sb.toString();
+ }
+ public static String concatenate(String separator, String ... strings) {
+ if (strings == null) return "";
+ return concatenate(separator,Arrays.asList(strings));
+ }
+}
diff --git a/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Types.java b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Types.java new file mode 100644 index 0000000..f720fe9 --- /dev/null +++ b/israfil-foundation-core/src/main/java/net/israfil/foundation/core/Types.java @@ -0,0 +1,195 @@ +/*
+ * Copyright (c) 2006 Israfil Consulting Services Corporation
+ * Copyright (c) 2006 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * $Id: Types.java 644 2009-01-04 18:02:21Z christianedwardgruber $
+ */
+package net.israfil.foundation.core;
+
+/**
+ * A Utility class that provides type-conversion facilities. For
+ * example, this class provides well-deliniated logic for taking
+ * a generic object and converting it into another concrete type, such
+ * as a String. Another example would be transforming the string "yes"
+ * into a boolean in a well-defined, well-ordered way.
+ *
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber</a>
+ * @author Latest: $Author: christianedwardgruber $
+ * @version $Revision: 644 $
+ */
+public class Types {
+
+ private static final byte BOOLEAN_FALSE_NUMERIC = 0;
+ private static final byte BOOLEAN_TRUE_NUMERIC = 1;
+
+ /**
+ * A delegate interface that, if provided to the convert(String,Class,Converter)
+ * method will add fallback conversions. This allows the existing
+ * convert method to be extended without subclassing, overriding, or
+ * modifying source.
+ * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber</a>
+ */
+ public static interface Converter {
+ public Object convert(Object val, Class<?> aClass);
+ }
+
+ /**
+ * A method to convert an object to another object of a given type.
+ * @param value The object to be converted.
+ * @param aClass The class to which you wish to convert the object.
+ * @return The converted object.
+ */
+ public static Object convert(Object value, Class<?> aClass) {
+ return convert(value,aClass,null);
+ }
+
+ /**
+ * A method to convert an object to another object of a given type.
+ * @param value The object to be converted.
+ * @param aClass The class to which you wish to convert the object.
+ * @param converter An optional delegate that will convert the object if it fails - for extensibility.
+ * @return The converted object.
+ */
+ public static Object convert(Object value, Class<?> aClass,
+ Converter converter) {
+ if (value == null) return null;
+ if (aClass == null) throw new IllegalArgumentException("Cannot convert to a null class.");
+ if (Void.class.isAssignableFrom(aClass)) throw new IllegalArgumentException("Cannot convert to void.");
+ if (aClass.isInstance(value) ) return value;
+
+ if (aClass.isAssignableFrom(String.class)) {
+
+ // TODO: Insert any specific conversions
+ return String.valueOf(value);
+ } else if (Boolean.class.isAssignableFrom(aClass)) {
+ if (value instanceof String) {
+ if (((String)value).equalsIgnoreCase("Yes")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("True")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("Y")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("T")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("1")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("Aye")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("Yar")) return Boolean.TRUE;
+ if (((String)value).equalsIgnoreCase("No")) return Boolean.FALSE;
+ if (((String)value).equalsIgnoreCase("False")) return Boolean.FALSE;
+ if (((String)value).equalsIgnoreCase("N")) return Boolean.FALSE;
+ if (((String)value).equalsIgnoreCase("F")) return Boolean.FALSE;
+ if (((String)value).equalsIgnoreCase("0")) return Boolean.FALSE;
+ if (((String)value).equalsIgnoreCase("Avast")) return Boolean.FALSE;
+ if (((String)value).equalsIgnoreCase("Nay")) return Boolean.FALSE;
+ throw new IllegalArgumentException("Cannot convert value '"+value+"' to a java.lang.Boolean");
+ }
+ if(value instanceof Number) {
+ return (((Number)value).intValue() != 0) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ } else if (aClass.isAssignableFrom(Byte.class)) {
+ if (value instanceof String) return Byte.valueOf((String)value);
+ if (value instanceof Number) return new Byte(((Number)value).byteValue());
+ if (value instanceof Boolean) return new Byte(((Boolean)value).booleanValue() ? BOOLEAN_TRUE_NUMERIC : BOOLEAN_FALSE_NUMERIC);
+ } else if (aClass.isAssignableFrom(Short.class)) {
+ if (value instanceof String) return Short.valueOf((String)value);
+ if (value instanceof Number) return new Short(((Number)value).shortValue());
+ if (value instanceof Boolean) return new Short(((Boolean)value).booleanValue() ? BOOLEAN_TRUE_NUMERIC : BOOLEAN_FALSE_NUMERIC);
+ } else if (aClass.isAssignableFrom(Integer.class)) {
+ if (value instanceof String) return Integer.valueOf((String)value);
+ if (value instanceof Number) return new Integer(((Number)value).intValue());
+ if (value instanceof Boolean) return new Integer(((Boolean)value).booleanValue() ? BOOLEAN_TRUE_NUMERIC : BOOLEAN_FALSE_NUMERIC);
+ } else if (aClass.isAssignableFrom(Long.class)) {
+ if (value instanceof String) return Long.valueOf((String)value);
+ if (value instanceof Number) return new Long(((Number)value).longValue());
+ if (value instanceof Boolean) return new Long(((Boolean)value).booleanValue() ? BOOLEAN_TRUE_NUMERIC : BOOLEAN_FALSE_NUMERIC);
+ } else if (aClass.isAssignableFrom(Float.class)) {
+ if (value instanceof String) return Float.valueOf((String)value);
+ if (value instanceof Number) return new Float(((Number)value).floatValue());
+ if (value instanceof Boolean) return new Float(((Boolean)value).booleanValue() ? BOOLEAN_TRUE_NUMERIC : BOOLEAN_FALSE_NUMERIC);
+ } else if (aClass.isAssignableFrom(Double.class)) {
+ if (value instanceof String) return Double.valueOf((String)value);
+ if (value instanceof Number) return new Double(((Number)value).doubleValue());
+ if (value instanceof Boolean) return new Double(((Boolean)value).booleanValue() ? BOOLEAN_TRUE_NUMERIC : BOOLEAN_FALSE_NUMERIC);
+ } else if (aClass.isAssignableFrom(Character.class)) {
+ if (value instanceof String) return new Character(((String)value).charAt(0));
+ if (value instanceof Number) return new Character((char)((Number)value).byteValue());
+ if (value instanceof Boolean) return new Character(((Boolean)value).booleanValue() ? 'T' : 'F');
+ }
+
+ if (value instanceof String) {
+ String stringVal = (String)value;
+ if (Float.class.isAssignableFrom(aClass)) return new Float((String)value);
+ if (Double.class.isAssignableFrom(aClass)) return new Double((String)value);
+ if (Byte.class.isAssignableFrom(aClass)) return new Byte((String)value);
+ if (Short.class.isAssignableFrom(aClass)) return new Short((String)value);
+ if (Integer.class.isAssignableFrom(aClass)) return new Integer((String)value);
+ if (Long.class.isAssignableFrom(aClass)) return new Long((String)value);
+ if (Character.class.isAssignableFrom(aClass)) return new Character(stringVal.charAt(0));
+ }
+
+ if (converter != null) return converter.convert(value,aClass);
+ throw new IllegalArgumentException("Don't know how to convert a String to a " + aClass);
+ }
+
+ public static Object convert(boolean object, Class<?> aClass) {
+ return convert(new Boolean(object),aClass);
+ }
+
+ public static Object convert(byte object, Class<?> aClass) {
+ return convert(new Byte(object),aClass);
+ }
+
+ public static Object convert(short object, Class<?> aClass) {
+ return convert(new Short(object),aClass);
+ }
+
+ public static Object convert(int object, Class<?> aClass) {
+ return convert(new Integer(object),aClass);
+ }
+
+ public static Object convert(long object, Class<?> aClass) {
+ return convert(new Long(object),aClass);
+ }
+
+ public static Object convert(float object, Class<?> aClass) {
+ return convert(new Float(object),aClass);
+ }
+
+ public static Object convert(double object, Class<?> aClass) {
+ return convert(new Double(object),aClass);
+ }
+
+ public static Object convert(char object, Class<?> aClass) {
+ return convert(new Character(object),aClass);
+ }
+
+ public static boolean convertToBoolean(Object object) {
+ return ((Boolean)convert(object,Boolean.class)).booleanValue();
+ }
+
+ public static byte convertToByte(Object object) {
+ return ((Number)convert(object,Byte.class)).byteValue();
+ }
+
+ public static short convertToShort(Object object) {
+ return ((Number)convert(object,Short.class)).shortValue();
+ }
+
+ public static int convertToInt(Object object) {
+ return ((Number)convert(object,Integer.class)).intValue();
+ }
+
+ public static long convertToLong(Object object) {
+ return ((Number)convert(object,Long.class)).longValue();
+ }
+
+ public static float convertToFloat(Object object) {
+ return ((Number)convert(object,Float.class)).floatValue();
+ }
+
+ public static double convertToDouble(Object object) {
+ return ((Number)convert(object,Double.class)).doubleValue();
+ }
+
+ public static char convertToChar(Object object) {
+ return ((Character)convert(object,Character.class)).charValue();
+ }
+
+}
diff --git a/israfil-foundation-core/src/test/conf/testng.xml b/israfil-foundation-core/src/test/conf/testng.xml new file mode 100644 index 0000000..45ec021 --- /dev/null +++ b/israfil-foundation-core/src/test/conf/testng.xml @@ -0,0 +1,24 @@ +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> +<!-- + Copyright 2007, 2008 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. +--> + +<suite name="Israfil Foundation Core" thread-count="5" annotations="1.5" verbose="2" parallel="tests"> + <test name="core"> + <packages> + <package name="net.israfil.foundation.core"/> + </packages> + </test> +</suite> diff --git a/israfil-foundation-core/src/test/java/net/israfil/foundation/core/SimpleCounterTest.java b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/SimpleCounterTest.java new file mode 100644 index 0000000..fc9c3d7 --- /dev/null +++ b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/SimpleCounterTest.java @@ -0,0 +1,61 @@ +/*
+ * Copyright (c) 2006-2009 Israfil Consulting Services Corporation
+ * Copyright (c) 2006-2009 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: SimpleCounterTest.java 640 2009-01-04 16:48:31Z christianedwardgruber $
+ */
+
+package net.israfil.foundation.core;
+
+import org.testng.annotations.Test;
+
+
+
+public class SimpleCounterTest{
+
+ @Test
+ public void testCounter() {
+ Counter c = new SimpleCounter();
+ assert c.getCount() == 0;
+ c.increment();
+ assert c.getCount() == 1;
+ c.increment();
+ assert c.getCount() == 2;
+ c.decrement();
+ assert c.getCount() == 1;
+ c.decrement();
+ assert c.getCount() == 0;
+ c.decrement();
+ assert c.getCount() == -1;
+ c.reset();
+ assert c.getCount() == 0;
+ }
+
+}
diff --git a/israfil-foundation-core/src/test/java/net/israfil/foundation/core/StringsTest.java b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/StringsTest.java new file mode 100644 index 0000000..8c67260 --- /dev/null +++ b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/StringsTest.java @@ -0,0 +1,90 @@ +/*
+ * Copyright © 2003-2009 Israfil Consulting Services Corporation
+ * Copyright © 2003-2009 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: StringsTest.java 640 2009-01-04 16:48:31Z christianedwardgruber $
+ */
+
+package net.israfil.foundation.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class StringsTest {
+ @Test
+ public void testCamel() {
+ assert "BlahFoo".equals(Strings.camel("blahFoo"));
+ assert "FooBar".equals(Strings.camel("FooBar"));
+ }
+
+ @Test
+ public void testCamelAllWords() {
+ assert "BlahFoo BlahBlahFoo".equals(Strings.camelAllWords("blahFoo blahBlahFoo", " "));
+ assert "FooBar::Foo::Bar::Bash".equals(Strings.camelAllWords("FooBar::foo::bar::bash", "::"));
+ }
+
+ @Test
+ public void testConcatenate() {
+ Assert.assertEquals("a:b:c:d",Strings.concatenate(":", "a","b","c","d"));
+ }
+
+ @Test
+ public void testConcatenateNull() {
+ Assert.assertEquals("",Strings.concatenate(":",(String[])null));
+ }
+ @Test
+ public void testConcatenateEmpty() {
+ Assert.assertEquals("",Strings.concatenate(":"));
+ }
+
+ @Test
+ public void testConcatenateIterable() {
+ List<String> strings = new ArrayList<String>();
+ strings.add("a");
+ strings.add("b");
+ strings.add("c");
+ strings.add("d");
+ Assert.assertEquals("a:b:c:d",Strings.concatenate(":", strings));
+ }
+
+ @Test
+ public void testConcatenateNullIterable() {
+ Assert.assertEquals("",Strings.concatenate(":",(Iterable<String>)null));
+ }
+ @Test
+ public void testEmpty() {
+ Assert.assertEquals("",Strings.concatenate(":", new ArrayList<String>()));
+ }
+
+}
diff --git a/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromBooleanTest.java b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromBooleanTest.java new file mode 100644 index 0000000..cffbc4f --- /dev/null +++ b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromBooleanTest.java @@ -0,0 +1,91 @@ +/*
+ * Copyright © 2003-2009 Israfil Consulting Services Corporation
+ * Copyright © 2003-2009 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: TypesFromBooleanTest.java 640 2009-01-04 16:48:31Z christianedwardgruber $
+ */
+
+package net.israfil.foundation.core;
+
+import org.testng.annotations.Test;
+
+
+public class TypesFromBooleanTest {
+
+ @Test
+ public void testConvertBooleanToboolean() {
+ assert Types.convertToBoolean(Boolean.TRUE) == true;
+ assert Types.convertToBoolean(Boolean.FALSE) == false;
+ }
+ @Test
+ public void testConvertBooleanToBoolean() {
+ assert new Boolean(true).equals(Types.convert(Boolean.TRUE,Boolean.class));
+ assert new Boolean(false).equals(Types.convert(Boolean.FALSE, Boolean.class));
+ }
+ @Test
+ public void testConvertBooleanToString() {
+ assert "true".equals(Types.convert(Boolean.TRUE, String.class));
+ assert "false".equals(Types.convert(Boolean.FALSE, String.class));
+ }
+ @Test
+ public void testConvertBooleanToByte() {
+ assert new Byte((byte)1).equals(Types.convert(Boolean.TRUE, Byte.class));
+ assert new Byte((byte)0).equals(Types.convert(Boolean.FALSE, Byte.class));
+ }
+ @Test
+ public void testConvertBooleanToShort() {
+ assert new Short((short)1).equals(Types.convert(Boolean.TRUE, Short.class));
+ assert new Short((short)0).equals(Types.convert(Boolean.FALSE, Short.class));
+ }
+ @Test
+ public void testConvertBooleanToInteger() {
+ assert new Integer(1).equals(Types.convert(Boolean.TRUE, Integer.class));
+ assert new Integer(0).equals(Types.convert(Boolean.FALSE, Integer.class));
+ }
+ @Test
+ public void testConvertBooleanToLong() {
+ assert new Long(1).equals(Types.convert(Boolean.TRUE, Long.class));
+ assert new Long(0).equals(Types.convert(Boolean.FALSE, Long.class));
+ }
+ @Test
+ public void testConvertBooleanToFloat() {
+ assert new Float(1.0).equals(Types.convert(Boolean.TRUE, Float.class));
+ assert new Float(0.0).equals(Types.convert(Boolean.FALSE, Float.class));
+ }
+ @Test
+ public void testConvertBooleanToDouble() {
+ assert new Double(1.0d).equals(Types.convert(Boolean.TRUE, Double.class));
+ assert new Double(0.0d).equals(Types.convert(Boolean.FALSE, Double.class));
+ }
+ @Test
+ public void testConvertBooleanToCharacter() {
+ assert new Character('T').equals(Types.convert(Boolean.TRUE, Character.class));
+ assert new Character('F').equals(Types.convert(Boolean.FALSE, Character.class));
+ }}
diff --git a/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromNumberTest.java b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromNumberTest.java new file mode 100644 index 0000000..ba32b95 --- /dev/null +++ b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromNumberTest.java @@ -0,0 +1,49 @@ +/*
+ * Copyright © 2003-2009 Israfil Consulting Services Corporation
+ * Copyright © 2003-2009 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: TypesFromNumberTest.java 640 2009-01-04 16:48:31Z christianedwardgruber $
+ */
+
+package net.israfil.foundation.core;
+
+import org.testng.annotations.Test;
+
+
+
+//@Copyright(years={"2006"},owner="Israfil Consulting Services Corporation",license="BSD")
+public class TypesFromNumberTest {
+
+ @Test
+ public void testConvertNumberToCharacter() {
+ throw new org.testng.SkipException("Not yet implemented");
+ }
+
+}
diff --git a/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromStringTest.java b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromStringTest.java new file mode 100644 index 0000000..2648d4f --- /dev/null +++ b/israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromStringTest.java @@ -0,0 +1,131 @@ +/*
+ * Copyright © 2003-2009 Israfil Consulting Services Corporation
+ * Copyright © 2003-2009 Christian Edward Gruber
+ * All Rights Reserved
+ *
+ * This software is licensed under the Berkeley Standard Distribution license,
+ * (BSD license), as defined below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Israfil Consulting Services 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.
+ *
+ * $Id: TypesFromStringTest.java 640 2009-01-04 16:48:31Z christianedwardgruber $
+ */
+
+package net.israfil.foundation.core;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TypesFromStringTest {
+
+ @Test
+ public void testConvertStringToboolean() {
+ Assert.assertTrue(Types.convertToBoolean("true"));
+ Assert.assertTrue(Types.convertToBoolean("t"));
+ Assert.assertTrue(Types.convertToBoolean("T"));
+ Assert.assertTrue(Types.convertToBoolean("True"));
+ Assert.assertTrue(Types.convertToBoolean("TrUe"));
+ Assert.assertTrue(Types.convertToBoolean("Yes"));
+ Assert.assertTrue(Types.convertToBoolean("y"));
+ Assert.assertTrue(Types.convertToBoolean("yes"));
+ Assert.assertTrue(Types.convertToBoolean("aye"));
+ Assert.assertFalse(Types.convertToBoolean("false"));
+ Assert.assertFalse(Types.convertToBoolean("f"));
+ Assert.assertFalse(Types.convertToBoolean("F"));
+ Assert.assertFalse(Types.convertToBoolean("False"));
+ Assert.assertFalse(Types.convertToBoolean("faLSe"));
+ Assert.assertFalse(Types.convertToBoolean("No"));
+ Assert.assertFalse(Types.convertToBoolean("n"));
+ Assert.assertFalse(Types.convertToBoolean("no"));
+ Assert.assertFalse(Types.convertToBoolean("nay"));
+ }
+ @Test(expectedExceptions={IllegalArgumentException.class})
+ public void testConvertEmptyStringToBoolean() {
+ Types.convertToBoolean("");
+ }
+ @Test(expectedExceptions={NullPointerException.class})
+ public void testConvertNullStringToBoolean() {
+ Types.convertToBoolean(null);
+ }
+ @Test(expectedExceptions={IllegalArgumentException.class})
+ public void testConvertNonNumberStringToBoolean() {
+ Types.convertToBoolean("bark");
+ }
+ @Test(expectedExceptions={IllegalArgumentException.class})
+ public void testConvertStringWithLeadingWhitespaceToBoolean() {
+ Types.convertToBoolean(" aye");
+ }
+ /*
+ @Test
+ public void testConvertStringToBoolean() {
+ Assert.assertEquals(new Boolean(true),Types.convert(Boolean.TRUE, Boolean.class));
+ Assert.assertEquals(new Boolean(false),Types.convert(Boolean.FALSE, Boolean.class));
+ }
+ */
+ @Test
+ public void testConvertStringToString() {
+ Assert.assertEquals("a",Types.convert("a", String.class));
+ Assert.assertSame("a",Types.convert("a", String.class));
+ Assert.assertFalse("A".equals(Types.convert("a", String.class)));
+ }
+ /*
+ @Test
+ public void testConvertBooleanToByte() {
+ Assert.assertEquals(new Byte((byte)1),Types.convert(Boolean.TRUE, Byte.class));
+ Assert.assertEquals(new Byte((byte)0),Types.convert(Boolean.FALSE, Byte.class));
+ }
+ @Test
+ public void testConvertBooleanToShort() {
+ Assert.assertEquals(new Short((short)1),Types.convert(Boolean.TRUE, Short.class));
+ Assert.assertEquals(new Short((short)0),Types.convert(Boolean.FALSE, Short.class));
+ }
+ @Test
+ public void testConvertBooleanToInteger() {
+ Assert.assertEquals(new Integer(1),Types.convert(Boolean.TRUE, Integer.class));
+ Assert.assertEquals(new Integer(0),Types.convert(Boolean.FALSE, Integer.class));
+ }
+ @Test
+ public void testConvertBooleanToLong() {
+ Assert.assertEquals(new Long(1),Types.convert(Boolean.TRUE, Long.class));
+ Assert.assertEquals(new Long(0),Types.convert(Boolean.FALSE, Long.class));
+ }
+ @Test
+ public void testConvertBooleanToFloat() {
+ Assert.assertEquals(new Float(1.0),Types.convert(Boolean.TRUE, Float.class));
+ Assert.assertEquals(new Float(0.0),Types.convert(Boolean.FALSE, Float.class));
+ }
+ @Test
+ public void testConvertBooleanToDouble() {
+ Assert.assertEquals(new Double(1.0d),Types.convert(Boolean.TRUE, Double.class));
+ Assert.assertEquals(new Double(0.0d),Types.convert(Boolean.FALSE, Double.class));
+ }
+ @Test
+ public void testConvertBooleanToCharacter() {
+ Assert.assertEquals(new Character('T'),Types.convert(Boolean.TRUE, Character.class));
+ Assert.assertEquals(new Character('F'),Types.convert(Boolean.FALSE, Character.class));
+ }
+ */
+
+}
|
