| Line | Hits | Note | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * $Id: ObjectUtilTest.java 1286 2009-03-07 20:06:15Z amandel $ | ||
| 3 | * | ||
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * Redistributions in binary form must reproduce the above | ||
| 13 | * copyright notice, this list of conditions and the following | ||
| 14 | * disclaimer in the documentation and/or other materials | ||
| 15 | * provided with the distribution. | ||
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of | ||
| 17 | * its contributors may be used to endorse or promote products | ||
| 18 | * derived from this software without specific prior written | ||
| 19 | * permission. | ||
| 20 | * | ||
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND | ||
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS | ||
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | */ | ||
| 33 | package org.jcoderz.commons.util; | ||
| 34 | |||
| 35 | import junit.framework.TestCase; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * JUnit test for {@link org.jcoderz.commons.util.ObjectUtil}. | ||
| 39 | * | ||
| 40 | * @author Michael Griffel | ||
| 41 | */ | ||
| 42 | 100 | public class ObjectUtilTest | |
| 43 | extends TestCase | ||
| 44 | { | ||
| 45 | /** | ||
| 46 | * Test the method {@link ObjectUtil#equals(Object, Object)}. | ||
| 47 | */ | ||
| 48 | public void testEquals () | ||
| 49 | { | ||
| 50 | 100 | final Object a = "Foo"; | |
| 51 | 100 | final Object b = "Bar"; | |
| 52 | 100 | (1) | assertTrue("Same instance should be equals", ObjectUtil.equals(a, a)); |
| 53 | 100 | assertFalse("Different instances should not be equal", | |
| 54 | ObjectUtil.equals(a, b)); | ||
| 55 | 100 | (2) | assertTrue("two null references should be equal", |
| 56 | ObjectUtil.equals(null, null)); | ||
| 57 | 100 | assertFalse("Should not be equals, if one reference is null", | |
| 58 | ObjectUtil.equals(a, null)); | ||
| 59 | 100 | assertFalse("Should not be equals, if one reference is null", | |
| 60 | ObjectUtil.equals(null, a)); | ||
| 61 | 100 | } | |
| 62 | |||
| 63 | /** Tests the {@link ObjectUtil#toString(Object)} method. */ | ||
| 64 | public void testToString () | ||
| 65 | { | ||
| 66 | 100 | assertNull("ObjectUtil.toString(null) should return null.", | |
| 67 | ObjectUtil.toString(null)); | ||
| 68 | 100 | assertEquals("ObjectUtil.toString(\"foo\") should return \"foo\".", | |
| 69 | (3) | "foo", ObjectUtil.toString("foo")); | |
| 70 | 100 | } | |
| 71 | |||
| 72 | /** Tests the {@link ObjectUtil#toStringOrEmpty(Object)} method. */ | ||
| 73 | public void testToStringOrEmpty () | ||
| 74 | { | ||
| 75 | 100 | assertEquals("ObjectUtil.toStringOrEmpty(null) should return \"\".", | |
| 76 | "", ObjectUtil.toStringOrEmpty(null)); | ||
| 77 | 100 | assertEquals("ObjectUtil.toStringOrEmpty(\"foo\") should return \"foo\".", | |
| 78 | "foo", ObjectUtil.toStringOrEmpty("foo")); | ||
| 79 | 100 | } | |
| 80 | } |