Skip to content

Commit

Permalink
Improved: Turn ‘UtilPropertiesTests’ into a unit test class
Browse files Browse the repository at this point in the history
(OFBIZ-11067)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1859975 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed May 25, 2019
1 parent 402db94 commit 0dede26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -15,8 +15,12 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.apache.ofbiz.base.util.test;
*/
package org.apache.ofbiz.base.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -25,24 +29,21 @@
import java.util.Locale;
import java.util.Properties;

import org.apache.ofbiz.base.test.GenericTestCaseBase;
import org.apache.ofbiz.base.util.UtilProperties;
import org.junit.Test;

public class UtilPropertiesTests extends GenericTestCaseBase {
public class UtilPropertiesTests {

private static final String country = "AU";
private static final String language = "en";
private final Locale locale = new Locale(language, country);

public UtilPropertiesTests(String name) {
super(name);
}

/**
* Old style xml:lang attribute value was of form en_AU. Test this
* format still works.
* @throws Exception
*/
@Test
public void testReadXmlLangOldStyle() throws Exception {
Properties result = xmlToProperties("_");
assertNotNull(result);
Expand All @@ -56,13 +57,13 @@ public void testReadXmlLangOldStyle() throws Exception {
* Test it works.
* @throws Exception
*/
@Test
public void testReadXmlLangNewStyle() throws Exception {
Properties result = xmlToProperties("-");
assertNotNull(result);
assertTrue(!result.isEmpty());
assertEquals(1, result.size());
assertEquals("Key Value", result.getProperty("PropertyKey"));

}

private Properties xmlToProperties(String separator) throws IOException {
Expand All @@ -75,8 +76,9 @@ private Properties xmlToProperties(String separator) throws IOException {
"\">Key Value</value>\n" +
" </property>\n" +
"</resource>";
try (InputStream in = new ByteArrayInputStream(new String(xmlData.getBytes(), Charset.forName("UTF-8")).getBytes())) {
return UtilProperties.xmlToProperties(in, locale, null);
try (InputStream in = new ByteArrayInputStream(
new String(xmlData.getBytes(), Charset.forName("UTF-8")).getBytes())) {
return UtilProperties.xmlToProperties(in, locale, null);
}
}
}
1 change: 0 additions & 1 deletion framework/base/testdef/basetests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.TestJSONConverters"/>
<!--junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilIOTests"/-->
<junit-test-suite class-name="org.apache.ofbiz.base.test.BaseUnitTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilPropertiesTests"/>
<groovy-test-suite name="simple" location="component://base/groovyScripts/test/SimpleTests.groovy"/>
</test-group>
</test-suite>

0 comments on commit 0dede26

Please sign in to comment.