-
-
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 unit test to four test classes #7651
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c67512d
Added unit tests with mocks for DuplicationSearch
BShaq 35c486b
Added unit tests with mocks for ManageKeywordsViewModel
BShaq 54dbb0d
Added unit tests with mocks for GroupDiff
BShaq d74f0a7
organized imports in DuplicateSearch
BShaq 6953da2
Merge remote-tracking branch 'upstream/main' into a3-bs
BShaq 54a6e3b
Added unit test to GroupTreeNodeTest.java
BShaq 16e8b59
remove outcommeted code
BShaq b71be0d
fixed checkstyle
BShaq 4b7f78e
Merge remote-tracking branch 'upstream/main' into a3-bs
BShaq 81e79ee
switched to comparing content of lists in ManageKeywordsViewModelTest
BShaq 3ecb4f8
removed outcommented code
BShaq 97b8217
Merge remote-tracking branch 'upstream/main' into a3-bs
BShaq bd1d218
Merge remote-tracking branch 'upstream/main' into a3-bs
BShaq 540e915
compare content in GroupDiffTest.java
BShaq a867e3a
created BeforeAll method
BShaq b8c996e
fixed checkstyle issue
BShaq 42fc053
made entries creation more concise
BShaq 6cd9986
Merge remote-tracking branch 'upstream/main' into a3-bs
BShaq cd37a64
Merge branch 'a3-bs' of https://github.com/ningxie1991/jabref into a3-bs
BShaq 948f6c0
Fix checkstyle
koppor 17c5b31
Merge branch 'main' into ningxie1991-a3-bs
koppor 29718c5
Remove Globals dependency
koppor d4d8170
Fix Codacy
koppor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
103 changes: 103 additions & 0 deletions
103
src/test/java/org/jabref/gui/duplicationFinder/DuplicateSearchTest.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,103 @@ | ||
package org.jabref.gui.duplicationFinder; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.LibraryTab; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.undo.CountingUndoManager; | ||
import org.jabref.gui.undo.NamedCompound; | ||
import org.jabref.gui.util.OptionalObjectProperty; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.entry.types.StandardEntryType; | ||
import org.jabref.testutils.category.GUITest; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.testfx.framework.junit5.ApplicationExtension; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@GUITest | ||
@ExtendWith(ApplicationExtension.class) | ||
public class DuplicateSearchTest { | ||
|
||
private final DialogService dialogService = spy(DialogService.class); | ||
private final StateManager stateManager = mock(StateManager.class); | ||
private final JabRefFrame jabRefFrame = mock(JabRefFrame.class); | ||
private final LibraryTab libraryTab = mock(LibraryTab.class); | ||
private final BibDatabaseContext bibDatabaseContext = mock(BibDatabaseContext.class); | ||
private final CountingUndoManager undoManager = mock(CountingUndoManager.class); | ||
|
||
private DuplicateSearch duplicateSearch; | ||
private BibEntry entry1; | ||
|
||
@BeforeEach | ||
void setupDuplicateSearchInstance() { | ||
entry1 = new BibEntry(StandardEntryType.InProceedings) | ||
.withField(StandardField.AUTHOR, "Souti Chattopadhyay and Nicholas Nelson and Audrey Au and Natalia Morales and Christopher Sanchez and Rahul Pandita and Anita Sarma") | ||
.withField(StandardField.TITLE, "A tale from the trenches") | ||
.withField(StandardField.YEAR, "2020") | ||
.withField(StandardField.DOI, "10.1145/3377811.3380330") | ||
.withField(StandardField.SUBTITLE, "cognitive biases and software development") | ||
.withCitationKey("Chattopadhyay2020"); | ||
|
||
when(jabRefFrame.getCurrentLibraryTab()).thenReturn(libraryTab); | ||
when(stateManager.activeDatabaseProperty()).thenReturn(OptionalObjectProperty.empty()); | ||
duplicateSearch = new DuplicateSearch(jabRefFrame, dialogService, stateManager); | ||
} | ||
|
||
@Test | ||
public void executeWithNoEntries() { | ||
when(stateManager.getActiveDatabase()).thenReturn(Optional.of(bibDatabaseContext)); | ||
when(bibDatabaseContext.getEntries()).thenReturn(Collections.emptyList()); | ||
|
||
duplicateSearch.execute(); | ||
verify(dialogService, times(1)).notify(Localization.lang("Searching for duplicates...")); | ||
} | ||
|
||
@Test | ||
public void executeWithOneEntry() { | ||
when(stateManager.getActiveDatabase()).thenReturn(Optional.of(bibDatabaseContext)); | ||
when(bibDatabaseContext.getEntries()).thenReturn(Collections.singletonList(entry1)); | ||
|
||
duplicateSearch.execute(); | ||
verify(dialogService, times(1)).notify(Localization.lang("Searching for duplicates...")); | ||
} | ||
|
||
@Test | ||
public void executeWithNoDuplicates() { | ||
BibEntry entry2 = new BibEntry(StandardEntryType.InProceedings) | ||
.withField(StandardField.AUTHOR, "Tale S Sastad and Karl Thomas Hjelmervik") | ||
.withField(StandardField.TITLE, "Synthesizing Realistic, High-Resolution Anti-Submarine Sonar Data\n") | ||
.withField(StandardField.YEAR, "2018") | ||
.withField(StandardField.DOI, "10.1109/OCEANSKOBE.2018.8558837") | ||
.withCitationKey("Sastad2018"); | ||
|
||
when(stateManager.getActiveDatabase()).thenReturn(Optional.of(bibDatabaseContext)); | ||
when(bibDatabaseContext.getEntries()).thenReturn(Arrays.asList(entry1, entry2)); | ||
when(bibDatabaseContext.getMode()).thenReturn(BibDatabaseMode.BIBTEX); | ||
when(libraryTab.getBibDatabaseContext()).thenReturn(bibDatabaseContext); | ||
when(libraryTab.getDatabase()).thenReturn(mock(BibDatabase.class)); | ||
when(libraryTab.getUndoManager()).thenReturn(undoManager); | ||
when(undoManager.addEdit(mock(NamedCompound.class))).thenReturn(true); | ||
|
||
duplicateSearch.execute(); | ||
verify(dialogService, times(1)).notify(Localization.lang("Searching for duplicates...")); | ||
verify(dialogService, times(1)).notify(Localization.lang("Duplicates found") + ": " + String.valueOf(0) + ' ' | ||
+ Localization.lang("pairs processed") + ": " + String.valueOf(0)); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/test/java/org/jabref/gui/edit/ManageKeywordsViewModelTest.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,83 @@ | ||
package org.jabref.gui.edit; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.entry.types.StandardEntryType; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ManageKeywordsViewModelTest { | ||
|
||
private final PreferencesService preferences = mock(PreferencesService.class); | ||
private ManageKeywordsViewModel keywordsViewModel; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
BibEntry entryOne = new BibEntry(StandardEntryType.Article) | ||
.withField(StandardField.AUTHOR, "Prakhar Srivastava and Nishant Singh") | ||
.withField(StandardField.YEAR, "2020") | ||
.withField(StandardField.DOI, "10.1109/PARC49193.2020.236624") | ||
.withField(StandardField.ISBN, "978-1-7281-6575-2") | ||
.withField(StandardField.JOURNALTITLE, "2020 International Conference on Power Electronics & IoT Applications in Renewable Energy and its Control (PARC)") | ||
.withField(StandardField.PAGES, "351--354") | ||
.withField(StandardField.PUBLISHER, "IEEE") | ||
.withField(StandardField.TITLE, "Automatized Medical Chatbot (Medibot)") | ||
.withField(StandardField.KEYWORDS, "Human-machine interaction, Chatbot, Medical Chatbot, Natural Language Processing, Machine Learning, Bot"); | ||
|
||
BibEntry entryTwo = new BibEntry(StandardEntryType.Article) | ||
.withField(StandardField.AUTHOR, "Mladjan Jovanovic and Marcos Baez and Fabio Casati") | ||
.withField(StandardField.DATE, "November 2020") | ||
.withField(StandardField.YEAR, "2020") | ||
.withField(StandardField.DOI, "10.1109/MIC.2020.3037151") | ||
.withField(StandardField.ISSN, "1941-0131") | ||
.withField(StandardField.JOURNALTITLE, "IEEE Internet Computing") | ||
.withField(StandardField.PAGES, "1--1") | ||
.withField(StandardField.PUBLISHER, "IEEE") | ||
.withField(StandardField.TITLE, "Chatbots as conversational healthcare services") | ||
.withField(StandardField.KEYWORDS, "Chatbot, Medical services, Internet, Data collection, Medical diagnostic imaging, Automation, Vocabulary"); | ||
|
||
List<BibEntry> entries = List.of(entryOne, entryTwo); | ||
|
||
char delimiter = ','; | ||
when(preferences.getKeywordDelimiter()).thenReturn(delimiter); | ||
|
||
keywordsViewModel = new ManageKeywordsViewModel(preferences, entries); | ||
} | ||
|
||
@Test | ||
void keywordsFilledInCorrectly() { | ||
ObservableList<String> addedKeywords = keywordsViewModel.getKeywords(); | ||
List<String> expectedKeywordsList = Arrays.asList("Human-machine interaction", "Chatbot", "Medical Chatbot", | ||
"Natural Language Processing", "Machine Learning", "Bot", "Chatbot", "Medical services", "Internet", | ||
"Data collection", "Medical diagnostic imaging", "Automation", "Vocabulary"); | ||
|
||
assertEquals(FXCollections.observableList(expectedKeywordsList), addedKeywords); | ||
} | ||
|
||
@Test | ||
void removedKeywordNotIncludedInKeywordsList() { | ||
ObservableList<String> modifiedKeywords = keywordsViewModel.getKeywords(); | ||
List<String> originalKeywordsList = Arrays.asList("Human-machine interaction", "Chatbot", "Medical Chatbot", | ||
"Natural Language Processing", "Machine Learning", "Bot", "Chatbot", "Medical services", "Internet", | ||
"Data collection", "Medical diagnostic imaging", "Automation", "Vocabulary"); | ||
|
||
assertEquals(FXCollections.observableList(originalKeywordsList), modifiedKeywords, "compared lists are not identical"); | ||
|
||
keywordsViewModel.removeKeyword("Human-machine interaction"); | ||
|
||
assertNotEquals(FXCollections.observableList(originalKeywordsList), modifiedKeywords, "compared lists are identical"); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/org/jabref/logic/bibtex/comparator/GroupDiffTest.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,65 @@ | ||
package org.jabref.logic.bibtex.comparator; | ||
|
||
import java.util.Optional; | ||
|
||
import org.jabref.model.groups.AllEntriesGroup; | ||
import org.jabref.model.groups.ExplicitGroup; | ||
import org.jabref.model.groups.GroupHierarchyType; | ||
import org.jabref.model.groups.GroupTreeNode; | ||
import org.jabref.model.metadata.MetaData; | ||
|
||
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 GroupDiffTest { | ||
|
||
private final MetaData originalMetaData = mock(MetaData.class); | ||
private final MetaData newMetaData = mock(MetaData.class); | ||
private GroupTreeNode rootOriginal; | ||
|
||
@BeforeEach | ||
void setup() { | ||
rootOriginal = GroupTreeNode.fromGroup(new AllEntriesGroup("All entries")); | ||
rootOriginal.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, ',')); | ||
GroupTreeNode parent = rootOriginal | ||
.addSubgroup(new ExplicitGroup("ExplicitParent", GroupHierarchyType.INDEPENDENT, ',')); | ||
parent.addSubgroup(new ExplicitGroup("ExplicitNode", GroupHierarchyType.REFINING, ',')); | ||
} | ||
|
||
@Test | ||
void compareEmptyGroups() { | ||
when(originalMetaData.getGroups()).thenReturn(Optional.empty()); | ||
when(newMetaData.getGroups()).thenReturn(Optional.empty()); | ||
|
||
assertEquals(Optional.empty(), GroupDiff.compare(originalMetaData, newMetaData)); | ||
} | ||
|
||
@Test | ||
void compareGroupWithItself() { | ||
when(originalMetaData.getGroups()).thenReturn(Optional.of(rootOriginal)); | ||
when(newMetaData.getGroups()).thenReturn(Optional.of(rootOriginal)); | ||
|
||
assertEquals(Optional.empty(), GroupDiff.compare(originalMetaData, newMetaData)); | ||
} | ||
|
||
@Test | ||
void compareWithChangedGroup() { | ||
GroupTreeNode rootModified = GroupTreeNode.fromGroup(new AllEntriesGroup("All entries")); | ||
rootModified.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, ',')); | ||
|
||
when(originalMetaData.getGroups()).thenReturn(Optional.of(rootOriginal)); | ||
when(newMetaData.getGroups()).thenReturn(Optional.of(rootModified)); | ||
|
||
Optional<GroupDiff> groupDiff = GroupDiff.compare(originalMetaData, newMetaData); | ||
koppor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Optional<GroupDiff> expectedGroupDiff = Optional.of(new GroupDiff(newMetaData.getGroups().get(), originalMetaData.getGroups().get())); | ||
|
||
assertEquals(expectedGroupDiff.get().getNewGroupRoot(), groupDiff.get().getNewGroupRoot()); | ||
assertEquals(expectedGroupDiff.get().getOriginalGroupRoot(), groupDiff.get().getOriginalGroupRoot()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hi :)
I saw on the discussion #7636 that you would prefer using any() over a localized argument for the notify() method. The rationale for using this localized argument was to verify if dialogService shows the correct message for each condition. As @ningxie1991 pointed out, would the dialogService somehow loose its purpose when using any() as the argument?
Moreover, in this case, if I use the localized argument, both very() methods work, but by using any() as argument I receive the feedback that the dialogService got invoked only once. So, what did I miss on here?
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.
It's okay to use the correct localization argument. I think we thought that it just verifies the numbers of calls, but not the content