/** @tests java.text.MessageFormat#equals(java.lang.Object) */ @TestTargetNew( level = TestLevel.COMPLETE, method = "equals", args = {java.lang.Object.class}) public void test_equalsLjava_lang_Object() { // Test for method boolean // java.text.MessageFormat.equals(java.lang.Object) MessageFormat format1 = new MessageFormat("{0}"); MessageFormat format2 = new MessageFormat("{1}"); assertTrue("Should not be equal", !format1.equals(format2)); format2.applyPattern("{0}"); assertTrue("Should be equal", format1.equals(format2)); SimpleDateFormat date = (SimpleDateFormat) DateFormat.getTimeInstance(); format1.setFormat(0, DateFormat.getTimeInstance()); format2.setFormat(0, new SimpleDateFormat(date.toPattern())); assertTrue("Should be equal2", format1.equals(format2)); }
/** @tests java.text.MessageFormat#clone() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "clone", args = {}) public void test_clone() { // Test for method java.lang.Object java.text.MessageFormat.clone() MessageFormat format = new MessageFormat("'{'choice'}'{0}"); MessageFormat clone = (MessageFormat) format.clone(); assertTrue("Clone not equal", format.equals(clone)); assertEquals("Wrong answer", "{choice}{0}", format.format(new Object[] {})); clone.setFormat(0, DateFormat.getInstance()); assertTrue("Clone shares format data", !format.equals(clone)); format = (MessageFormat) clone.clone(); Format[] formats = clone.getFormats(); ((SimpleDateFormat) formats[0]).applyPattern("adk123"); assertTrue("Clone shares format data", !format.equals(clone)); }
private void checkSerialization(MessageFormat format) { try { ByteArrayOutputStream ba = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(ba); out.writeObject(format); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(ba.toByteArray())); MessageFormat read = (MessageFormat) in.readObject(); assertTrue("Not equal: " + format.toPattern(), format.equals(read)); } catch (IOException e) { fail("Format: " + format.toPattern() + " caused IOException: " + e); } catch (ClassNotFoundException e) { fail("Format: " + format.toPattern() + " caused ClassNotFoundException: " + e); } }