-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add a new parseJabRefComment with unit test #12145
base: main
Are you sure you want to change the base?
Changes from 9 commits
56c1bef
b2646ae
e12e655
465d6cf
830e7e6
065a784
3c4ee8f
fb161cf
ae98cdc
9cc8bbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,8 @@ | |
import org.jabref.model.groups.WordKeywordGroup; | ||
import org.jabref.model.metadata.SaveOrder; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -2238,4 +2240,42 @@ void parseInvalidBibDeskFilesResultsInWarnings() throws IOException { | |
|
||
assertEquals(List.of(firstEntry, secondEntry), result.getDatabase().getEntries()); | ||
} | ||
|
||
@Test | ||
void parseCommentToJson() { | ||
String entries = | ||
""" | ||
@Comment{jabref-meta-0.1.0 | ||
{ | ||
"saveActions" : | ||
{ | ||
"state": true, | ||
"date": ["normalize_date", "action2"], | ||
"pages" : ["normalize_page_numbers"], | ||
"month" : ["normalize_month"] | ||
} | ||
} | ||
"""; | ||
BibtexParser parser = new BibtexParser(importFormatPreferences); | ||
Optional<JsonObject> actualJson = parser.parseCommentToJson(entries); | ||
assertEquals(actualJson, Optional.of(getExpectedJson())); | ||
} | ||
|
||
private JsonObject getExpectedJson() { | ||
JsonObject saveActions = new JsonObject(); | ||
saveActions.addProperty("state", true); | ||
JsonArray dateArray = new JsonArray(); | ||
dateArray.add("normalize_date"); | ||
dateArray.add("action2"); | ||
saveActions.add("date", dateArray); | ||
JsonArray pagesArray = new JsonArray(); | ||
pagesArray.add("normalize_page_numbers"); | ||
saveActions.add("pages", pagesArray); | ||
JsonArray monthArray = new JsonArray(); | ||
monthArray.add("normalize_month"); | ||
saveActions.add("month", monthArray); | ||
JsonObject expectedJson = new JsonObject(); | ||
expectedJson.add("saveActions", saveActions); | ||
return expectedJson; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reads very ugly. According to https://stackoverflow.com/a/4696873/873282 it can be easier Can you try with var expected = new Object() {
... Another thought: Just simplify the contained object. you are testing the JSON reading - then put a simple JSON inside. Test one thing in one test :-) Reason: The searialization of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried using the var expected = new Object() {} style, but since Gson's JsonObject is declared as final, it throws an exception like Cannot inherit from final 'com.google.gson.JsonObject' when attempting this code:
P.S.: I had a bike accident and got injured, but I’ve finally fully recovered. Apologies for disappearing for such a long time! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im sorry to hear, I hope it wasn't too bad and you are well again. Don't worry about time, better slow and steady instead of rushing things in bad quality and never appearing again. |
||
} | ||
} |
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.
No additional spaces pleace