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

Real test linking real other entry #3214

Merged
merged 9 commits into from
Sep 14, 2017
Merged

Real test linking real other entry #3214

merged 9 commits into from
Sep 14, 2017

Conversation

sammann-fnordkollektiv
Copy link

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

Why
Based on #3191 (comment) I added two tests concerning cross referencing.

What

  1. It is based on two dummy entries, where source is cross referencing target.
  2. It reads the database from mentioned example bib file: https://github.com/JabRef/jabref/blob/master/src/test/resources/testbib/crossref.bib and asserts cross reference of two given entries.

Watchout

  • I was not able to clean code method assertSourceCrossrefsTarget further due to the Optional<> concept.
  • I wrote a small TestDataBuilder BibEntryBuild. It is an inner class, because I am uncertain where to put it.
  • I wrote an crossref.bib-encapsulating class DatabaseFromFile to keep test code readable. It is an inner class, because I did not find a similar wrapper nor did I know where to put it. Its construction uses a path to a file to be parsed to a database.

String expectedCrossrefValue = targetCiteKey.get();
crossrefs = actualcrossrefValue.contains(expectedCrossrefValue);
}
assertTrue(crossrefs);
Copy link
Member

Choose a reason for hiding this comment

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

Are you aware that you can directly call assertEquals on two optionals?
https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#equals-java.lang.Object-


@Test
public void givenTargetAndSourceWhenSourceCrossrefTargetThenSourceCrossrefsTarget() {
target = BibEntryBuild.ing().withId("target").withCiteKey("target").now();
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 see why it's necessary to have a BibEntry build class?
Why not just simply create two new BibEntrys? And you won't need the actual database file.

e.g.

database = new BibDatabase()
BibEntry source = new BibEntry()
source.setCiteKey("source")
source.setField(Crossref, "target")
database.insert(source)
BibEntry target = new BibEntry()
target.setCiteKey("target")
database.insert(target)

Copy link
Member

Choose a reason for hiding this comment

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

Put that in the before method and it will be "freshly created" for every test

Copy link
Member

Choose a reason for hiding this comment

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

BibEntry actually contains a withField method if you want to use a more fluent api,

public BibEntry withField(String field, String value) {
setField(field, value);
return this;
}

If you want, you can also add a new method withCiteKey along these lines.

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

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

Your test code looks a bit more complicated than it could be.
You don't need to access a real bib file on the disk.

@sammann-fnordkollektiv
Copy link
Author

Thank you for your valuable feedback, I learned a lot and implemented all change requests

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

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

Now it looks good to me!

@LinusDietz LinusDietz merged commit d941731 into JabRef:master Sep 14, 2017
Siedlerchr added a commit that referenced this pull request Sep 15, 2017
* upstream/master:
  Add tests for removal changes
  Improve telemetry (#3218)
  Real test linking real other entry (#3214)
  Check for explicit group at different location
  Update java-string-similarity from 0.24 -> 1.0.0
  Only remove ExplicitGroups from entries, but not keyword-based groups
  Remove unused import in GroupTreeNode
  Move getEntriesInGroup to GroupTreeNode
  Inline Consumer updateViewModel
  Undo IntelliJ autoformat of FXML annotations
  Remove unused import
  Rewrite selection logic to avoid NPEs
  Clear group selection when a group is removed
  Also remove a group from entries when you remove it
@sammann-fnordkollektiv sammann-fnordkollektiv deleted the real-test-linking-real-other-entry branch September 16, 2017 19:43
Siedlerchr added a commit that referenced this pull request Sep 23, 2017
* upstream/master: (188 commits)
  Show file description only if not empty
  Add file description to gui and fix sync bug (#3210)
  Don't highlight odd rows in file list editor (#3223)
  Fix assertion by removing typo (#3220)
  Update assertion to change of online reference (#3221)
  Put in null return
  Reformatted code, renamed method, added try/catch
  Add tests for removal changes
  Improve telemetry (#3218)
  Real test linking real other entry (#3214)
  Check for explicit group at different location
  Update java-string-similarity from 0.24 -> 1.0.0
  Only remove ExplicitGroups from entries, but not keyword-based groups
  Localization: French: Translation of a new string (#3212)
  Fix null return
  Changed from Path to Optional<Path>
  Fix #2775: Hyphens in last names are properly parsed (#3209)
  Followup to Issue #3167 (#3202)
  Remove unused import in GroupTreeNode
  Move getEntriesInGroup to GroupTreeNode
  ...
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.

4 participants