Skip to content

8347359: RichTextArea API Tests #1677

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

Conversation

andy-goryachev-oracle
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle commented Jan 14, 2025

Additional RichTextArea API tests.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1677/head:pull/1677
$ git checkout pull/1677

Update a local copy of the PR:
$ git checkout pull/1677
$ git pull https://git.openjdk.org/jfx.git pull/1677/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1677

View PR using the GUI difftool:
$ git pr show -t 1677

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1677.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 14, 2025

👋 Welcome back angorya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 14, 2025

@andy-goryachev-oracle This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8347359: RichTextArea API Tests

Reviewed-by: kcr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 3 new commits pushed to the master branch:

  • 1a12966: 8354478: Improve StageStyle documentation
  • 4df2326: 8352162: Update libxml2 to 2.13.8
  • 46b36fe: 8354876: Update SQLite to 3.49.1

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Jan 28, 2025

⚠️ @andy-goryachev-oracle This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@andy-goryachev-oracle andy-goryachev-oracle marked this pull request as ready for review January 29, 2025 16:41
@andy-goryachev-oracle
Copy link
Contributor Author

one reviewer is probably fine, but feel free to take a look everyone.

@openjdk openjdk bot added the rfr Ready for review label Jan 29, 2025
@mlbridge
Copy link

mlbridge bot commented Jan 29, 2025

Webrevs

@kevinrushforth kevinrushforth self-requested a review January 29, 2025 20:22
@bridgekeeper
Copy link

bridgekeeper bot commented Feb 26, 2025

@andy-goryachev-oracle This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@andy-goryachev-oracle
Copy link
Contributor Author

keep-alive

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 27, 2025

@andy-goryachev-oracle This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@andy-goryachev-oracle
Copy link
Contributor Author

@arapte or @Ziad-Mid please review

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First batch of comments. This looks like a good start for RichTextArea and CodeArea. I presume you'll handle the rest of the API with other bugs / PRs?

Some of my comments are about expanding the test coverage to handle more cases, and that could be done when you add functional tests.

Comment on lines 48 to 49
if (throwable instanceof RuntimeException) {
throw (RuntimeException)throwable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is RuntimeException treated differently than checked Exception and Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... This pattern was copied from some other test. We have 32 more instances of this pattern elsewhere.

I suspect it is not avoid declaring a checked exception.
What would you suggest? Forward the throwable to Thread.currentThread().getThreadGroup().uncaughtException(thread, throwable); unconditionally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting that other tests do this. When re-throwing an exception you often need to special case checked exceptions (to wrap them so that the caller doesn't need to explicitly declare it), but the UncaughtExceptionHandler can handle both, so I don't know why it was done that way.

You might try just unconditionally forwarding all throwables, but not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, this is required by junit framework to properly handle the failed tests.

If we pass all the Throwables to the thread group, then a RuntimeException thrown from a @Test does not mark the unit test as failed, though the stacktrace does appear in stderr; a thrown Error will mark the test as failed.

import javafx.beans.property.SimpleObjectProperty;

/**
* There should be a common place for module-agnostic test utilities.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javafx.base might eventually be a good place for this sort of utility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might, or perhaps it could be packaged into a jar so we can run single source files + library via JEP 458 --class-path 'libs/*' argument?

see "Using pre-compiled classes" section in
https://openjdk.org/jeps/458

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests already need to load the JavaFX modules, so I don't see how packaging it in a jar would help. All it would do it add one more thing to put on the path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the single-file manual tests, continuing discussion in #1747

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I didn't get that from the context of this discussion, since we are discussing automated tests in this PR.

I'm not sure there is enough value in sharing utilities between manual tests and our JUnit-based automated tests for us to want to deal with the complexities that it would bring, but we can discuss that separately (not here).

/**
* There should be a common place for module-agnostic test utilities.
*/
public class TUtil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is intended to be a static utility class, maybe add a private constructor to underscore this?

/**
* Utilities for RichTextArea-based tests.
*/
public class RTUtil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: add a private constructor

String[] lines = text.split("\n");
ArrayList<StyledSegment> ss = new ArrayList<>();
for (int i = 0; i < lines.length; i++) {
if(i > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: space after if

}

// @Test
// public void insertLineBreak() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out? A comment explaining why would be good. Or if there is a functional bug that prevents it, uncomment it and skip it with @Disabled("JDK-8888888").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// }

@Test
public void isRedoable() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also have functional tests for undo/redo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, undo() and redo()

I tried to exercise every public method to some extent.

}

@Test
public void modelChangeClearsSelection() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the actual data is sorted in the model, it might also be good to test that a model change clears all of the text that you have previously appended (in another test method).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the actual data is sorted

Typo, I meant "stored"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each test starts with a freshly created model, but it's a good idea to add a check for the content.

}

@Test
public void redo() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test of the undo / redo stack would be helpful (this tests a single undo/redo value, so is a good first step, but doesn't test its "stack" nature).

assertTrue(control.getModel() == null);

control = new CodeArea(null);
control.setModel(new CodeTextModel() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Check that the model you set can be read back.

@andy-goryachev-oracle
Copy link
Contributor Author

Thank you, Kevin, good suggestions.

I presume you'll handle the rest of the API with other bugs / PRs?

Correct - the idea is to follow up with headful behavioral test(s).

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll reapprove if you make further changes.

Comment on lines 321 to 322
@Disabled("JDK-8355415")
// TODO combine with copy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I might switch these two lines to keep all the annotations together.

@openjdk openjdk bot added the ready Ready to be integrated label Apr 23, 2025
@openjdk openjdk bot removed the ready Ready to be integrated label Apr 23, 2025
@openjdk openjdk bot added the ready Ready to be integrated label Apr 23, 2025
@andy-goryachev-oracle
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Apr 23, 2025

Going to push as commit 1b2f022d0c08d556d0decdf71d6e0c9d13dbe6f8.
Since your change was applied there have been 3 commits pushed to the master branch:

  • 1a12966: 8354478: Improve StageStyle documentation
  • 4df2326: 8352162: Update libxml2 to 2.13.8
  • 46b36fe: 8354876: Update SQLite to 3.49.1

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 23, 2025
@openjdk openjdk bot closed this Apr 23, 2025
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Apr 23, 2025
@openjdk
Copy link

openjdk bot commented Apr 23, 2025

@andy-goryachev-oracle Pushed as commit 1b2f022.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andy-goryachev-oracle andy-goryachev-oracle deleted the 8347359.rta.api.tests branch April 23, 2025 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants