-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add more unit tests * Delete unnecessary test * Override equals method for easier testing Address the requested changes from #7638 * Fix checkstyle * Suggested changes & no Id comparison in BibtexString * Compare optionals and compare lists
- Loading branch information
Showing
5 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jabref.logic.bibtex.comparator; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.entry.BibtexString; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class BibStringDiffTest { | ||
|
||
private final BibDatabase originalDataBase = mock(BibDatabase.class); | ||
private final BibDatabase newDataBase = mock(BibDatabase.class); | ||
private final BibStringDiff diff = new BibStringDiff(new BibtexString("name2", "content2"), new BibtexString("name2", "content3")); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(originalDataBase.hasNoStrings()).thenReturn(false); | ||
when(newDataBase.hasNoStrings()).thenReturn(false); | ||
when(originalDataBase.getStringValues()).thenReturn(List.of(new BibtexString("name", "content"), new BibtexString("name2", "content2"))); | ||
when(newDataBase.getStringValues()).thenReturn(List.of(new BibtexString("name", "content"), new BibtexString("name2", "content3"))); | ||
} | ||
|
||
@Test | ||
void compareTest() { | ||
List<BibStringDiff> result = BibStringDiff.compare(originalDataBase, newDataBase); | ||
assertEquals(List.of(diff), result); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/org/jabref/logic/bibtex/comparator/PreambleDiffTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.jabref.logic.bibtex.comparator; | ||
|
||
import java.util.Optional; | ||
|
||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class PreambleDiffTest { | ||
|
||
private final BibDatabaseContext originalDataBaseContext = mock(BibDatabaseContext.class); | ||
private final BibDatabaseContext newDataBaseContext = mock(BibDatabaseContext.class); | ||
private final BibDatabase originalDataBase = mock(BibDatabase.class); | ||
private final BibDatabase newDataBase = mock(BibDatabase.class); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(originalDataBaseContext.getDatabase()).thenReturn(originalDataBase); | ||
when(newDataBaseContext.getDatabase()).thenReturn(newDataBase); | ||
} | ||
|
||
@Test | ||
void compareSamePreambleTest() { | ||
when(originalDataBase.getPreamble()).thenReturn(Optional.of("preamble")); | ||
when(newDataBase.getPreamble()).thenReturn(Optional.of("preamble")); | ||
|
||
assertEquals(Optional.empty(), PreambleDiff.compare(originalDataBaseContext, newDataBaseContext)); | ||
} | ||
|
||
@Test | ||
void compareDifferentPreambleTest() { | ||
when(originalDataBase.getPreamble()).thenReturn(Optional.of("preamble")); | ||
when(newDataBase.getPreamble()).thenReturn(Optional.of("otherPreamble")); | ||
|
||
Optional<PreambleDiff> expected = Optional.of(new PreambleDiff("preamble", "otherPreamble")); | ||
Optional<PreambleDiff> result = PreambleDiff.compare(originalDataBaseContext, newDataBaseContext); | ||
assertEquals(expected, result); | ||
} | ||
} |