1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2007 - 2009 Pentaho Corporation and Contributors. All rights reserved.
*/
package org.pentaho.reporting.libraries.base.util;
import junit.framework.TestCase;
import org.pentaho.reporting.libraries.base.util.StringUtils;
/**
* Tests for the <code>StringUtils</code> class.
* @author David Kincade
*/
public class StringUtilsTest extends TestCase
{
public void testIsEmpty()
{
// TRUE
assertTrue(StringUtils.isEmpty(null));
assertTrue(StringUtils.isEmpty(""));
assertTrue(StringUtils.isEmpty(" "));
assertTrue(StringUtils.isEmpty("\t\n \t"));
assertTrue(StringUtils.isEmpty(null, true));
assertTrue(StringUtils.isEmpty("", true));
assertTrue(StringUtils.isEmpty(" ", true));
assertTrue(StringUtils.isEmpty("\t\n \t", true));
assertTrue(StringUtils.isEmpty(null, false));
assertTrue(StringUtils.isEmpty("", false));
// FALSE
assertTrue(!StringUtils.isEmpty("test"));
assertTrue(!StringUtils.isEmpty(" test "));
assertTrue(!StringUtils.isEmpty("test", true));
assertTrue(!StringUtils.isEmpty(" test ", true));
assertTrue(!StringUtils.isEmpty(" ", false));
assertTrue(!StringUtils.isEmpty("\t\n \t", false));
assertTrue(!StringUtils.isEmpty("test", false));
assertTrue(!StringUtils.isEmpty(" test ", false));
}
public void testToBoolean()
{
// TRUE
assertTrue(StringUtils.toBoolean("true"));
assertTrue(StringUtils.toBoolean("on"));
assertTrue(StringUtils.toBoolean("yes"));
assertTrue(StringUtils.toBoolean("TRUE"));
assertTrue(StringUtils.toBoolean("ON"));
assertTrue(StringUtils.toBoolean("YES"));
assertTrue(StringUtils.toBoolean("tRUe"));
assertTrue(StringUtils.toBoolean("oN"));
assertTrue(StringUtils.toBoolean("yEs"));
assertTrue(StringUtils.toBoolean(" true "));
assertTrue(StringUtils.toBoolean("\t on \t"));
assertTrue(StringUtils.toBoolean(" \nyes\n "));
assertTrue(StringUtils.toBoolean(" TRUE "));
assertTrue(StringUtils.toBoolean("\t ON \t"));
assertTrue(StringUtils.toBoolean(" \fYES\f "));
assertTrue(StringUtils.toBoolean(" tRUe "));
assertTrue(StringUtils.toBoolean("\t oN \t"));
assertTrue(StringUtils.toBoolean(" \u0009yEs\u0009 "));
assertTrue(StringUtils.toBoolean("true", false));
assertTrue(StringUtils.toBoolean("on", false));
assertTrue(StringUtils.toBoolean("yes", false));
assertTrue(StringUtils.toBoolean("TRUE", false));
assertTrue(StringUtils.toBoolean("ON", false));
assertTrue(StringUtils.toBoolean("YES", false));
assertTrue(StringUtils.toBoolean("tRUe", false));
assertTrue(StringUtils.toBoolean("oN", false));
assertTrue(StringUtils.toBoolean("yEs", false));
assertTrue(StringUtils.toBoolean(" true ", false));
assertTrue(StringUtils.toBoolean("\t on \t", false));
assertTrue(StringUtils.toBoolean(" \nyes\n ", false));
assertTrue(StringUtils.toBoolean(" TRUE ", false));
assertTrue(StringUtils.toBoolean("\t ON \t", false));
assertTrue(StringUtils.toBoolean(" \fYES\f ", false));
assertTrue(StringUtils.toBoolean(" tRUe ", false));
assertTrue(StringUtils.toBoolean("\t oN \t", false));
assertTrue(StringUtils.toBoolean(" \u0009yEs\u0009 ", false));
assertTrue(StringUtils.toBoolean("true", true));
assertTrue(StringUtils.toBoolean("on", true));
assertTrue(StringUtils.toBoolean("yes", true));
assertTrue(StringUtils.toBoolean("TRUE", true));
assertTrue(StringUtils.toBoolean("ON", true));
assertTrue(StringUtils.toBoolean("YES", true));
assertTrue(StringUtils.toBoolean("tRUe", true));
assertTrue(StringUtils.toBoolean("oN", true));
assertTrue(StringUtils.toBoolean("yEs", true));
assertTrue(StringUtils.toBoolean(" true ", true));
assertTrue(StringUtils.toBoolean("\t on \t", true));
assertTrue(StringUtils.toBoolean(" \nyes\n ", true));
assertTrue(StringUtils.toBoolean(" TRUE ", true));
assertTrue(StringUtils.toBoolean("\t ON \t", true));
assertTrue(StringUtils.toBoolean(" \fYES\f ", true));
assertTrue(StringUtils.toBoolean(" tRUe ", true));
assertTrue(StringUtils.toBoolean("\t oN \t", true));
assertTrue(StringUtils.toBoolean(" \u0009yEs\u0009 ", true));
assertTrue(StringUtils.toBoolean(null, true));
// FALSE
assertTrue(!StringUtils.toBoolean(null));
assertTrue(!StringUtils.toBoolean("false"));
assertTrue(!StringUtils.toBoolean("off"));
assertTrue(!StringUtils.toBoolean("no"));
assertTrue(!StringUtils.toBoolean("FALSE"));
assertTrue(!StringUtils.toBoolean("NO"));
assertTrue(!StringUtils.toBoolean("OFF"));
assertTrue(!StringUtils.toBoolean("fALSe"));
assertTrue(!StringUtils.toBoolean("oFf"));
assertTrue(!StringUtils.toBoolean("nO"));
assertTrue(!StringUtils.toBoolean(" false "));
assertTrue(!StringUtils.toBoolean(" \t off \t "));
assertTrue(!StringUtils.toBoolean("\n no \n"));
assertTrue(!StringUtils.toBoolean("true.", true));
assertTrue(!StringUtils.toBoolean("onn", true));
assertTrue(!StringUtils.toBoolean("yes!", true));
assertTrue(!StringUtils.toBoolean("false", true));
assertTrue(!StringUtils.toBoolean("off", true));
assertTrue(!StringUtils.toBoolean("no", true));
assertTrue(!StringUtils.toBoolean("FALSE", true));
assertTrue(!StringUtils.toBoolean("NO", true));
assertTrue(!StringUtils.toBoolean("OFF", true));
assertTrue(!StringUtils.toBoolean("fALSe", true));
assertTrue(!StringUtils.toBoolean("oFf", true));
assertTrue(!StringUtils.toBoolean("nO", true));
assertTrue(!StringUtils.toBoolean(" false ", true));
assertTrue(!StringUtils.toBoolean(" \t off \t ", true));
assertTrue(!StringUtils.toBoolean("\n no \n", true));
assertTrue(!StringUtils.toBoolean("true.", false));
assertTrue(!StringUtils.toBoolean("onn", false));
assertTrue(!StringUtils.toBoolean("yes!", false));
assertTrue(!StringUtils.toBoolean("false", false));
assertTrue(!StringUtils.toBoolean("off", false));
assertTrue(!StringUtils.toBoolean("no", false));
assertTrue(!StringUtils.toBoolean("FALSE", false));
assertTrue(!StringUtils.toBoolean("NO", false));
assertTrue(!StringUtils.toBoolean("OFF", false));
assertTrue(!StringUtils.toBoolean("fALSe", false));
assertTrue(!StringUtils.toBoolean("oFf", false));
assertTrue(!StringUtils.toBoolean("nO", false));
assertTrue(!StringUtils.toBoolean(" false ", false));
assertTrue(!StringUtils.toBoolean(" \t off \t ", false));
assertTrue(!StringUtils.toBoolean("\n no \n", false));
assertTrue(!StringUtils.toBoolean("true.", false));
assertTrue(!StringUtils.toBoolean("onn", false));
assertTrue(!StringUtils.toBoolean("yes!", false));
assertTrue(!StringUtils.toBoolean(null, false));
}
}
|