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

remove Deprecated getText() #11841

Merged
merged 7 commits into from
Oct 17, 2024
Merged

remove Deprecated getText() #11841

merged 7 commits into from
Oct 17, 2024

Conversation

leaf-soba
Copy link
Contributor

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

remove Deprecated getText()
@koppor
Copy link
Member

koppor commented Sep 27, 2024

@leaf-soba you see the failing test? Should be easy to fix 😅

�[0Korg.jabref.logic.layout.LayoutTest�[m

�[0K Test beginConditionals() FAILED

java.lang.NullPointerException: Cannot invoke "org.jabref.model.database.BibDatabase.resolveForStrings(String)" because "database" is null

@leaf-soba
Copy link
Contributor Author

@leaf-soba you see the failing test? Should be easy to fix 😅

�[0Korg.jabref.logic.layout.LayoutTest�[m

�[0K Test beginConditionals() FAILED

java.lang.NullPointerException: Cannot invoke "org.jabref.model.database.BibDatabase.resolveForStrings(String)" because "database" is null

sorry I submit it too hurry forget to run the test this time, I'll fix it.

@koppor
Copy link
Member

koppor commented Sep 29, 2024

sorry I submit it too hurry forget to run the test this time, I'll fix it.

No worries. We mostly do, too. (Main reason: Not all test succeed on Windows or MacOS locally - refs #9992).

The important thing is to check the GitHub output 30 minutes after a push ^^.

Maybe I should add more unit test based on my change?
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Very small nitpick (because we are aiming for clean code)

One other comment. While thinking through. Did you check your new code with code coverage (by tests)?

@@ -230,6 +230,16 @@ public String doLayout(BibEntry bibtex, BibDatabase database) {
}
}

private String resolveFieldEntry(BibEntry bibtex, BibDatabase database) {
Copy link
Member

Choose a reason for hiding this comment

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

Rename variable bibtex to `bibEntry - consistency with other code.

@@ -360,7 +368,10 @@ public String doLayout(BibDatabaseContext databaseContext, Charset encoding) {
throw new UnsupportedOperationException("field and group ends not allowed in begin or end layout");

case LayoutHelper.IS_OPTION_FIELD:
String field = BibDatabase.getText(text, databaseContext.getDatabase());
String field = Optional.ofNullable(databaseContext)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is necessary - the old code assumed that databaseContext is never null (otherwise an NPE would be there)

@@ -360,7 +368,10 @@ public String doLayout(BibDatabaseContext databaseContext, Charset encoding) {
throw new UnsupportedOperationException("field and group ends not allowed in begin or end layout");

case LayoutHelper.IS_OPTION_FIELD:
String field = BibDatabase.getText(text, databaseContext.getDatabase());
String field = Optional.ofNullable(databaseContext)
.map(BibDatabaseContext::getDatabase)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could be null?

@leaf-soba
Copy link
Contributor Author

leaf-soba commented Sep 30, 2024

Very small nitpick (because we are aiming for clean code)

One other comment. While thinking through. Did you check your new code with code coverage (by tests)?

Yes I did check it with old unit test code, but I think maybe we need more test. Sorry I'm a little busy yesterday, so I just wrote "need more unit test" in the commit message, I think I'll add more test today.

1. more unit test
2. rollback logic to follow old code which assumed that databaseContext is never null
@leaf-soba leaf-soba requested a review from koppor September 30, 2024 14:37
Comment on lines 124 to 132
// test IS_LAYOUT_TEXT
assertLayoutResult(1, "testString", parsedEntries, bibDatabaseContext);
// test IS_OPTION_FIELD with empty dataBase in BibDatabaseContext
assertLayoutResult(5, "testString", parsedEntries, bibDatabaseContext);
// test IS_ENCODING_NAME
assertLayoutResult(8, StandardCharsets.UTF_8.toString(), parsedEntries, bibDatabaseContext);
// test IS_FILENAME and IS_FILEPATH with empty path
assertLayoutResult(9, "", parsedEntries, bibDatabaseContext);
assertLayoutResult(10, "", parsedEntries, bibDatabaseContext);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like @ParameterizedTest should be used. --> There should be only one assertion per test case. (More readings at https://devdocs.jabref.org/code-howtos/testing.html#general-hints-on-tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My account was flagged by automated systems while I didn't do anything violate the terms of service, finally I get my account back by sending ticket. Sorry for left this PR behind about 15 days.

Copy link
Member

Choose a reason for hiding this comment

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

Welcome back! - I started to miss you - good to hear that you are back! Looking forward for more code-quality pull requests. Especially many tests should be converted to @ParameterizedTests. - I can send you pointers if I come along of some of these.

change to @ParameterizedTest test
List<StringInt> parsedEntries = List.of(new StringInt("place_holder", 0),
new StringInt("testString", 0));
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData(), null);
assertUnsupportedOperation(type, parsedEntries, bibDatabaseContext);
Copy link
Member

Choose a reason for hiding this comment

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

Inline the helper method - that helper method is used only here. No need to have a separeate method for two liens of code.

List<StringInt> parsedEntries = List.of(new StringInt("place_holder", 0),
new StringInt("testString", 0));
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData(), null);
assertLayoutResult(type, expectedValue, parsedEntries, bibDatabaseContext);
Copy link
Member

Choose a reason for hiding this comment

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

Inline the helper method - that helper method is used only here. No need to have a separeate method for two liens of code.

"9, ''",
"10, ''"
})
void testLayoutResult(int type, String expectedValue) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why OpenRewrite does not state anything (https://docs.openrewrite.org/recipes/java/testing/cleanup/removetestprefix)

--> test names should not start with test just remove test and strt with a lower case L.

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 wonder why OpenRewrite does not state anything

Because it seems there is a conflict with main, the OpenRewrite didn't start to work in this situation.

"6",
"7"
})
void testUnsupportedOperationTypes(int type) {
Copy link
Member

Choose a reason for hiding this comment

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

Remove test prefix.

1. remove test prefix
2. remove unnecessary inline the helper method
3. fix a type
4. two minor refactor in both files.
koppor
koppor previously approved these changes Oct 17, 2024
koppor
koppor previously approved these changes Oct 17, 2024
remove import org.jspecify.annotations.Nullable;
auto-merge was automatically disabled October 17, 2024 07:29

Head branch was pushed to by a user without write access

@koppor koppor enabled auto-merge October 17, 2024 07:33
@koppor koppor added this pull request to the merge queue Oct 17, 2024
Merged via the queue into JabRef:main with commit 62badb9 Oct 17, 2024
23 of 26 checks passed
ExrosZ pushed a commit to ExrosZ/jabref that referenced this pull request Oct 17, 2024
* remove Deprecated getText()

remove Deprecated getText()

* Fix the code to pass unit test

Maybe I should add more unit test based on my change?

* Add more unit test to support my change

1. more unit test
2. rollback logic to follow old code which assumed that databaseContext is never null

* change to @ParameterizedTest test

change to @ParameterizedTest test

* update follow requested change

1. remove test prefix
2. remove unnecessary inline the helper method
3. fix a type
4. two minor refactor in both files.

* remove unused import

remove import org.jspecify.annotations.Nullable;

---------

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
ExrosZ pushed a commit to ExrosZ/jabref that referenced this pull request Oct 17, 2024
* remove Deprecated getText()

remove Deprecated getText()

* Fix the code to pass unit test

Maybe I should add more unit test based on my change?

* Add more unit test to support my change

1. more unit test
2. rollback logic to follow old code which assumed that databaseContext is never null

* change to @ParameterizedTest test

change to @ParameterizedTest test

* update follow requested change

1. remove test prefix
2. remove unnecessary inline the helper method
3. fix a type
4. two minor refactor in both files.

* remove unused import

remove import org.jspecify.annotations.Nullable;

---------

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
ExrosZ pushed a commit to ExrosZ/jabref that referenced this pull request Oct 21, 2024
* remove Deprecated getText()

remove Deprecated getText()

* Fix the code to pass unit test

Maybe I should add more unit test based on my change?

* Add more unit test to support my change

1. more unit test
2. rollback logic to follow old code which assumed that databaseContext is never null

* change to @ParameterizedTest test

change to @ParameterizedTest test

* update follow requested change

1. remove test prefix
2. remove unnecessary inline the helper method
3. fix a type
4. two minor refactor in both files.

* remove unused import

remove import org.jspecify.annotations.Nullable;

---------

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants