//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// J2ME-Lib source file created in 2006
// Copyright (c) 2006 esoco GmbH/Elmar Sonnenschein
//
// J2ME-Lib is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// J2ME-Lib 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with J2ME-Lib; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or use the contact
// information from the GNU website http://www.gnu.org
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.j2me.util;
import j2meunit.framework.Test;
import j2meunit.framework.TestCase;
import j2meunit.framework.TestMethod;
import j2meunit.framework.TestSuite;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/********************************************************************
* Test suite for the IntArray class.
*
* @author eso
*/
public class PropertiesTest extends TestCase
{
//~ Static fields/initializers ---------------------------------------------
private static final String sCorrectProperties = "A=1\nB=12\n" +
"Key1=\nKey2= Val2\n" +
" Key3 \t =Val3\t \n" +
"ML=1\\n2\r\n";
//~ Constructors -----------------------------------------------------------
/***************************************
* Default constructor.
*/
public PropertiesTest()
{
}
/***************************************
* TestOne constructor for a particular method.
*
* @see TestCase#TestCase(String, TestMethod)
*/
public PropertiesTest(String sTestName, TestMethod rTestMethod)
{
super(sTestName, rTestMethod);
}
//~ Methods ----------------------------------------------------------------
/***************************************
* To create the test suite.
*
* @see TestCase#suite()
*/
public Test suite()
{
TestSuite aSuite = new TestSuite();
aSuite.addTest(new PropertiesTest("testLoadProperties",
new TestMethod()
{
public void run(TestCase tc)
throws IOException
{
((PropertiesTest) tc)
.testLoadProperties();
}
}));
return aSuite;
}
/***************************************
* Test loading properties from a file.
*
* @throws IOException
*/
public void testLoadProperties() throws IOException
{
Properties p = new Properties();
p.load(new InputStreamReader(new ByteArrayInputStream(sCorrectProperties
.getBytes())));
assertTrue(p.get("A").equals("1"));
assertTrue(p.get("B").equals("12"));
assertTrue(p.get("Key1").equals(""));
assertTrue(p.get("Key2").equals("Val2"));
assertTrue(p.get("Key3").equals("Val3"));
assertTrue(p.get("ML").equals("1\n2"));
}
}