You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/26 01:04:16 UTC
svn commit: r479240 [11/28] -
/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java?view=diff&rev=479240&r1=479239&r2=479240
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPaneTest.java Sat Nov 25 16:04:10 2006
@@ -43,43 +43,42 @@
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyledEditorKit;
+
//import javax.swing.text.html.HTMLEditorKit;
//import javax.swing.text.rtf.RTFEditorKit;
-
public class JEditorPaneTest extends SwingTestCase {
- JEditorPane jep;
+ JEditorPane jep;
- JEditorPane jep1;
+ JEditorPane jep1;
- JFrame jf;
+ JFrame jf;
- String fireOrder;
+ String fireOrder;
static final String plainString = "justPlain";
- static final String rtfString = "{\\rtf1\\ansi\\ansicpg1251\\deff0\\deflang1049{\\fonttbl{\\fswiss\\fcharset0 Arial;}}\n"
- + "{\\*\\generator Msftedit 5.41.15.1503;}\\viewkind4\\uc1\\pard\\lang1033\\f0\\fs20 blablabla\\par\n"
- + "}\n";
-
- static final String htmlString = "<html>"
- + " <head>"
- + " <meta http-equiv=\"Content-Typecontent=text/html;\" charset=\"iso-8859-1\">"
- + " <meta content=\"MSHTML5.50.4522.1800\" name=\"GENERATOR\">"
- + " "
- + " </head>"
- + " <body>"
- + " <div bgcolor=\"#ffffff\">"
- + " <div>"
- + " <font size=\"4\">Thank you for the quote you sentreguarding account"
- + " #99999999999999. &160;I just have a couple of questions.Please let me"
- + " know. </font>"
- + " </div>"
- + " <div>"
- + " <font size=\"4\">    Thank you, we look forward to hearing from you.</font>"
- + " </div>" + " </div>"
- + " </body>" + "</html>";
+ static final String rtfString = "{\\rtf1\\ansi\\ansicpg1251\\deff0\\deflang1049{\\fonttbl{\\fswiss\\fcharset0 Arial;}}\n"
+ + "{\\*\\generator Msftedit 5.41.15.1503;}\\viewkind4\\uc1\\pard\\lang1033\\f0\\fs20 blablabla\\par\n"
+ + "}\n";
+
+ static final String htmlString = "<html>"
+ + " <head>"
+ + " <meta http-equiv=\"Content-Typecontent=text/html;\" charset=\"iso-8859-1\">"
+ + " <meta content=\"MSHTML5.50.4522.1800\" name=\"GENERATOR\">"
+ + " "
+ + " </head>"
+ + " <body>"
+ + " <div bgcolor=\"#ffffff\">"
+ + " <div>"
+ + " <font size=\"4\">Thank you for the quote you sentreguarding account"
+ + " #99999999999999. &160;I just have a couple of questions.Please let me"
+ + " know. </font>"
+ + " </div>"
+ + " <div>"
+ + " <font size=\"4\">    Thank you, we look forward to hearing from you.</font>"
+ + " </div>" + " </div>" + " </body>" + "</html>";
- final URL TEST_URL;
+ final URL TEST_URL;
{
URL tmpUrl = null;
try {
@@ -90,6 +89,7 @@
TEST_URL = tmpUrl;
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
timeoutDelay = 10 * DEFAULT_TIMEOUT_DELAY;
@@ -105,13 +105,14 @@
jf.setSize(200, 300);
}
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
}
final class SimpleHyperlinkListener implements HyperlinkListener {
- String name;
+ String name;
HyperlinkEvent event;
@@ -126,15 +127,19 @@
}
static final class SimpleEditorKit extends DefaultEditorKit {
- boolean wasCallInstall = false;
+ private static final long serialVersionUID = 1L;
+
+ boolean wasCallInstall = false;
boolean wasCallDeinstall = false;
+ @Override
public void deinstall(final JEditorPane jep) {
wasCallDeinstall = true;
super.deinstall(jep);
}
+ @Override
public void install(final JEditorPane jep) {
wasCallInstall = true;
super.install(jep);
@@ -162,20 +167,21 @@
final class SimpleClassLoader extends ClassLoader {
boolean wasCallLoadClass = false;
- public Class loadClass(final String s) throws ClassNotFoundException {
+ @Override
+ public Class<?> loadClass(final String s) throws ClassNotFoundException {
wasCallLoadClass = true;
return super.loadClass(s);
}
- protected synchronized Class loadClass(final String s, final boolean b)
+ @Override
+ protected synchronized Class<?> loadClass(final String s, final boolean b)
throws ClassNotFoundException {
wasCallLoadClass = true;
return super.loadClass(s, b);
}
}
- private void assertEquals(final PropertyChangeEvent event1,
- final PropertyChangeEvent event2) {
+ private void assertEquals(final PropertyChangeEvent event1, final PropertyChangeEvent event2) {
assertNotNull(event1);
assertNotNull(event2);
assertEquals(event1.getPropertyName(), event2.getPropertyName());
@@ -191,18 +197,18 @@
if (isHarmony()) {
AccessibleContext accessibleContext = jep.getAccessibleContext();
assertEquals("javax.swing.JEditorPane$AccessibleJEditorPane",
- getClassName(accessibleContext));
+ getClassName(accessibleContext));
assertEquals(jep.getAccessibleContext(), accessibleContext);
- jep.setContentType("text/html");
- assertEquals("javax.swing.JEditorPane$AccessibleJEditorPaneHTML",
- getClassName(jep.getAccessibleContext()));
+ jep.setContentType("text/html");
+ assertEquals("javax.swing.JEditorPane$AccessibleJEditorPaneHTML", getClassName(jep
+ .getAccessibleContext()));
}
}
public void testGetPreferredSize() {
if (isHarmony()) {
- jep1.setMinimumSize(new Dimension(3,3));
- JViewport parent = (JViewport)jep1.getParent();
+ jep1.setMinimumSize(new Dimension(3, 3));
+ JViewport parent = (JViewport) jep1.getParent();
Dimension minSize = jep1.getMinimumSize();
parent.setSize(new Dimension(minSize.width - 1, minSize.height - 1));
assertEquals(minSize, jep1.getPreferredSize());
@@ -214,16 +220,15 @@
}
public void testGetScrollableTracksViewportWidthHeight() {
- JViewport parent = (JViewport)jep1.getParent();
- jep1.setMinimumSize(new Dimension(3,3));
+ JViewport parent = (JViewport) jep1.getParent();
+ jep1.setMinimumSize(new Dimension(3, 3));
Dimension minSize = jep1.getMinimumSize();
parent.setSize(new Dimension(minSize.width - 1, minSize.height - 1));
assertFalse(jep1.getScrollableTracksViewportHeight());
assertFalse(jep1.getScrollableTracksViewportWidth());
}
- private AttributeSet getAttributeSetByIndex(final AbstractDocument d,
- final int offset) {
+ private AttributeSet getAttributeSetByIndex(final AbstractDocument d, final int offset) {
AttributeSet as = null;
Element elem = d.getDefaultRootElement();
while (elem.getElementCount() > 0) {
@@ -237,23 +242,19 @@
jep.setText("testReplaceSelection");
jep.setSelectionStart(4);
jep.setSelectionEnd(7);
-
jep.replaceSelection("XXX");
assertEquals("testXXXlaceSelection", jep.getText());
assertNull(jep.getSelectedText());
-
jep.setSelectionStart(2);
jep.setSelectionEnd(4);
jep.replaceSelection(null);
assertEquals("teXXXlaceSelection", jep.getText());
assertNull(jep.getSelectedText());
-
jep.setSelectionStart(0);
jep.setSelectionEnd(2);
jep.replaceSelection(null);
assertEquals("XXXlaceSelection", jep.getText());
assertNull(jep.getSelectedText());
-
jep.setCaretPosition(3);
jep.replaceSelection("YYY");
assertEquals("XXXYYYlaceSelection", jep.getText());
@@ -279,7 +280,6 @@
as1.addAttribute("key1", "value1");
SimpleAttributeSet as2 = new SimpleAttributeSet();
as2.addAttribute("key2", "value2");
-
try {
doc.insertString(0, "testReplaceSelection", as1);
doc.insertString(4, "INSERT", as2);
@@ -290,17 +290,16 @@
//jep.setEditorKit(new RTFEditorKit());
jep.setEditorKit(new StyledEditorKit());
jep.setDocument(doc);
-
jep.setSelectionStart(6);
jep.setSelectionEnd(7);
jep.replaceSelection("YYY");
-
for (int i = 0; i < doc.getLength(); i++) {
AttributeSet as = getAttributeSetByIndex(doc, i);
- if (i > 3 && i < 12)
+ if (i > 3 && i < 12) {
assertEquals(as2, as);
- else
+ } else {
assertEquals(as1, as);
+ }
}
}
@@ -319,68 +318,60 @@
}
jep.setText(plainString);
assertEquals("plain", plainString, jep.getText());
-
jep.setContentType("text/rtf");
-
jep.setText(rtfString);
assertEquals("blablabla\n", getDocContent(jep.getDocument()));
-
jep.setContentType("text/html");
jep.setText(htmlString);
- assertEquals(removeMeta(htmlString), removeMeta(jep.getText()
- .replaceAll("\n", "")));
+ assertEquals(removeMeta(htmlString), removeMeta(jep.getText().replaceAll("\n", "")));
}
+
// commented due to unimplemented functionality
/*public void testCreateEditorKitForContentType() {
- String content = "testCreateEditorKitForContentType";
- assertNull(JEditorPane.createEditorKitForContentType(content));
- JEditorPane
- .registerEditorKitForContentType(content,
- "javax.swing.text.DefaultEditorKit");
- EditorKit rtfKit1 = JEditorPane
- .createEditorKitForContentType("text/rtf");
- EditorKit rtfKit2 = JEditorPane
- .createEditorKitForContentType("text/rtf");
- EditorKit htmlKit1 = JEditorPane
- .createEditorKitForContentType("text/html");
- EditorKit htmlKit2 = JEditorPane
- .createEditorKitForContentType("text/html");
- EditorKit plainKit1 = JEditorPane
- .createEditorKitForContentType("text/plain");
-
- EditorKit plainKit2 = JEditorPane
- .createEditorKitForContentType("text/plain");
- EditorKit contentKit1 = JEditorPane
- .createEditorKitForContentType(content);
- EditorKit contentKit2 = JEditorPane
- .createEditorKitForContentType(content);
-
- assertEquals("javax.swing.text.rtf.RTFEditorKit", getClassName(rtfKit1));
- assertEquals("javax.swing.text.html.HTMLEditorKit",
- getClassName(htmlKit1));
- assertEquals("javax.swing.JEditorPane$PlainEditorKit",
- getClassName(plainKit1));
- assertEquals("javax.swing.text.DefaultEditorKit",
- getClassName(contentKit1));
-
- assertNotSame(rtfKit1, rtfKit2);
- assertNotSame(htmlKit1, htmlKit2);
- assertNotSame(plainKit1, plainKit2);
- assertNotSame(contentKit1, contentKit2);
- }*/
-
+ String content = "testCreateEditorKitForContentType";
+ assertNull(JEditorPane.createEditorKitForContentType(content));
+ JEditorPane
+ .registerEditorKitForContentType(content,
+ "javax.swing.text.DefaultEditorKit");
+ EditorKit rtfKit1 = JEditorPane
+ .createEditorKitForContentType("text/rtf");
+ EditorKit rtfKit2 = JEditorPane
+ .createEditorKitForContentType("text/rtf");
+ EditorKit htmlKit1 = JEditorPane
+ .createEditorKitForContentType("text/html");
+ EditorKit htmlKit2 = JEditorPane
+ .createEditorKitForContentType("text/html");
+ EditorKit plainKit1 = JEditorPane
+ .createEditorKitForContentType("text/plain");
+
+ EditorKit plainKit2 = JEditorPane
+ .createEditorKitForContentType("text/plain");
+ EditorKit contentKit1 = JEditorPane
+ .createEditorKitForContentType(content);
+ EditorKit contentKit2 = JEditorPane
+ .createEditorKitForContentType(content);
+
+ assertEquals("javax.swing.text.rtf.RTFEditorKit", getClassName(rtfKit1));
+ assertEquals("javax.swing.text.html.HTMLEditorKit",
+ getClassName(htmlKit1));
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit",
+ getClassName(plainKit1));
+ assertEquals("javax.swing.text.DefaultEditorKit",
+ getClassName(contentKit1));
+
+ assertNotSame(rtfKit1, rtfKit2);
+ assertNotSame(htmlKit1, htmlKit2);
+ assertNotSame(plainKit1, plainKit2);
+ assertNotSame(contentKit1, contentKit2);
+ }*/
public void testRegisterEditorKitForContentTypeStringString() {
- JEditorPane
- .registerEditorKitForContentType("text/test1",
- "javax.swing.text.DefaultEditorKit");
+ JEditorPane.registerEditorKitForContentType("text/test1",
+ "javax.swing.text.DefaultEditorKit");
assertEquals("javax.swing.text.DefaultEditorKit", JEditorPane
.getEditorKitClassNameForContentType("text/test1"));
-
JEditorPane.registerEditorKitForContentType("text/test1", "");
-
- JEditorPane
- .registerEditorKitForContentType("text/test1",
- "javax.swing.JEditorPaneTest$SimpleEditorKit");
+ JEditorPane.registerEditorKitForContentType("text/test1",
+ "javax.swing.JEditorPaneTest$SimpleEditorKit");
assertEquals("javax.swing.JEditorPaneTest$SimpleEditorKit", JEditorPane
.getEditorKitClassNameForContentType("text/test1"));
}
@@ -390,40 +381,30 @@
throw new UnsupportedOperationException("Not implemented");
}
SimpleClassLoader cl = new SimpleClassLoader();
-
cl.wasCallLoadClass = false;
- JEditorPane
- .registerEditorKitForContentType(
- "content1",
- "javax.swing.text.DefaultEditorKit",
- cl);
- JEditorPane
- .registerEditorKitForContentType("content2",
- "javax.swing.text.DefaultEditorKit");
+ JEditorPane.registerEditorKitForContentType("content1",
+ "javax.swing.text.DefaultEditorKit", cl);
+ JEditorPane.registerEditorKitForContentType("content2",
+ "javax.swing.text.DefaultEditorKit");
assertFalse(cl.wasCallLoadClass);
-
jep.setContentType("content1");
assertTrue(cl.wasCallLoadClass);
-
cl.wasCallLoadClass = false;
jep.setContentType("content2");
assertFalse(cl.wasCallLoadClass);
}
private void checkBaseValues(final String docClass, final String kitClass,
- final String contentType,
- final URL currentPage, final JEditorPane c) {
+ final String contentType, final URL currentPage, final JEditorPane c) {
assertEquals(docClass, getClassName(c.getDocument()));
assertEquals(kitClass, getClassName(c.getEditorKit()));
assertEquals(contentType, c.getContentType());
assertEquals(currentPage, c.getPage());
-
}
public void testJEditorPane() {
checkBaseValues("javax.swing.text.PlainDocument",
- "javax.swing.JEditorPane$PlainEditorKit", "text/plain",
- null, jep);
+ "javax.swing.JEditorPane$PlainEditorKit", "text/plain", null, jep);
}
public void testJEditorPaneString() {
@@ -436,8 +417,7 @@
assertFalse("Unexpected exception: " + e.getMessage(), true);
}
checkBaseValues("javax.swing.text.html.HTMLDocument",
- "javax.swing.text.html.HTMLEditorKit", "text/html",
- TEST_URL, jep);
+ "javax.swing.text.html.HTMLEditorKit", "text/html", TEST_URL, jep);
}
public void testJEditorPaneStringString() {
@@ -446,10 +426,8 @@
}
jep = new JEditorPane("text/html", htmlString);
checkBaseValues("javax.swing.text.html.HTMLDocument",
- "javax.swing.text.html.HTMLEditorKit", "text/html",
- null, jep);
- assertEquals(removeMeta(htmlString), removeMeta(jep.getText()
- .replaceAll("\n", "")));
+ "javax.swing.text.html.HTMLEditorKit", "text/html", null, jep);
+ assertEquals(removeMeta(htmlString), removeMeta(jep.getText().replaceAll("\n", "")));
}
public void testJEditorPaneURL() {
@@ -462,11 +440,10 @@
assertFalse("Unexpected exception: " + e.getMessage(), true);
}
checkBaseValues("javax.swing.text.html.HTMLDocument",
- "javax.swing.text.html.HTMLEditorKit", "text/html",
- TEST_URL, jep);
+ "javax.swing.text.html.HTMLEditorKit", "text/html", TEST_URL, jep);
}
- private void assertEquals(final ArrayList a, final Object objects[]) {
+ private void assertEquals(final ArrayList<HyperlinkListener> a, final Object objects[]) {
int size = a.size();
assertEquals(size, objects.length);
for (int i = 0; i < size; i++) {
@@ -479,43 +456,35 @@
HyperlinkListener listener2 = new SimpleHyperlinkListener("2");
HyperlinkListener listener3 = new SimpleHyperlinkListener("3");
HyperlinkListener listeners[];
- ArrayList testList = new ArrayList();
-
+ ArrayList<HyperlinkListener> testList = new ArrayList<HyperlinkListener>();
jep.addHyperlinkListener(listener1);
listeners = jep.getHyperlinkListeners();
testList.add(listener1);
assertEquals(testList, listeners);
-
jep.addHyperlinkListener(listener2);
listeners = jep.getHyperlinkListeners();
testList.add(0, listener2);
assertEquals(testList, listeners);
-
jep.addHyperlinkListener(listener3);
listeners = jep.getHyperlinkListeners();
testList.add(0, listener3);
assertEquals(testList, listeners);
-
jep.addHyperlinkListener(listener1);
listeners = jep.getHyperlinkListeners();
testList.add(0, listener1);
assertEquals(testList, listeners);
-
jep.removeHyperlinkListener(listener2);
listeners = jep.getHyperlinkListeners();
testList.remove(listener2);
assertEquals(testList, listeners);
-
jep.removeHyperlinkListener(listener1);
listeners = jep.getHyperlinkListeners();
testList.remove(listener1);
assertEquals(testList, listeners);
-
jep.removeHyperlinkListener(listener3);
listeners = jep.getHyperlinkListeners();
testList.remove(listener3);
assertEquals(testList, listeners);
-
jep.removeHyperlinkListener(listener1);
listeners = jep.getHyperlinkListeners();
testList.remove(listener1);
@@ -525,8 +494,7 @@
public void testCreateDefaultEditorKit() {
EditorKit kit1 = jep.createDefaultEditorKit();
EditorKit kit2 = jep.createDefaultEditorKit();
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", kit1.getClass()
- .getName());
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", kit1.getClass().getName());
assertNotSame(kit1, kit2);
}
@@ -541,14 +509,12 @@
jep.addHyperlinkListener(listener1);
jep.addHyperlinkListener(listener2);
jep.addHyperlinkListener(listener3);
-
HyperlinkEvent event = getHyperlinkEvent(HyperlinkEvent.EventType.ACTIVATED);
jep.fireHyperlinkUpdate(event);
assertEquals("321", fireOrder);
assertEquals(event, listener1.event);
assertEquals(event, listener2.event);
assertEquals(event, listener3.event);
-
fireOrder = "";
event = getHyperlinkEvent(HyperlinkEvent.EventType.EXITED);
jep.fireHyperlinkUpdate(event);
@@ -556,7 +522,6 @@
assertEquals(event, listener1.event);
assertEquals(event, listener2.event);
assertEquals(event, listener3.event);
-
fireOrder = "";
event = getHyperlinkEvent(HyperlinkEvent.EventType.ENTERED);
jep.fireHyperlinkUpdate(event);
@@ -564,7 +529,6 @@
assertEquals(event, listener1.event);
assertEquals(event, listener2.event);
assertEquals(event, listener3.event);
-
}
public void testSetGetPage1() {
@@ -591,20 +555,20 @@
}
assertEquals(testUrlString, jep.getPage().toString());
}
- //temporarily commented-out: HTMLEditorKit not implemented
- /* public void testGetStream() {
- try {
- Document doc = jep.getDocument();
- assertEquals(getClassName(TEST_URL.openStream()), getClassName(jep
- .getStream(TEST_URL)));
- assertTrue(jep.getEditorKit() instanceof HTMLEditorKit);
- //4825653
- //System.out.println(jep.getDocument().getProperty(Document.StreamDescriptionProperty));
- } catch (final IOException e) {
- assertFalse("Unexpected exception: " + e.getMessage(), true);
- }
- }*/
+ //temporarily commented-out: HTMLEditorKit not implemented
+ /* public void testGetStream() {
+ try {
+ Document doc = jep.getDocument();
+ assertEquals(getClassName(TEST_URL.openStream()), getClassName(jep
+ .getStream(TEST_URL)));
+ assertTrue(jep.getEditorKit() instanceof HTMLEditorKit);
+ //4825653
+ //System.out.println(jep.getDocument().getProperty(Document.StreamDescriptionProperty));
+ } catch (final IOException e) {
+ assertFalse("Unexpected exception: " + e.getMessage(), true);
+ }
+ }*/
public void testReadHTML() {
if (true) {
throw new UnsupportedOperationException("Not implemented");
@@ -619,28 +583,27 @@
}
assertEquals("text/html", jep.getContentType());
/*
- * String docContent = null; try { Document doc = jep.getDocument();
- * docContent = doc.getText(0, doc.getLength()); }
- * catch(BadLocationException e){ assertFalse("Unexpected exception :",
- * true); } System.out.println("_____" + docContent + "_____"); String
- * temp = " \nThank you for the quote you sentreguarding account
- * #99999999999999. &160;I just have a couple of questions.Please let
- * me know. \n" + " Thank you, we look forward to hearing from you.";
- * System.out.println("___" + temp.replaceAll("\n","X") + "____");
- * System.out.println("___" + docContent.replaceAll("\n","X") +
- * "____"); System.out.println(temp.length() + " "+
- * docContent.length()); for (int i = 0 ; i < 182; i ++){
- * System.out.println("__" + temp.charAt(i) + "___"+
- * docContent.charAt(i)+ "___" + (temp.charAt(i) ==
- * docContent.charAt(i)) + " ..." + (docContent.charAt(i) == ' ')); }
- * assertTrue("BLA",temp.replaceAll("\n","X").equals(docContent.replaceAll("\n","X")));
- * //assertEquals(temp, docContent);
- * //assertEquals(htmlString,jep.getText().replaceAll("\n",""));
- *
- */
-
- assertEquals(removeMeta(htmlString), removeMeta(jep.getText()
- .replaceAll("\n", "").replaceAll("\r","")));
+ * String docContent = null; try { Document doc = jep.getDocument();
+ * docContent = doc.getText(0, doc.getLength()); }
+ * catch(BadLocationException e){ assertFalse("Unexpected exception :",
+ * true); } System.out.println("_____" + docContent + "_____"); String
+ * temp = " \nThank you for the quote you sentreguarding account
+ * #99999999999999. &160;I just have a couple of questions.Please let
+ * me know. \n" + " Thank you, we look forward to hearing from you.";
+ * System.out.println("___" + temp.replaceAll("\n","X") + "____");
+ * System.out.println("___" + docContent.replaceAll("\n","X") +
+ * "____"); System.out.println(temp.length() + " "+
+ * docContent.length()); for (int i = 0 ; i < 182; i ++){
+ * System.out.println("__" + temp.charAt(i) + "___"+
+ * docContent.charAt(i)+ "___" + (temp.charAt(i) ==
+ * docContent.charAt(i)) + " ..." + (docContent.charAt(i) == ' ')); }
+ * assertTrue("BLA",temp.replaceAll("\n","X").equals(docContent.replaceAll("\n","X")));
+ * //assertEquals(temp, docContent);
+ * //assertEquals(htmlString,jep.getText().replaceAll("\n",""));
+ *
+ */
+ assertEquals(removeMeta(htmlString), removeMeta(jep.getText().replaceAll("\n", "")
+ .replaceAll("\r", "")));
}
static final String removeMeta(final String s) {
@@ -656,7 +619,6 @@
assertFalse("Unexpected exception :", true);
}
assertEquals("text/plain", jep.getContentType());
- String docContent = null;
assertEquals(plainString, jep.getText());
}
@@ -684,7 +646,6 @@
}
public void testScrollToReference() {
-
}
public void testSetGetContentType() {
@@ -693,41 +654,27 @@
}
assertEquals("text/plain", jep.getContentType());
jep.setContentType("text/rtf");
-
- assertEquals("javax.swing.text.rtf.RTFEditorKit", jep.getEditorKit()
- .getClass().getName());
- assertEquals("javax.swing.text.DefaultStyledDocument", getClassName(jep
- .getDocument()));
-
+ assertEquals("javax.swing.text.rtf.RTFEditorKit", jep.getEditorKit().getClass()
+ .getName());
+ assertEquals("javax.swing.text.DefaultStyledDocument", getClassName(jep.getDocument()));
jep.setContentType("text/html");
-
- assertEquals("javax.swing.text.html.HTMLEditorKit", jep.getEditorKit()
- .getClass().getName());
- assertEquals("javax.swing.text.html.HTMLDocument", getClassName(jep
- .getDocument()));
-
+ assertEquals("javax.swing.text.html.HTMLEditorKit", jep.getEditorKit().getClass()
+ .getName());
+ assertEquals("javax.swing.text.html.HTMLDocument", getClassName(jep.getDocument()));
jep.setContentType("text/plain");
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", jep
- .getEditorKit().getClass().getName());
- assertEquals("javax.swing.text.PlainDocument", getClassName(jep
- .getDocument()));
-
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", jep.getEditorKit().getClass()
+ .getName());
+ assertEquals("javax.swing.text.PlainDocument", getClassName(jep.getDocument()));
jep.setContentType("text/test");
-
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", jep
- .getEditorKit().getClass().getName());
- assertEquals("javax.swing.text.PlainDocument", getClassName(jep
- .getDocument()));
-
- JEditorPane.
- registerEditorKitForContentType("text/test",
- "javax.swing.text.DefaultEditorKit");
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", jep.getEditorKit().getClass()
+ .getName());
+ assertEquals("javax.swing.text.PlainDocument", getClassName(jep.getDocument()));
+ JEditorPane.registerEditorKitForContentType("text/test",
+ "javax.swing.text.DefaultEditorKit");
jep.setContentType("text/test");
- assertEquals("javax.swing.text.DefaultEditorKit", jep.getEditorKit()
- .getClass().getName());
- assertEquals("javax.swing.text.PlainDocument", getClassName(jep
- .getDocument()));
-
+ assertEquals("javax.swing.text.DefaultEditorKit", jep.getEditorKit().getClass()
+ .getName());
+ assertEquals("javax.swing.text.PlainDocument", getClassName(jep.getDocument()));
JEditorPane.registerEditorKitForContentType("text/test", "");
}
@@ -735,35 +682,35 @@
assertNotNull(obj);
return obj.getClass().getName();
}
+
//commented due to unimplemented functionality
/*public void testSetGetEditorKitForContentType() {
- String content = "testSetGetEditorKitForContentType";
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", getClassName(jep
- .getEditorKitForContentType("...")));
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", getClassName(jep
- .getEditorKitForContentType("text/plain")));
- assertEquals("javax.swing.text.html.HTMLEditorKit", getClassName(jep
- .getEditorKitForContentType("text/html")));
- assertEquals("javax.swing.text.rtf.RTFEditorKit", getClassName(jep
- .getEditorKitForContentType("text/rtf")));
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", getClassName(jep
- .getEditorKitForContentType(content)));
-
- JEditorPane
- .registerEditorKitForContentType(content,
- "javax.swing.text.DefaultEditorKit");
- assertEquals("javax.swing.text.DefaultEditorKit", getClassName(jep
- .getEditorKitForContentType(content)));
- assertEquals("javax.swing.text.DefaultEditorKit", JEditorPane
- .getEditorKitClassNameForContentType(content));
- SimpleEditorKit kit = new SimpleEditorKit();
- jep.setEditorKitForContentType(content, kit);
- assertEquals("javax.swing.JEditorPaneTest$SimpleEditorKit",
- getClassName(jep.getEditorKitForContentType(content)));
- assertEquals("javax.swing.text.DefaultEditorKit", JEditorPane
- .getEditorKitClassNameForContentType(content));
- }*/
-
+ String content = "testSetGetEditorKitForContentType";
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", getClassName(jep
+ .getEditorKitForContentType("...")));
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", getClassName(jep
+ .getEditorKitForContentType("text/plain")));
+ assertEquals("javax.swing.text.html.HTMLEditorKit", getClassName(jep
+ .getEditorKitForContentType("text/html")));
+ assertEquals("javax.swing.text.rtf.RTFEditorKit", getClassName(jep
+ .getEditorKitForContentType("text/rtf")));
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", getClassName(jep
+ .getEditorKitForContentType(content)));
+
+ JEditorPane
+ .registerEditorKitForContentType(content,
+ "javax.swing.text.DefaultEditorKit");
+ assertEquals("javax.swing.text.DefaultEditorKit", getClassName(jep
+ .getEditorKitForContentType(content)));
+ assertEquals("javax.swing.text.DefaultEditorKit", JEditorPane
+ .getEditorKitClassNameForContentType(content));
+ SimpleEditorKit kit = new SimpleEditorKit();
+ jep.setEditorKitForContentType(content, kit);
+ assertEquals("javax.swing.JEditorPaneTest$SimpleEditorKit",
+ getClassName(jep.getEditorKitForContentType(content)));
+ assertEquals("javax.swing.text.DefaultEditorKit", JEditorPane
+ .getEditorKitClassNameForContentType(content));
+ }*/
public void testSetGetEditorKit() {
if (true) {
throw new UnsupportedOperationException("Not implemented");
@@ -774,8 +721,7 @@
EditorKit kit0 = jep.getEditorKit();
SimpleEditorKit kit1 = new SimpleEditorKit();
SimpleEditorKit kit2 = new SimpleEditorKit();
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", kit0.getClass()
- .getName());
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", kit0.getClass().getName());
event = new PropertyChangeEvent(jep, "editorKit", kit0, kit1);
jep.setEditorKit(kit1);
assertEquals(kit1, jep.getEditorKit());
@@ -784,52 +730,46 @@
assertFalse(kit1.wasCallDeinstall);
listener.resetDbgInfo();
kit1.resetDbgInfo();
-
event = new PropertyChangeEvent(jep, "editorKit", kit1, kit2);
jep.setEditorKit(kit2);
assertEquals(kit2, jep.getEditorKit());
assertEquals(event, listener.event);
-
assertTrue(kit2.wasCallInstall);
assertFalse(kit2.wasCallDeinstall);
-
assertFalse(kit1.wasCallInstall);
assertTrue(kit1.wasCallDeinstall);
-
kit2.resetDbgInfo();
jep.setEditorKit(null);
kit0 = jep.getEditorKit();
event = new PropertyChangeEvent(jep, "editorKit", kit2, kit0);
- assertEquals("javax.swing.JEditorPane$PlainEditorKit", kit0.getClass()
- .getName());
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", kit0.getClass().getName());
assertTrue(kit2.wasCallDeinstall);
//temporarily commented-out: HTMLEditorKit,
//DefaultStyledDocument not implemented
/*assertEquals("text/plain", jep.getContentType());
- jep.setEditorKit(new HTMLEditorKit());
- assertEquals("text/html", jep.getContentType());
- assertEquals("javax.swing.text.html.HTMLDocument", getClassName(jep
- .getDocument()));
-
- jep.setEditorKit(new DefaultEditorKit());
- assertEquals("text/plain", jep.getContentType());
- assertEquals("javax.swing.text.PlainDocument", getClassName(jep
- .getDocument()));
-
- jep.setEditorKit(new StyledEditorKit());
- assertEquals("text/plain", jep.getContentType());
- assertEquals("javax.swing.text.DefaultStyledDocument", getClassName(jep
- .getDocument()));
-
- jep.setEditorKit(new RTFEditorKit());
- assertEquals("text/rtf", jep.getContentType());
- assertEquals("javax.swing.text.DefaultStyledDocument", getClassName(jep
- .getDocument())); */
+ jep.setEditorKit(new HTMLEditorKit());
+ assertEquals("text/html", jep.getContentType());
+ assertEquals("javax.swing.text.html.HTMLDocument", getClassName(jep
+ .getDocument()));
+
+ jep.setEditorKit(new DefaultEditorKit());
+ assertEquals("text/plain", jep.getContentType());
+ assertEquals("javax.swing.text.PlainDocument", getClassName(jep
+ .getDocument()));
+
+ jep.setEditorKit(new StyledEditorKit());
+ assertEquals("text/plain", jep.getContentType());
+ assertEquals("javax.swing.text.DefaultStyledDocument", getClassName(jep
+ .getDocument()));
+
+ jep.setEditorKit(new RTFEditorKit());
+ assertEquals("text/rtf", jep.getContentType());
+ assertEquals("javax.swing.text.DefaultStyledDocument", getClassName(jep
+ .getDocument())); */
}
public void testConstants() {
- assertEquals("JEditorPane.honorDisplayProperties",
- JEditorPane.HONOR_DISPLAY_PROPERTIES);
+ assertEquals("JEditorPane.honorDisplayProperties", JEditorPane.HONOR_DISPLAY_PROPERTIES);
assertEquals("JEditorPane.w3cLengthUnits", JEditorPane.W3C_LENGTH_UNITS);
}
@@ -837,13 +777,14 @@
EditorKit kit = jep.getEditorKit();
assertEquals(kit, kit.getViewFactory());
}
- public void testGetEditorKitClassNameForContentType(){
- assertEquals("javax.swing.JEditorPane$PlainEditorKit",
- JEditorPane.getEditorKitClassNameForContentType("text/plain"));
- assertEquals("javax.swing.text.html.HTMLEditorKit",
- JEditorPane.getEditorKitClassNameForContentType("text/html"));
- assertEquals("javax.swing.text.rtf.RTFEditorKit",
- JEditorPane.getEditorKitClassNameForContentType("text/rtf"));
+
+ public void testGetEditorKitClassNameForContentType() {
+ assertEquals("javax.swing.JEditorPane$PlainEditorKit", JEditorPane
+ .getEditorKitClassNameForContentType("text/plain"));
+ assertEquals("javax.swing.text.html.HTMLEditorKit", JEditorPane
+ .getEditorKitClassNameForContentType("text/html"));
+ assertEquals("javax.swing.text.rtf.RTFEditorKit", JEditorPane
+ .getEditorKitClassNameForContentType("text/rtf"));
assertNull(JEditorPane.getEditorKitClassNameForContentType("..."));
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneHTMLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneHTMLTest.java?view=diff&rev=479240&r1=479239&r2=479240
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneHTMLTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneHTMLTest.java Sat Nov 25 16:04:10 2006
@@ -20,11 +20,14 @@
*/
package javax.swing;
-public class JEditorPane_AccessibleJEditorPaneHTMLTest extends SwingTestCase{
- JEditorPane jep;
- JFrame jf;
+public class JEditorPane_AccessibleJEditorPaneHTMLTest extends SwingTestCase {
+ JEditorPane jep;
+
+ JFrame jf;
+
JEditorPane.AccessibleJEditorPaneHTML accessible;
+ @Override
protected void setUp() throws Exception {
super.setUp();
setIgnoreNotImplemented(true);
@@ -37,26 +40,22 @@
accessible = jep.new AccessibleJEditorPaneHTML();
}
-
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
}
- public void testGetAccessibleText(){
- assertTrue(accessible.getAccessibleText()instanceof
- JEditorPane.JEditorPaneAccessibleHypertextSupport);
+ public void testGetAccessibleText() {
+ assertTrue(accessible.getAccessibleText() instanceof JEditorPane.JEditorPaneAccessibleHypertextSupport);
}
- public void testGetAccessibleAt(){
-
+ public void testGetAccessibleAt() {
}
- public void testGetAccessibleChild(final int i){
-
+ public void testGetAccessibleChild(final int i) {
}
- public void testGetAccessibleChildrenCount(){
-
+ public void testGetAccessibleChildrenCount() {
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneTest.java?view=diff&rev=479240&r1=479239&r2=479240
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_AccessibleJEditorPaneTest.java Sat Nov 25 16:04:10 2006
@@ -22,11 +22,14 @@
import javax.accessibility.AccessibleState;
-public class JEditorPane_AccessibleJEditorPaneTest extends SwingTestCase{
- JEditorPane jep;
- JFrame jf;
+public class JEditorPane_AccessibleJEditorPaneTest extends SwingTestCase {
+ JEditorPane jep;
+
+ JFrame jf;
+
JEditorPane.AccessibleJEditorPane accessible;
+ @Override
protected void setUp() throws Exception {
super.setUp();
setIgnoreNotImplemented(true);
@@ -38,24 +41,25 @@
accessible = jep.new AccessibleJEditorPane();
}
-
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
}
- public void testGetAccessibleStateSet(){
+ public void testGetAccessibleStateSet() {
assertTrue(accessible.getAccessibleStateSet().contains(AccessibleState.MULTI_LINE));
}
- public void testGetAccessibleDescription(){
+
+ public void testGetAccessibleDescription() {
assertEquals("text/plain", accessible.getAccessibleDescription());
// TODO: uncomment when HTML support is implemented
-// jep.setContentType("text/html");
-// assertEquals("text/html", accessible.getAccessibleDescription());
+ // jep.setContentType("text/html");
+ // assertEquals("text/html", accessible.getAccessibleDescription());
jep.setContentType("test");
assertEquals("text/plain", accessible.getAccessibleDescription());
// TODO: uncomment when RTF support is implemented
-// jep.setContentType("text/rtf");
-// assertEquals("text/rtf", accessible.getAccessibleDescription());
+ // jep.setContentType("text/rtf");
+ // assertEquals("text/rtf", accessible.getAccessibleDescription());
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_MultithreadedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_MultithreadedTest.java?view=diff&rev=479240&r1=479239&r2=479240
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_MultithreadedTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JEditorPane_MultithreadedTest.java Sat Nov 25 16:04:10 2006
@@ -20,26 +20,20 @@
*/
package javax.swing;
-import javax.swing.text.AbstractDocument;
-import javax.swing.text.AttributeSet;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.Element;
-import javax.swing.text.SimpleAttributeSet;
-
import junit.framework.TestCase;
public class JEditorPane_MultithreadedTest extends TestCase {
- JEditorPane jep;
+ JEditorPane jep;
- JFrame jf;
+ JFrame jf;
- SetTextMaster masterSetText = new SetTextMaster();
+ SetTextMaster masterSetText = new SetTextMaster();
MakeSelectionMaster masterMakeSelection = new MakeSelectionMaster();
UnsupportedOperationException ex;
+ @Override
protected void setUp() throws Exception {
super.setUp();
ex = null;
@@ -50,22 +44,12 @@
jf.pack();
}
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
}
- private AttributeSet getAttributeSetByIndex(final AbstractDocument d,
- final int offset) {
- AttributeSet as = null;
- Element elem = d.getDefaultRootElement();
- while (elem.getElementCount() > 0) {
- elem = elem.getElement(elem.getElementIndex(offset));
- as = elem.getAttributes();
- }
- return as;
- }
-
final class MakeSelectionMaster implements Runnable {
int dot;
@@ -103,21 +87,17 @@
masterMakeSelection.setDotAndMark(7, 4);
SwingUtilities.invokeAndWait(masterSetText);
SwingUtilities.invokeAndWait(masterMakeSelection);
-
jep.replaceSelection("XXX");
assertEquals("testXXXlaceSelection", jep.getText());
-
masterMakeSelection.setDotAndMark(4, 2);
SwingUtilities.invokeAndWait(masterMakeSelection);
jep.replaceSelection(null);
assertEquals("teXXXlaceSelection", jep.getText());
-
masterMakeSelection.setDotAndMark(2, 0);
SwingUtilities.invokeAndWait(masterMakeSelection);
jep.replaceSelection(null);
assertEquals("XXXlaceSelection", jep.getText());
-
- masterMakeSelection.setDotAndMark(3,3);
+ masterMakeSelection.setDotAndMark(3, 3);
SwingUtilities.invokeAndWait(masterMakeSelection);
jep.replaceSelection("YYY");
assertEquals("XXXYYYlaceSelection", jep.getText());
@@ -132,106 +112,98 @@
jep.setSelectionEnd(5);
}
});
-
jep.replaceSelection("AAAA");
-
assertEquals("la", jep.getSelectedText());
assertEquals("replaceSelectionNotEditable", jep.getText());
}
+
//temporary commented: DefaultStyledDocument not implemented
/*public void testReplaceSelectionWithAttributes() throws Exception {
- final AbstractDocument doc = new DefaultStyledDocument();
- SimpleAttributeSet as1 = new SimpleAttributeSet();
- as1.addAttribute("key1", "value1");
- SimpleAttributeSet as2 = new SimpleAttributeSet();
- as2.addAttribute("key2", "value2");
-
- try {
- doc.insertString(0, "testReplaceSelection", as1);
- doc.insertString(4, "INSERT", as2);
- } catch (final BadLocationException e) {
- assertFalse("unexpected exception :" + e.getMessage(), true);
- }
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- try {
- jep.setEditorKit(new RTFEditorKit());
- jep.setDocument(doc);
- } catch(UnsupportedOperationException e){
- ex = e;
- }
- }
- });
- if (ex != null)
- return;
- masterMakeSelection.setDotAndMark(7, 6);
- SwingUtilities.invokeAndWait(masterMakeSelection);
-
- jep.replaceSelection("YYY");
-
- for (int i = 0; i < doc.getLength(); i++) {
- AttributeSet as = getAttributeSetByIndex(doc, i);
- if (i > 3 && i < 12)
- assertEquals(as2, as);
- else
- assertEquals(as1, as);
- }
- }*/
-
+ final AbstractDocument doc = new DefaultStyledDocument();
+ SimpleAttributeSet as1 = new SimpleAttributeSet();
+ as1.addAttribute("key1", "value1");
+ SimpleAttributeSet as2 = new SimpleAttributeSet();
+ as2.addAttribute("key2", "value2");
+
+ try {
+ doc.insertString(0, "testReplaceSelection", as1);
+ doc.insertString(4, "INSERT", as2);
+ } catch (final BadLocationException e) {
+ assertFalse("unexpected exception :" + e.getMessage(), true);
+ }
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ try {
+ jep.setEditorKit(new RTFEditorKit());
+ jep.setDocument(doc);
+ } catch(UnsupportedOperationException e){
+ ex = e;
+ }
+ }
+ });
+ if (ex != null)
+ return;
+ masterMakeSelection.setDotAndMark(7, 6);
+ SwingUtilities.invokeAndWait(masterMakeSelection);
+
+ jep.replaceSelection("YYY");
+
+ for (int i = 0; i < doc.getLength(); i++) {
+ AttributeSet as = getAttributeSetByIndex(doc, i);
+ if (i > 3 && i < 12)
+ assertEquals(as2, as);
+ else
+ assertEquals(as1, as);
+ }
+ }*/
public void testSetGetTextPlain() throws Exception {
jep.setText(JEditorPaneTest.plainString);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
-
- assertEquals("plain", JEditorPaneTest.plainString, jep
- .getText());
+ assertEquals("plain", JEditorPaneTest.plainString, jep.getText());
}
});
-
};
public void testSetGetTextRtf() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
- jep.setContentType("text/rtf");
- } catch(UnsupportedOperationException e){
+ jep.setContentType("text/rtf");
+ } catch (UnsupportedOperationException e) {
ex = e;
}
}
});
- if (ex != null)
+ if (ex != null) {
return;
+ }
jep.setText(JEditorPaneTest.rtfString);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- assertEquals("blablabla\n", JEditorPaneTest.getDocContent(jep
- .getDocument()));
+ assertEquals("blablabla\n", JEditorPaneTest.getDocContent(jep.getDocument()));
}
});
};
public void testSetGetTextHTML() throws Exception {
-
SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- try {
- jep.setContentType("text/html");
- } catch(UnsupportedOperationException e){
- ex = e;
- }
+ public void run() {
+ try {
+ jep.setContentType("text/html");
+ } catch (UnsupportedOperationException e) {
+ ex = e;
}
+ }
});
- if (ex != null)
+ if (ex != null) {
return;
-
+ }
jep.setText(JEditorPaneTest.htmlString);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- assertEquals(JEditorPaneTest
- .removeMeta(JEditorPaneTest.htmlString),
- JEditorPaneTest.removeMeta(jep.getText()
- .replaceAll("\n", "")));
+ assertEquals(JEditorPaneTest.removeMeta(JEditorPaneTest.htmlString),
+ JEditorPaneTest.removeMeta(jep.getText().replaceAll("\n", "")));
}
});
};
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserRTest.java?view=diff&rev=479240&r1=479239&r2=479240
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserRTest.java Sat Nov 25 16:04:10 2006
@@ -21,8 +21,6 @@
package javax.swing;
import java.io.File;
-
-import javax.swing.BasicSwingTestCase.PropertyChangeController;
import javax.swing.filechooser.FileFilter;
public class JFileChooserRTest extends BasicSwingTestCase {
@@ -32,36 +30,35 @@
super(name);
}
+ @Override
protected void setUp() throws Exception {
chooser = new JFileChooser();
}
+ @Override
protected void tearDown() throws Exception {
chooser = null;
}
public void testAddChoosableFileFilter() throws Exception {
FileFilter ff = new FileFilter() {
+ @Override
public boolean accept(File file) {
return false;
}
+ @Override
public String getDescription() {
return "any";
}
};
-
assertEquals(1, chooser.getChoosableFileFilters().length);
-
chooser.addChoosableFileFilter(ff);
assertEquals(2, chooser.getChoosableFileFilters().length);
-
chooser.addChoosableFileFilter(ff);
assertEquals(2, chooser.getChoosableFileFilters().length);
-
chooser.addChoosableFileFilter(chooser.getAcceptAllFileFilter());
assertEquals(2, chooser.getChoosableFileFilters().length);
-
assertSame(chooser.getAcceptAllFileFilter(), chooser.getChoosableFileFilters()[0]);
assertSame(ff, chooser.getChoosableFileFilters()[1]);
}
@@ -69,17 +66,15 @@
public void testGetSetSelectedFile() throws Exception {
propertyChangeController = new PropertyChangeController();
chooser.addPropertyChangeListener(propertyChangeController);
-
assertNull(chooser.getSelectedFile());
- File selectedFile = new File(new File(".").getCanonicalPath() + File.separator + "testFile");
+ File selectedFile = new File(new File(".").getCanonicalPath() + File.separator
+ + "testFile");
selectedFile.deleteOnExit();
chooser.setSelectedFile(selectedFile);
-
assertEquals(selectedFile, chooser.getSelectedFile());
assertEquals(0, chooser.getSelectedFiles().length);
- assertEquals(selectedFile.getAbsoluteFile().getParentFile().getCanonicalFile(),
- chooser.getCurrentDirectory().getCanonicalFile());
-
+ assertEquals(selectedFile.getAbsoluteFile().getParentFile().getCanonicalFile(), chooser
+ .getCurrentDirectory().getCanonicalFile());
selectedFile.mkdir();
chooser.setSelectedFile(selectedFile);
assertEquals(selectedFile, chooser.getSelectedFile());
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserTest.java?view=diff&rev=479240&r1=479239&r2=479240
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JFileChooserTest.java Sat Nov 25 16:04:10 2006
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* @author Anton Avtamonov
* @version $Revision$
@@ -26,7 +25,6 @@
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
-
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
@@ -41,6 +39,7 @@
setIgnoreNotImplemented(true);
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
timeoutDelay = 5 * DEFAULT_TIMEOUT_DELAY;
@@ -49,6 +48,7 @@
chooser.addPropertyChangeListener(propertyChangeController);
}
+ @Override
protected void tearDown() throws Exception {
chooser = null;
super.tearDown();
@@ -56,44 +56,47 @@
public void testJFileChooser() throws Exception {
assertNotNull(chooser.getCurrentDirectory());
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser.getCurrentDirectory());
-
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser
+ .getCurrentDirectory());
File testDir = new File("testDir");
testDir.deleteOnExit();
testDir.mkdir();
chooser = new JFileChooser(testDir);
- assertEqualsIgnoreCase(testDir.getAbsolutePath(), chooser.getCurrentDirectory().getAbsolutePath());
-
+ assertEqualsIgnoreCase(testDir.getAbsolutePath(), chooser.getCurrentDirectory()
+ .getAbsolutePath());
chooser = new JFileChooser(testDir.getAbsolutePath());
- assertEqualsIgnoreCase(testDir.getAbsolutePath(), chooser.getCurrentDirectory().getAbsolutePath());
-
+ assertEqualsIgnoreCase(testDir.getAbsolutePath(), chooser.getCurrentDirectory()
+ .getAbsolutePath());
testDir.delete();
testDir = new File("anotherTestDir");
chooser = new JFileChooser(testDir);
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser.getCurrentDirectory());
-
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser
+ .getCurrentDirectory());
chooser = new JFileChooser(testDir.getAbsolutePath());
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser.getCurrentDirectory());
-
- chooser = new JFileChooser((String)null);
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser.getCurrentDirectory());
-
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser
+ .getCurrentDirectory());
+ chooser = new JFileChooser((String) null);
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser
+ .getCurrentDirectory());
final File defaultDir = new File("testDir");
defaultDir.deleteOnExit();
defaultDir.mkdir();
try {
FileSystemView view = new FileSystemView() {
+ @Override
public File createNewFolder(final File containingDir) throws IOException {
return containingDir;
}
+ @Override
public File getDefaultDirectory() {
return defaultDir;
}
};
chooser = new JFileChooser(view);
assertEquals(view, chooser.getFileSystemView());
- assertEqualsIgnoreCase(defaultDir.getAbsolutePath(), chooser.getCurrentDirectory().getAbsolutePath());
+ assertEqualsIgnoreCase(defaultDir.getAbsolutePath(), chooser.getCurrentDirectory()
+ .getAbsolutePath());
} finally {
defaultDir.delete();
}
@@ -102,24 +105,25 @@
//TODO
public void testSetup() throws Exception {
assertEquals(FileSystemView.getFileSystemView(), chooser.getFileSystemView());
-
final File defaultDir = new File("testDir");
defaultDir.deleteOnExit();
try {
defaultDir.mkdir();
FileSystemView view = new FileSystemView() {
+ @Override
public File createNewFolder(final File containingDir) throws IOException {
return containingDir;
}
+ @Override
public File getDefaultDirectory() {
return defaultDir;
}
};
-
chooser.setup(view);
assertEquals(view, chooser.getFileSystemView());
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser.getCurrentDirectory());
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser
+ .getCurrentDirectory());
} catch (Throwable t) {
defaultDir.delete();
fail("Detected problem " + t.getMessage());
@@ -128,7 +132,6 @@
public void testGetSetDragEnabled() throws Exception {
assertFalse(chooser.getDragEnabled());
-
chooser.setDragEnabled(true);
assertTrue(chooser.getDragEnabled());
assertFalse(propertyChangeController.isChanged());
@@ -141,7 +144,6 @@
assertEquals(selectedFile, chooser.getSelectedFile());
assertEquals(0, chooser.getSelectedFiles().length);
assertTrue(propertyChangeController.isChanged("SelectedFileChangedProperty"));
-
selectedFile = new File("testDir");
selectedFile.deleteOnExit();
selectedFile.mkdir();
@@ -151,59 +153,51 @@
public void testGetSetSelectedFiles() throws Exception {
assertEquals(0, chooser.getSelectedFiles().length);
-
chooser.setSelectedFile(new File("c"));
assertEquals(0, chooser.getSelectedFiles().length);
-
propertyChangeController.reset();
File selectedFile = new File("a");
- File[] files = new File[] {selectedFile, new File("b")};
+ File[] files = new File[] { selectedFile, new File("b") };
chooser.setSelectedFiles(files);
assertNotSame(files, chooser.getSelectedFiles());
assertEquals(files.length, chooser.getSelectedFiles().length);
-
assertEquals(selectedFile, chooser.getSelectedFile());
assertTrue(propertyChangeController.isChanged("SelectedFilesChangedProperty"));
assertTrue(propertyChangeController.isChanged("SelectedFileChangedProperty"));
-
propertyChangeController.reset();
- files = new File[] {new File("b"), selectedFile};
+ files = new File[] { new File("b"), selectedFile };
chooser.setSelectedFiles(files);
assertNotSame(files, chooser.getSelectedFiles());
assertEquals(files.length, chooser.getSelectedFiles().length);
-
assertEquals(new File("b"), chooser.getSelectedFile());
assertTrue(propertyChangeController.isChanged("SelectedFilesChangedProperty"));
assertTrue(propertyChangeController.isChanged("SelectedFileChangedProperty"));
-
-
propertyChangeController.reset();
- chooser.setSelectedFiles(new File[] {new File("b"), selectedFile});
+ chooser.setSelectedFiles(new File[] { new File("b"), selectedFile });
assertTrue(propertyChangeController.isChanged("SelectedFilesChangedProperty"));
assertFalse(propertyChangeController.isChanged("SelectedFileChangedProperty"));
}
public void testGetSetCurrentDirectory() throws Exception {
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser.getCurrentDirectory());
-
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory(), chooser
+ .getCurrentDirectory());
File dir = new File("testDir");
dir.deleteOnExit();
dir.mkdir();
-
File innerDir = new File(dir, "innerDir");
innerDir.deleteOnExit();
innerDir.mkdir();
-
File file = new File(innerDir, "innerFile");
file.deleteOnExit();
file.createNewFile();
try {
chooser.setCurrentDirectory(dir);
- assertEqualsIgnoreCase(dir.getAbsolutePath(), chooser.getCurrentDirectory().getAbsolutePath());
-
+ assertEqualsIgnoreCase(dir.getAbsolutePath(), chooser.getCurrentDirectory()
+ .getAbsolutePath());
chooser.setCurrentDirectory(file);
- assertEqualsIgnoreCase(innerDir.getAbsolutePath(), chooser.getCurrentDirectory().getAbsolutePath());
- } finally {
+ assertEqualsIgnoreCase(innerDir.getAbsolutePath(), chooser.getCurrentDirectory()
+ .getAbsolutePath());
+ } finally {
file.delete();
innerDir.delete();
dir.delete();
@@ -212,7 +206,8 @@
public void testChangeToParentDirectory() throws Exception {
chooser.changeToParentDirectory();
- assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory().getParentFile(), chooser.getCurrentDirectory());
+ assertEquals(FileSystemView.getFileSystemView().getDefaultDirectory().getParentFile(),
+ chooser.getCurrentDirectory());
}
public void testGetSetControlButtonsAreShown() throws Exception {
@@ -227,11 +222,10 @@
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
assertEquals(JFileChooser.SAVE_DIALOG, chooser.getDialogType());
assertTrue(propertyChangeController.isChanged("DialogTypeChangedProperty"));
-
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
assertEquals(JFileChooser.CUSTOM_DIALOG, chooser.getDialogType());
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
chooser.setDialogType(10);
}
@@ -241,7 +235,6 @@
public void testGetSetDialogTitle() throws Exception {
assertNull(chooser.getDialogTitle());
assertEquals("Open", chooser.getUI().getDialogTitle(chooser));
-
chooser.setDialogTitle("title");
assertEquals("title", chooser.getDialogTitle());
assertEquals("title", chooser.getUI().getDialogTitle(chooser));
@@ -252,8 +245,8 @@
assertNull(chooser.getApproveButtonToolTipText());
chooser.setApproveButtonToolTipText("text");
assertEquals("text", chooser.getApproveButtonToolTipText());
- assertTrue(propertyChangeController.isChanged("ApproveButtonToolTipTextChangedProperty"));
-
+ assertTrue(propertyChangeController
+ .isChanged("ApproveButtonToolTipTextChangedProperty"));
chooser.setApproveButtonToolTipText(null);
assertNull(chooser.getApproveButtonToolTipText());
}
@@ -266,7 +259,6 @@
assertEquals("text", chooser.getApproveButtonText());
assertEquals("text", chooser.getUI().getApproveButtonText(chooser));
assertTrue(propertyChangeController.isChanged("ApproveButtonTextChangedProperty"));
-
chooser.setApproveButtonText(null);
assertNull(chooser.getApproveButtonToolTipText());
assertEquals("Open", chooser.getUI().getApproveButtonText(chooser));
@@ -277,7 +269,6 @@
chooser.setApproveButtonMnemonic('c');
assertEquals(KeyEvent.VK_C, chooser.getApproveButtonMnemonic());
assertTrue(propertyChangeController.isChanged("ApproveButtonMnemonicChangedProperty"));
-
chooser.setApproveButtonMnemonic(KeyEvent.VK_X);
assertEquals(KeyEvent.VK_X, chooser.getApproveButtonMnemonic());
}
@@ -285,10 +276,12 @@
public void testGetAddRemoveResetChoosableFileFilters() throws Exception {
assertEquals(1, chooser.getChoosableFileFilters().length);
FileFilter fileFilter = new FileFilter() {
+ @Override
public boolean accept(final File file) {
return false;
}
+ @Override
public String getDescription() {
return "additional";
}
@@ -298,19 +291,16 @@
assertEquals("additional", chooser.getChoosableFileFilters()[1].getDescription());
assertTrue(propertyChangeController.isChanged("ChoosableFileFilterChangedProperty"));
assertTrue(propertyChangeController.isChanged("fileFilterChanged"));
-
propertyChangeController.reset();
chooser.removeChoosableFileFilter(fileFilter);
assertEquals(1, chooser.getChoosableFileFilters().length);
assertTrue(propertyChangeController.isChanged("ChoosableFileFilterChangedProperty"));
-
chooser.addChoosableFileFilter(fileFilter);
assertEquals(2, chooser.getChoosableFileFilters().length);
propertyChangeController.reset();
chooser.resetChoosableFileFilters();
assertEquals(1, chooser.getChoosableFileFilters().length);
assertTrue(propertyChangeController.isChanged("ChoosableFileFilterChangedProperty"));
-
chooser.resetChoosableFileFilters();
assertTrue(propertyChangeController.isChanged("ChoosableFileFilterChangedProperty"));
}
@@ -319,7 +309,6 @@
FileFilter acceptAllFilter = chooser.getAcceptAllFileFilter();
assertNotNull(acceptAllFilter);
assertEquals(acceptAllFilter, chooser.getUI().getAcceptAllFileFilter(chooser));
-
chooser.removeChoosableFileFilter(acceptAllFilter);
assertEquals(0, chooser.getChoosableFileFilters().length);
assertTrue(acceptAllFilter == chooser.getAcceptAllFileFilter());
@@ -328,12 +317,10 @@
public void testIsSetAcceptAllFilterUsed() throws Exception {
assertTrue(chooser.isAcceptAllFileFilterUsed());
-
chooser.setAcceptAllFileFilterUsed(false);
assertFalse(chooser.isAcceptAllFileFilterUsed());
assertEquals(0, chooser.getChoosableFileFilters().length);
assertTrue(propertyChangeController.isChanged("acceptAllFileFilterUsedChanged"));
-
chooser.setAcceptAllFileFilterUsed(true);
assertTrue(chooser.isAcceptAllFileFilterUsed());
assertEquals(1, chooser.getChoosableFileFilters().length);
@@ -351,19 +338,17 @@
assertEquals(JFileChooser.FILES_ONLY, chooser.getFileSelectionMode());
assertTrue(chooser.isFileSelectionEnabled());
assertFalse(chooser.isDirectorySelectionEnabled());
-
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
assertEquals(JFileChooser.DIRECTORIES_ONLY, chooser.getFileSelectionMode());
assertFalse(chooser.isFileSelectionEnabled());
assertTrue(chooser.isDirectorySelectionEnabled());
assertTrue(propertyChangeController.isChanged("fileSelectionChanged"));
-
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
assertEquals(JFileChooser.FILES_AND_DIRECTORIES, chooser.getFileSelectionMode());
assertTrue(chooser.isFileSelectionEnabled());
assertTrue(chooser.isDirectorySelectionEnabled());
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
chooser.setFileSelectionMode(10);
}
@@ -387,10 +372,12 @@
public void testGetSetFileFilter() throws Exception {
assertEquals(chooser.getAcceptAllFileFilter(), chooser.getFileFilter());
FileFilter fileFilter = new FileFilter() {
+ @Override
public boolean accept(final File file) {
return false;
}
+ @Override
public String getDescription() {
return "description";
}
@@ -403,8 +390,8 @@
public void testGetSetFileView() throws Exception {
assertNull(chooser.getFileView());
assertNotNull(chooser.getUI().getFileView(chooser));
-
- FileView view = new FileView() {};
+ FileView view = new FileView() {
+ };
chooser.setFileView(view);
assertTrue(propertyChangeController.isChanged("fileViewChanged"));
assertEquals(view, chooser.getFileView());
@@ -414,37 +401,42 @@
public void testGetName_Description_TypeDescription_Icon_Traversable() throws Exception {
File f = new File(".");
assertEquals(chooser.getUI().getFileView(chooser).getName(f), chooser.getName(f));
- assertEquals(chooser.getUI().getFileView(chooser).getDescription(f), chooser.getDescription(f));
- assertEquals(chooser.getUI().getFileView(chooser).getTypeDescription(f), chooser.getTypeDescription(f));
+ assertEquals(chooser.getUI().getFileView(chooser).getDescription(f), chooser
+ .getDescription(f));
+ assertEquals(chooser.getUI().getFileView(chooser).getTypeDescription(f), chooser
+ .getTypeDescription(f));
assertEquals(chooser.getUI().getFileView(chooser).getIcon(f), chooser.getIcon(f));
assertTrue(chooser.isTraversable(f));
-
final String description = "description";
final Icon icon = new ImageIcon();
final String name = "name";
final String typeDescription = "typeDescription";
FileView view = new FileView() {
+ @Override
public String getDescription(final File f) {
return description;
}
+ @Override
public Icon getIcon(final File f) {
return icon;
}
+ @Override
public String getName(final File f) {
return name;
}
+ @Override
public String getTypeDescription(final File f) {
return typeDescription;
}
+ @Override
public Boolean isTraversable(final File f) {
return Boolean.FALSE;
}
};
-
chooser.setFileView(view);
assertEquals(name, chooser.getName(f));
assertEquals(description, chooser.getDescription(f));
@@ -456,18 +448,18 @@
public void testAccept() throws Exception {
File f = new File(".");
assertTrue(chooser.accept(f));
-
chooser.setFileFilter(new FileFilter() {
+ @Override
public boolean accept(final File file) {
return false;
}
+ @Override
public String getDescription() {
return null;
}
});
assertFalse(chooser.accept(f));
-
chooser.setFileFilter(null);
assertTrue(chooser.accept(f));
}
@@ -475,6 +467,7 @@
public void testGetSetFileSystemView() throws Exception {
assertEquals(FileSystemView.getFileSystemView(), chooser.getFileSystemView());
FileSystemView fileSystemView = new FileSystemView() {
+ @Override
public File createNewFolder(final File containingDir) throws IOException {
return null;
}
@@ -487,7 +480,6 @@
public void testApproveSelection() throws Exception {
TestActionListener listener = new TestActionListener();
chooser.addActionListener(listener);
-
chooser.approveSelection();
assertNotNull(listener.getEvent());
assertEquals(JFileChooser.APPROVE_SELECTION, listener.getEvent().getActionCommand());
@@ -497,7 +489,6 @@
public void testCancelSelection() throws Exception {
TestActionListener listener = new TestActionListener();
chooser.addActionListener(listener);
-
chooser.cancelSelection();
assertNotNull(listener.getEvent());
assertEquals(JFileChooser.CANCEL_SELECTION, listener.getEvent().getActionCommand());
@@ -509,10 +500,8 @@
TestActionListener listener = new TestActionListener();
chooser.addActionListener(listener);
chooser.addActionListener(new TestActionListener());
-
chooser.fireActionPerformed("command");
assertEquals("command", listener.getEvent().getActionCommand());
-
assertEquals(2, chooser.getActionListeners().length);
chooser.removeActionListener(listener);
assertEquals(1, chooser.getActionListeners().length);
@@ -521,12 +510,10 @@
public void testGetUpdateUI() throws Exception {
FileChooserUI ui = chooser.getUI();
assertNotNull(ui);
-
FileChooserUI customUI = new BasicFileChooserUI(chooser);
chooser.setUI(customUI);
assertEquals(customUI, chooser.getUI());
assertNotSame(ui, chooser.getUI());
-
chooser.updateUI();
assertNotSame(customUI, chooser.getUI());
}
@@ -538,7 +525,6 @@
public void testgetAccessibleContext() throws Exception {
assertTrue(chooser.getAccessibleContext() instanceof JFileChooser.AccessibleJFileChooser);
}
-
private class TestActionListener implements ActionListener {
private ActionEvent event;