From 7c279747beb43c7e88633a6228a155a30e6834f7 Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Mon, 27 May 2024 11:38:33 -0400 Subject: Initial import --- .../israfil/foundation/core/SimpleCounterTest.java | 61 ++++++++++ .../net/israfil/foundation/core/StringsTest.java | 90 ++++++++++++++ .../foundation/core/TypesFromBooleanTest.java | 91 ++++++++++++++ .../foundation/core/TypesFromNumberTest.java | 49 ++++++++ .../foundation/core/TypesFromStringTest.java | 131 +++++++++++++++++++++ 5 files changed, 422 insertions(+) create mode 100644 israfil-foundation-core/src/test/java/net/israfil/foundation/core/SimpleCounterTest.java create mode 100644 israfil-foundation-core/src/test/java/net/israfil/foundation/core/StringsTest.java create mode 100644 israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromBooleanTest.java create mode 100644 israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromNumberTest.java create mode 100644 israfil-foundation-core/src/test/java/net/israfil/foundation/core/TypesFromStringTest.java (limited to 'israfil-foundation-core/src/test/java/net') 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 strings = new ArrayList(); + 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)null)); + } + @Test + public void testEmpty() { + Assert.assertEquals("",Strings.concatenate(":", new ArrayList())); + } + +} 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)); + } + */ + +} -- cgit v1.2.3