ICU-7950 Clean up test code for SelectFormat.
X-SVN-Rev: 28623
This commit is contained in:
parent
3220024a63
commit
755b0f2a56
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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<checkSyntaxData.length; ++i) {
|
||||
try {
|
||||
selFmt.applyPattern(checkSyntaxData[i]);
|
||||
errln("\nERROR: Unexpected result - SelectFormat Unit Test failed "
|
||||
+ "to detect syntax error with pattern: "+checkSyntaxData[i]);
|
||||
} catch (IllegalArgumentException e){
|
||||
assertEquals("Error:TestPatternSyntax failed with unexpected"
|
||||
+ " error message for pattern: " + checkSyntaxData[i] ,
|
||||
expectedErrorMsgs[i], e.getMessage() );
|
||||
continue;
|
||||
}
|
||||
SelectFormat selFmt = new SelectFormat(SIMPLE_PATTERN);
|
||||
for (int i=0; i<checkSyntaxData.length; ++i) {
|
||||
try {
|
||||
selFmt.applyPattern(checkSyntaxData[i]);
|
||||
errln("\nERROR: Unexpected result - SelectFormat Unit Test failed "
|
||||
+ "to detect syntax error with pattern: "+checkSyntaxData[i]);
|
||||
} catch (IllegalArgumentException e){
|
||||
assertEquals("Error:TestPatternSyntax failed with unexpected"
|
||||
+ " error message for pattern: " + checkSyntaxData[i] ,
|
||||
expectedErrorMsgs[i], e.getMessage() );
|
||||
continue;
|
||||
}
|
||||
} catch (Exception e){
|
||||
errln("Exception encountered in TestPatternSyntax ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,8 +73,6 @@ public class SelectFormatUnitTest extends TestFmwk {
|
||||
*/
|
||||
public void TestInvalidKeyword() {
|
||||
//Test formatting with invalid keyword
|
||||
log("Inside TestInvalidKeyword");
|
||||
|
||||
String keywords[] = {
|
||||
"9Keyword-_", //Starts with a digit
|
||||
"-Keyword-_", //Starts with a hyphen
|
||||
@ -102,9 +94,6 @@ public class SelectFormatUnitTest extends TestFmwk {
|
||||
+"error message for keyword: " + keywords[i]
|
||||
, expected , e.getMessage() );
|
||||
continue;
|
||||
} catch (Exception e){
|
||||
errln("ERROR:TestInvalidKeyword failed with an invalid keyword: "
|
||||
+ keywords[i] + " with exception: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,8 +104,6 @@ public class SelectFormatUnitTest extends TestFmwk {
|
||||
*/
|
||||
public void TestApplyFormat() {
|
||||
//Test applying and formatting with various pattern
|
||||
log("Inside TestApplyFormat");
|
||||
|
||||
String patternTestData[] = {
|
||||
"fem {femValue} other{even}",
|
||||
"other{odd or even}",
|
||||
@ -159,7 +146,7 @@ public class SelectFormatUnitTest extends TestFmwk {
|
||||
for (int i=0; i<patternTestData.length; ++i) {
|
||||
try {
|
||||
selFmt.applyPattern(patternTestData[i]);
|
||||
} catch (Exception e){
|
||||
} catch (IllegalArgumentException e){
|
||||
errln("ERROR: SelectFormat Unit Test failed to apply pattern- "
|
||||
+ patternTestData[i] );
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user