Search in sources :

Example 6 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class IntegrityCheckTest method assertCorrect.

private void assertCorrect(BibDatabaseContext context) {
    List<IntegrityMessage> messages = new IntegrityCheck(context, mock(FileDirectoryPreferences.class), createBibtexKeyPatternPreferences(), new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW"))).checkBibtexDatabase();
    assertEquals(Collections.emptyList(), messages);
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) JournalAbbreviationRepository(org.jabref.logic.journals.JournalAbbreviationRepository)

Example 7 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class IntegrityCheckTest method testEntryIsUnchangedAfterChecks.

@Test
public void testEntryIsUnchangedAfterChecks() {
    BibEntry entry = new BibEntry();
    // populate with all known fields
    for (String fieldName : InternalBibtexFields.getAllPublicAndInternalFieldNames()) {
        entry.setField(fieldName, UUID.randomUUID().toString());
    }
    // add a random field
    entry.setField(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    // duplicate entry
    BibEntry clonedEntry = (BibEntry) entry.clone();
    BibDatabase bibDatabase = new BibDatabase();
    bibDatabase.insertEntry(entry);
    BibDatabaseContext context = new BibDatabaseContext(bibDatabase, new Defaults());
    new IntegrityCheck(context, mock(FileDirectoryPreferences.class), createBibtexKeyPatternPreferences(), new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW"))).checkBibtexDatabase();
    assertEquals(clonedEntry, entry);
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) BibEntry(org.jabref.model.entry.BibEntry) Defaults(org.jabref.model.Defaults) JournalAbbreviationRepository(org.jabref.logic.journals.JournalAbbreviationRepository) BibDatabase(org.jabref.model.database.BibDatabase) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Test(org.junit.Test)

Example 8 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class ManageJournalAbbreviationsViewModelTest method testDeleteAbbreviationSelectsPreviousOne.

@Test
public void testDeleteAbbreviationSelectsPreviousOne() throws Exception {
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile4Entries));
    viewModel.addNewFile();
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate));
    viewModel.addNewFile();
    viewModel.selectLastJournalFile();
    Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE");
    addAbbrevaition(testAbbreviation);
    Assert.assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)));
    Assert.assertEquals(new AbbreviationViewModel(testAbbreviation), viewModel.currentAbbreviationProperty().get());
    viewModel.deleteAbbreviation();
    Assert.assertEquals(5, viewModel.abbreviationsProperty().size());
    // check if the previous (the last) element is the current abbreviation
    Assert.assertEquals(viewModel.currentAbbreviationProperty().get(), viewModel.abbreviationsProperty().get(4));
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) Test(org.junit.Test)

Example 9 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class ManageJournalAbbreviationsViewModelTest method testSaveAbbreviationsToFilesCreatesNewFilesWithWrittenAbbreviations.

@Test
public void testSaveAbbreviationsToFilesCreatesNewFilesWithWrittenAbbreviations() throws Exception {
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile4Entries));
    viewModel.addNewFile();
    viewModel.selectLastJournalFile();
    selectLastAbbreviation();
    Abbreviation testAbbreviation = new Abbreviation("JabRefTestEntry", "JTE");
    editAbbreviation(testAbbreviation);
    Assert.assertEquals(5, viewModel.abbreviationsProperty().size());
    Assert.assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)));
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate));
    viewModel.addNewFile();
    viewModel.selectLastJournalFile();
    selectLastAbbreviation();
    viewModel.deleteAbbreviation();
    Abbreviation testAbbreviation1 = new Abbreviation("SomeOtherEntry", "SOE");
    addAbbrevaition(testAbbreviation1);
    Assert.assertEquals(5, viewModel.abbreviationsProperty().size());
    Assert.assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation1)));
    viewModel.saveJournalAbbreviationFiles();
    String expected = "Abbreviations = Abb" + NEWLINE + "Test Entry = TE" + NEWLINE + "MoreEntries = ME" + NEWLINE + "JabRefTestEntry = JTE" + NEWLINE + "";
    String actual = Files.contentOf(testFile4Entries.toFile(), StandardCharsets.UTF_8);
    Assert.assertEquals(expected, actual);
    expected = "Abbreviations = Abb" + NEWLINE + "Test Entry = TE" + NEWLINE + "MoreEntries = ME" + NEWLINE + "SomeOtherEntry = SOE" + NEWLINE + "";
    actual = Files.contentOf(testFile5EntriesWithDuplicate.toFile(), StandardCharsets.UTF_8);
    Assert.assertEquals(expected, actual);
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class ManageJournalAbbreviationsViewModelTest method testEditSameAbbreviationWithNoChangeDoesNotResultInException.

@Test
public void testEditSameAbbreviationWithNoChangeDoesNotResultInException() throws Exception {
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile));
    viewModel.addNewFile();
    viewModel.selectLastJournalFile();
    Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE");
    addAbbrevaition(testAbbreviation);
    editAbbreviation(testAbbreviation);
    Assert.assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)));
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) Test(org.junit.Test)

Aggregations

Abbreviation (org.jabref.logic.journals.Abbreviation)15 Test (org.junit.Test)9 JournalAbbreviationRepository (org.jabref.logic.journals.JournalAbbreviationRepository)3 DefaultTableModel (javax.swing.table.DefaultTableModel)1 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)1 Defaults (org.jabref.model.Defaults)1 BibDatabase (org.jabref.model.database.BibDatabase)1 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)1 BibEntry (org.jabref.model.entry.BibEntry)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1