From 755b0f2a5631b9a40030b2ca25ddf88e45e6972d Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Wed, 15 Sep 2010 20:21:34 +0000 Subject: [PATCH] ICU-7950 Clean up test code for SelectFormat. X-SVN-Rev: 28623 --- .../dev/test/format/SelectFormatAPITest.java | 151 ++++++------------ .../dev/test/format/SelectFormatUnitTest.java | 37 ++--- 2 files changed, 59 insertions(+), 129 deletions(-) diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatAPITest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatAPITest.java index 7740467064..f3a9565a52 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatAPITest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatAPITest.java @@ -30,67 +30,49 @@ public class SelectFormatAPITest extends TestFmwk { * API tests for constructors */ public void TestConstructors() { - log("Inside TestConstructors"); - try { - SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN1); - assertNotNull("Error: TestConstructors - SelectFormat object constructed " - + "with argument constructor is null" , selFmt ); - } catch (Exception e){ - errln("Exception encountered in TestConstructors while creating a constructor with argument"); - } + SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN1); + assertNotNull("Error: TestConstructors - SelectFormat object constructed " + + "with argument constructor is null" , selFmt ); } /** * API tests for equals() method */ public void TestEquals() { - log("Inside TestEquals"); SelectFormat selFmt1 = null; //Check equality for pattern constructed SelectFormats - try { - selFmt1 = new SelectFormat(SIMPLE_PATTERN1); - SelectFormat selFmt2 = new SelectFormat(SIMPLE_PATTERN1); - assertTrue("Equals test failed while checking equality for " - + "pattern constructed SelectFormats ." - , selFmt1.equals(selFmt2) ); - } catch (Exception e){ - errln("Exception encountered in TestEquals 1 " + e.getMessage()); - } + selFmt1 = new SelectFormat(SIMPLE_PATTERN1); + SelectFormat selFmt2 = new SelectFormat(SIMPLE_PATTERN1); + assertTrue("Equals test failed while checking equality for " + + "pattern constructed SelectFormats ." + , selFmt1.equals(selFmt2) ); //Check equality for 2 objects - try { - Object selFmt3 = new SelectFormat(SIMPLE_PATTERN1); - Object selFmt4 = new SelectFormat(SIMPLE_PATTERN1); - Object selFmt5 = new SelectFormat(SIMPLE_PATTERN2); - assertTrue("Equals test failed while checking equality for object 1." - , selFmt3.equals(selFmt4) ); - assertTrue("Equals test failed while checking equality for object 2." - , selFmt1.equals(selFmt3) ); - assertFalse("Equals test failed while checking equality for object 3." - , selFmt3.equals(selFmt5) ); - } catch (Exception e){ - errln("Exception encountered in TestEquals 2" + e.getMessage()); - } + Object selFmt3 = new SelectFormat(SIMPLE_PATTERN1); + Object selFmt4 = new SelectFormat(SIMPLE_PATTERN1); + Object selFmt5 = new SelectFormat(SIMPLE_PATTERN2); + assertTrue("Equals test failed while checking equality for object 1." + , selFmt3.equals(selFmt4) ); + assertTrue("Equals test failed while checking equality for object 2." + , selFmt1.equals(selFmt3) ); + assertFalse("Equals test failed while checking equality for object 3." + , selFmt3.equals(selFmt5) ); } /** * API tests for applyPattern() method */ public void TestApplyPatternToPattern() { - log("Inside TestApplyPatternToPattern"); SelectFormat selFmt = null; String pattern = "masculine{masculineVerbValue} other{otherVerbValue}"; //Check for applyPattern/toPattern - try { - selFmt = new SelectFormat(SIMPLE_PATTERN1); - selFmt.applyPattern(pattern); - assertEquals("Failed in applyPattern,toPattern with unexpected output" - , pattern, selFmt.toPattern() ); - } catch (Exception e){ - errln("Exception encountered in TestApplyPatternToPattern"); - } + selFmt = new SelectFormat(SIMPLE_PATTERN1); + selFmt.applyPattern(pattern); + assertEquals("Failed in applyPattern,toPattern with unexpected output" + , pattern, selFmt.toPattern() ); + //Check for invalid pattern try { String brokenPattern = "broken }{ pattern"; @@ -105,96 +87,61 @@ public class SelectFormatAPITest extends TestFmwk { * API tests for toString() method */ public void TestToString(){ - log("Inside TestToString"); SelectFormat selFmt = null; //Check toString for pattern constructed SelectFormat - try { - selFmt = new SelectFormat(SIMPLE_PATTERN1); - String expected = "pattern='feminine {feminineVerbValue1} other{otherVerbValue1}'"; - assertEquals("Failed in TestToString with unexpected output 2" - , expected, selFmt.toString() ); - } catch (Exception e){ - errln("Exception encountered in TestToString 2"); - } + selFmt = new SelectFormat(SIMPLE_PATTERN1); + String expected = "pattern='feminine {feminineVerbValue1} other{otherVerbValue1}'"; + assertEquals("Failed in TestToString with unexpected output 2" + , expected, selFmt.toString() ); } /** * API tests for hashCode() method */ public void TestHashCode(){ - log("Inside TestHashCode"); - //Check hashCode for pattern constructed SelectFormat - try { - SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN1); - SelectFormat selFmt1 = new SelectFormat(SIMPLE_PATTERN1); - SelectFormat selFmt2 = new SelectFormat(SIMPLE_PATTERN2); - assertEquals("Failed in TestHashCode 1 with unexpected output" - , selFmt.hashCode(), selFmt1.hashCode() ); - assertNotEquals("Failed in TestHashCode 2 with unexpected output" - , selFmt.hashCode(), selFmt2.hashCode() ); - } catch (Exception e){ - errln("Exception encountered in TestHashCode 3 with message : " - + e.getMessage()); - } - + SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN1); + SelectFormat selFmt1 = new SelectFormat(SIMPLE_PATTERN1); + SelectFormat selFmt2 = new SelectFormat(SIMPLE_PATTERN2); + assertEquals("Failed in TestHashCode 1 with unexpected output" + , selFmt.hashCode(), selFmt1.hashCode() ); + assertNotEquals("Failed in TestHashCode 2 with unexpected output" + , selFmt.hashCode(), selFmt2.hashCode() ); } /** * API tests for toPattern() method */ public void TestToPattern(){ - log("Inside TestToPattern"); - SelectFormat selFmt = null; - - //Check toPattern for pattern constructed SelectFormat - try { - selFmt = new SelectFormat(SIMPLE_PATTERN1); - assertEquals("Failed in TestToPattern 2 with unexpected output" - , SIMPLE_PATTERN1, selFmt.toPattern() ); - } catch (Exception e){ - errln("Exception encountered in TestToPattern 2 with message : " - + e.getMessage()); - } + SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN1); + assertEquals("Failed in TestToPattern 2 with unexpected output" + , SIMPLE_PATTERN1, selFmt.toPattern() ); } /** * API tests for format() method */ public void TestFormat(){ - log("Inside TestFormat"); - //Check format for pattern constructed object - try { - SelectFormat selFmt1 = new SelectFormat(SIMPLE_PATTERN1); - String expected = "feminineVerbValue1"; - assertEquals("Failed in TestFormat with unexpected output 1" - , expected - , selFmt1.format("feminine") ); - } catch (Exception e){ - errln("Exception encountered in TestFormat 3: " + e.getMessage() ); - } + SelectFormat selFmt1 = new SelectFormat(SIMPLE_PATTERN1); + String expected = "feminineVerbValue1"; + assertEquals("Failed in TestFormat with unexpected output 1" + , expected + , selFmt1.format("feminine") ); //Check format with appendTo for pattern constructed object - try { - SelectFormat selFmt1 = new SelectFormat(SIMPLE_PATTERN1); - StringBuffer expected = new StringBuffer("AppendHere-otherVerbValue1"); - StringBuffer strBuf = new StringBuffer("AppendHere-"); - assertEquals("Failed in TestFormat with unexpected output 2" - , expected.toString() - , (selFmt1.format("other",strBuf, new FieldPosition(0))).toString() ); - } catch (Exception e){ - errln("Exception encountered in TestFormat 2: " + e.getMessage() ); - } + expected = "AppendHere-otherVerbValue1"; + StringBuffer strBuf = new StringBuffer("AppendHere-"); + assertEquals("Failed in TestFormat with unexpected output 2" + , expected + , (selFmt1.format("other", strBuf, new FieldPosition(0))).toString()); } /** * API tests for parseObject() method */ public void TestParseObject(){ - log("Inside TestToPattern"); - //Check parseObject try { SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN1); @@ -202,11 +149,7 @@ public class SelectFormatAPITest extends TestFmwk { fail("Failed in TestParseObject - UnsupportedOperationException not received"); } catch (UnsupportedOperationException e){ //Expect this Exception - } catch (Exception e){ - errln("Exception encountered in TestParseObject with message : " - + e.getMessage()); - } + } } - } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatUnitTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatUnitTest.java index 04f465e89d..37d4529b51 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatUnitTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/SelectFormatUnitTest.java @@ -26,8 +26,6 @@ public class SelectFormatUnitTest extends TestFmwk { * Unit tests for pattern syntax */ public void TestPatternSyntax() { - log("Inside TestPatternSyntax"); - String checkSyntaxData[] = { "odd{foo} odd{bar} other{foobar}", "odd{foo} other{bar} other{foobar}", @@ -55,22 +53,18 @@ public class SelectFormatUnitTest extends TestFmwk { }; //Test SelectFormat pattern syntax - try { - SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN); - for (int i=0; i