001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.test;
016    
017    import com.liferay.portal.kernel.util.MapUtil;
018    
019    import java.io.InputStream;
020    
021    import java.sql.Blob;
022    
023    import java.util.Map;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class TestCase extends junit.framework.TestCase {
029    
030            protected void assertEquals(Blob expectedBlob, Blob actualBlob)
031                    throws Exception {
032    
033                    InputStream expectInputStream = expectedBlob.getBinaryStream();
034                    InputStream actualInputStream = actualBlob.getBinaryStream();
035    
036                    while (true) {
037                            int expectValue = expectInputStream.read();
038                            int actualValue = actualInputStream.read();
039    
040                            assertEquals(expectValue, actualValue);
041    
042                            if (expectValue == -1) {
043                                    break;
044                            }
045                    }
046    
047                    expectInputStream.close();
048                    actualInputStream.close();
049            }
050    
051            protected void assertEquals(double expectedDouble, double actualDouble)
052                    throws Exception {
053    
054                    assertEquals(expectedDouble, actualDouble, 0);
055            }
056    
057            protected void assertEquals(
058                    Map<String, ?> expectedMap, Map<String, ?> actualMap) {
059    
060                    assertEquals(
061                            "The maps are different sizes", expectedMap.size(),
062                            actualMap.size());
063    
064                    for (String name : expectedMap.keySet()) {
065                            assertEquals(
066                                    "The values for key '" + name + "' are different",
067                                    MapUtil.getString(expectedMap, name),
068                                    MapUtil.getString(actualMap, name));
069                    }
070            }
071    
072            protected void assertEqualsIgnoreCase(
073                    String expectedString, String actualString) {
074    
075                    if (expectedString != null) {
076                            expectedString = expectedString.toLowerCase();
077                    }
078    
079                    if (actualString != null) {
080                            actualString = actualString.toLowerCase();
081                    }
082    
083                    assertEquals(expectedString, actualString);
084            }
085    
086            protected void assertLessThan(double expectedDouble, double actualDouble)
087                    throws Exception {
088    
089                    if (actualDouble > expectedDouble) {
090                            fail(actualDouble + " is not less than " + expectedDouble);
091                    }
092            }
093    
094    }