package net.sf.jabref.logic.journals;

import static org.junit.Assert.*;

import org.junit.Test;

public class JournalAbbreviationRepositoryTest {

    @Test
    public void empty() {
        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();
        assertEquals(0, repository.size());
        assertTrue(repository.getAbbreviations().isEmpty());
    }

    @Test
    public void oneElement() {
        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();
        repository.addEntry(new Abbreviation("Long Name", "L. N."));
        assertEquals(1, repository.size());
        assertFalse(repository.getAbbreviations().isEmpty());

        assertEquals("L. N.", repository.getIsoAbbreviation("Long Name").orElse("WRONG"));
        assertEquals("UNKNOWN", repository.getIsoAbbreviation("?").orElse("UNKNOWN"));

        assertEquals("L N", repository.getMedlineAbbreviation("Long Name").orElse("WRONG"));
        assertEquals("UNKNOWN", repository.getMedlineAbbreviation("?").orElse("UNKNOWN"));

        assertEquals("L. N.", repository.getNextAbbreviation("Long Name").orElse("WRONG"));
        assertEquals("L N", repository.getNextAbbreviation("L. N.").orElse("WRONG"));
        assertEquals("Long Name", repository.getNextAbbreviation("L N").orElse("WRONG"));
        assertEquals("UNKNOWN", repository.getNextAbbreviation("?").orElse("UNKNOWN"));

        assertTrue(repository.isKnownName("Long Name"));
        assertTrue(repository.isKnownName("L. N."));
        assertTrue(repository.isKnownName("L N"));
        assertFalse(repository.isKnownName("?"));

        assertEquals(String.format("Long Name = L. N.%n"), repository.toPropertiesString());
    }

    @Test
    public void testSorting() {
        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();
        repository.addEntry(new Abbreviation("Long Name", "L. N."));
        repository.addEntry(new Abbreviation("A Long Name", "AL. N."));
        assertEquals("A Long Name", repository.getAbbreviations().first().getName());
        assertEquals("Long Name", repository.getAbbreviations().last().getName());
    }

    @Test
    public void testDuplicates() {
        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();
        repository.addEntry(new Abbreviation("Long Name", "L. N."));
        repository.addEntry(new Abbreviation("Long Name", "L. N."));
        assertEquals(1, repository.size());
    }

    @Test
    public void testDuplicateKeys() {
        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();
        repository.addEntry(new Abbreviation("Long Name", "L. N."));
        assertEquals(1, repository.size());
        assertEquals("L. N.", repository.getIsoAbbreviation("Long Name").orElse("WRONG"));

        repository.addEntry(new Abbreviation("Long Name", "LA. N."));
        assertEquals(1, repository.size());
        assertEquals("LA. N.", repository.getIsoAbbreviation("Long Name").orElse("WRONG"));

        assertEquals("Long Name = LA. N.", repository.getAbbreviations().first().toPropertiesLine());
    }

    @Test
    public void testParsing() {
        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();
        repository.readJournalListFromResource(Abbreviations.JOURNALS_FILE_BUILTIN);
        repository.readJournalListFromResource(Abbreviations.JOURNALS_IEEE_INTERNAL_LIST);
        assertTrue(!repository.getAbbreviations().isEmpty());
    }

}
@@ -2476,32 +2476,550 @@
 size());%0A    %7D%0A%0A
+    @Test%0A    public void testDuplicatesIsoOnly() %7B%0A        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();%0A        repository.addEntry(new Abbreviation(%22Old Long Name%22, %22L. N.%22));%0A        repository.addEntry(new Abbreviation(%22New Long Name%22, %22L. N.%22));%0A        assertEquals(2, repository.size());%0A%0A        assertEquals(%22L N%22, repository.getNextAbbreviation(%22L. N.%22).orElse(%22WRONG%22));%0A        assertEquals(%22New Long Name%22, repository.getNextAbbreviation(%22L N%22).orElse(%22WRONG%22));%0A    %7D%0A%0A
     @Test%0A    pu
@@ -3663,380 +3663,5 @@
  %7D%0A%0A
-    @Test%0A    public void testParsing() %7B%0A        JournalAbbreviationRepository repository = new JournalAbbreviationRepository();%0A        repository.readJournalListFromResource(Abbreviations.JOURNALS_FILE_BUILTIN);%0A        repository.readJournalListFromResource(Abbreviations.JOURNALS_IEEE_INTERNAL_LIST);%0A        assertTrue(!repository.getAbbreviations().isEmpty());%0A    %7D%0A%0A
 %7D

Add test to explain the issue when two abbreviations have different names but the same key.