Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codetools 7902736 #2

Merged
merged 2 commits into from Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
/build/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -828,10 +828,8 @@ public String toString() {
public Hashtable<String, Object> getDump() {
Hashtable<String, Object> result = super.getDump();
result.put(TEXT_DPROP, ((JTextComponent) getSource()).getText());
if (((JTextComponent) getSource()).getSelectedText() != null
&& !((JTextComponent) getSource()).getSelectedText().equals("")) {
result.put(SELECTED_TEXT_DPROP, ((JTextComponent) getSource()).getSelectedText());
}
String selected = ((JTextComponent) getSource()).getSelectedText();
result.put(SELECTED_TEXT_DPROP, (selected != null) ? selected : "");
result.put(IS_EDITABLE_DPROP, ((JTextComponent) getSource()).isEditable() ? "true" : "false");
return result;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -58,6 +58,13 @@ public class TextComponentOperator extends ComponentOperator
*/
public static final String TEXT_DPROP = "Text";

/**
* Identifier for a "selected text" property.
*
* @see #getDump
*/
public static final String SELECTED_TEXT_DPROP = "Selected text";

private final static long PUSH_KEY_TIMEOUT = 0;
private final static long BETWEEN_KEYS_TIMEOUT = 0;
private final static long CHANGE_CARET_POSITION_TIMEOUT = 60000;
@@ -505,6 +512,8 @@ public String toString() {
public Hashtable<String, Object> getDump() {
Hashtable<String, Object> result = super.getDump();
result.put(TEXT_DPROP, ((TextComponent) getSource()).getText());
String selected = ((TextComponent) getSource()).getSelectedText();
result.put(SELECTED_TEXT_DPROP, (selected != null) ? selected : "");
return result;
}

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.netbeans.jemmy.operators;

import org.testng.annotations.Test;

import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import static org.testng.Assert.assertEquals;

public class JTextComponentOperatorTest {
@Test
public void selection() {
JTextComponent text = new JTextField("0123456789");
JTextComponentOperator textOper = new JTextComponentOperator(text);
assertEquals(textOper.getDump().get(JTextComponentOperator.SELECTED_TEXT_DPROP), "");
text.select(1,1);
assertEquals(textOper.getDump().get(JTextComponentOperator.SELECTED_TEXT_DPROP), "");
text.select(1,2);
assertEquals(textOper.getDump().get(JTextComponentOperator.SELECTED_TEXT_DPROP), "1");
}
}
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.netbeans.jemmy.operators;

import org.testng.annotations.Test;

import java.awt.TextComponent;
import java.awt.TextField;

import static org.testng.Assert.assertEquals;

public class TextComponentOperatorTest {
@Test
public void selection() {
TextComponent text = new TextField("0123456789");
TextComponentOperator textOper = new TextComponentOperator(text);
assertEquals(textOper.getDump().get(TextComponentOperator.SELECTED_TEXT_DPROP), "");
text.select(1,1);
assertEquals(textOper.getDump().get(TextComponentOperator.SELECTED_TEXT_DPROP), "");
text.select(1,2);
assertEquals(textOper.getDump().get(TextComponentOperator.SELECTED_TEXT_DPROP), "1");
}
}