-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
remove Deprecated getText() #11841
Conversation
remove Deprecated getText()
@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. |
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?
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
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
// 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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
remove import org.jspecify.annotations.Nullable;
Head branch was pushed to by a user without write access
* 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>
* 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>
* 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>
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)