- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3k
Add simple Unit Tests for #6207 #6240
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
          
     Merged
      
      
            koppor
  merged 20 commits into
  JabRef:dimitra-karadima-fix-for-issue-6207
from
dimitra-karadima:fix-for-issue-6207
  
      
      
   
  May 13, 2020 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            20 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b9c73fd
              
                Unit tests improvement for #6207
              
              
                dimitra-karadima b37a921
              
                Fix some problems
              
              
                dimitra-karadima fe9546d
              
                Fix merge conflict
              
              
                dimitra-karadima 02e8f67
              
                Add more unit tests
              
              
                dimitra-karadima b204b6b
              
                Solve some issues
              
              
                dimitra-karadima 0595351
              
                Merge from upstream/master
              
              
                dimitra-karadima 3a4f9d7
              
                Rework the added tests
              
              
                dimitra-karadima c9320d4
              
                Merge branch 'master' into fix-for-issue-6207
              
              
                dimitra-karadima ed2e7ea
              
                Fix conflicts
              
              
                dimitra-karadima dc72c05
              
                Merge master to branch
              
              
                dimitra-karadima 3933821
              
                Merge branch 'master' into fix-for-issue-6207
              
              
                koppor ca9f2f4
              
                Rework IntegrityCheckTest and BibtexKeyCheckerTest
              
              
                dimitra-karadima 207b28f
              
                Change JournalInAbbreviationListCheckerTest
              
              
                dimitra-karadima 1544c73
              
                Remove @BeforeEach from test classes
              
              
                dimitra-karadima 16129ca
              
                Rework EditionCheckerTest
              
              
                dimitra-karadima 870ce0d
              
                Fix checkstyle
              
              
                dimitra-karadima 8529050
              
                Fix checkstyle again
              
              
                dimitra-karadima 193d420
              
                Rework PersonNamesCheckersTest
              
              
                dimitra-karadima 08afd12
              
                Update PersonNamesCheckerTest
              
              
                dimitra-karadima 4eae95a
              
                Update IntegrityCheckTest
              
              
                dimitra-karadima 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
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,36 @@ | ||
| package org.jabref.logic.integrity; | ||
|  | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|  | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.field.StandardField; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|  | ||
| public class ASCIICharacterCheckerTest { | ||
|  | ||
| private final ASCIICharacterChecker checker = new ASCIICharacterChecker(); | ||
| private final BibEntry entry = new BibEntry(); | ||
|  | ||
| @Test | ||
| void fieldAcceptsAsciiCharacters() { | ||
| entry.setField(StandardField.TITLE, "Only ascii characters!'@12"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldDoesNotAcceptUmlauts() { | ||
| entry.setField(StandardField.MONTH, "Umlauts are nöt ällowed"); | ||
| assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.MONTH)), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldDoesNotAcceptUnicode() { | ||
| entry.setField(StandardField.AUTHOR, "Some unicode ⊕"); | ||
| assertEquals(List.of(new IntegrityMessage("Non-ASCII encoded character found", entry, StandardField.AUTHOR)), checker.check(entry)); | ||
| } | ||
|  | ||
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
              
        
          
          
            47 changes: 47 additions & 0 deletions
          
          47 
        
  src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,47 @@ | ||
| package org.jabref.logic.integrity; | ||
|  | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|  | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.field.StandardField; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|  | ||
| public class BibStringCheckerTest { | ||
|  | ||
| private final BibStringChecker checker = new BibStringChecker(); | ||
| private final BibEntry entry = new BibEntry(); | ||
|  | ||
| @Test | ||
| void fieldAcceptsNoHashMarks() { | ||
| entry.setField(StandardField.TITLE, "Not a single hash mark"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void monthAcceptsEvenNumberOfHashMarks() { | ||
| entry.setField(StandardField.MONTH, "#jan#"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void authorAcceptsEvenNumberOfHashMarks() { | ||
| entry.setField(StandardField.AUTHOR, "#einstein# and #newton#"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void monthDoesNotAcceptOddNumberOfHashMarks() { | ||
| entry.setField(StandardField.MONTH, "#jan"); | ||
| assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.MONTH)), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void authorDoesNotAcceptOddNumberOfHashMarks() { | ||
| entry.setField(StandardField.AUTHOR, "#einstein# #amp; #newton#"); | ||
| assertEquals(List.of(new IntegrityMessage("odd number of unescaped '#'", entry, StandardField.AUTHOR)), checker.check(entry)); | ||
| } | ||
| } | 
        
          
          
            26 changes: 26 additions & 0 deletions
          
          26 
        
  src/test/java/org/jabref/logic/integrity/BibtexKeyCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,26 @@ | ||
| package org.jabref.logic.integrity; | ||
|  | ||
| import java.util.Collections; | ||
|  | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.field.InternalField; | ||
| import org.jabref.model.entry.field.StandardField; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|  | ||
| public class BibtexKeyCheckerTest { | ||
|  | ||
| private final BibtexKeyChecker checker = new BibtexKeyChecker(); | ||
| private final BibEntry entry = new BibEntry(); | ||
|  | ||
| @Test | ||
| void bibTexAcceptsKeyFromAuthorAndYear() { | ||
| entry.setField(InternalField.KEY_FIELD, "Knuth2014"); | ||
| entry.setField(StandardField.AUTHOR, "Knuth"); | ||
| entry.setField(StandardField.YEAR, "2014"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| } | 
        
          
          
            24 changes: 24 additions & 0 deletions
          
          24 
        
  src/test/java/org/jabref/logic/integrity/BooktitleCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,24 @@ | ||
| package org.jabref.logic.integrity; | ||
|  | ||
| import java.util.Optional; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|  | ||
| public class BooktitleCheckerTest { | ||
|  | ||
| private final BooktitleChecker checker = new BooktitleChecker(); | ||
|  | ||
| @Test | ||
| void booktitleAcceptsIfItDoesNotEndWithConferenceOn() { | ||
| assertEquals(Optional.empty(), checker.checkValue("2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)")); | ||
| } | ||
|  | ||
| @Test | ||
| void booktitleDoesNotAcceptsIfItEndsWithConferenceOn() { | ||
| assertNotEquals(Optional.empty(), checker.checkValue("Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on")); | ||
| } | ||
|  | ||
| } | 
        
          
          
            44 changes: 44 additions & 0 deletions
          
          44 
        
  src/test/java/org/jabref/logic/integrity/BracketCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,44 @@ | ||
| package org.jabref.logic.integrity; | ||
|  | ||
| import java.util.Optional; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|  | ||
| public class BracketCheckerTest { | ||
|  | ||
| private final BracketChecker checker = new BracketChecker(); | ||
|  | ||
| @Test | ||
| void fieldAcceptsNoBrackets() { | ||
| assertEquals(Optional.empty(), checker.checkValue("x")); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldAcceptsEvenNumberOfBrackets() { | ||
| assertEquals(Optional.empty(), checker.checkValue("{x}")); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldAcceptsExpectedBracket() { | ||
| assertEquals(Optional.empty(), checker.checkValue("{x}x{}x{{}}")); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldDoesNotAcceptOddNumberOfBrackets() { | ||
| assertNotEquals(Optional.empty(), checker.checkValue("{x}x{}}x{{}}")); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldDoesNotAcceptUnexpectedClosingBracket() { | ||
| assertNotEquals(Optional.empty(), checker.checkValue("}")); | ||
| } | ||
|  | ||
| @Test | ||
| void fieldDoesNotAcceptUnexpectedOpeningBracket() { | ||
| assertNotEquals(Optional.empty(), checker.checkValue("{")); | ||
| } | ||
|  | ||
| } | 
        
          
          
            34 changes: 34 additions & 0 deletions
          
          34 
        
  src/test/java/org/jabref/logic/integrity/DOIValidityCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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.integrity; | ||
|  | ||
| import java.util.Optional; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|  | ||
| public class DOIValidityCheckerTest { | ||
|  | ||
| private final DOIValidityChecker checker = new DOIValidityChecker(); | ||
|  | ||
| @Test | ||
| void doiAcceptsValidInput() { | ||
| assertEquals(Optional.empty(), checker.checkValue("10.1023/A:1022883727209")); | ||
| } | ||
|  | ||
| @Test | ||
| void doiAcceptsValidInputWithNotOnlyNumbers() { | ||
| assertEquals(Optional.empty(), checker.checkValue("10.17487/rfc1436")); | ||
| } | ||
|  | ||
| @Test | ||
| void doiAcceptsValidInputNoMatterTheLengthOfTheDOIName() { | ||
| assertEquals(Optional.empty(), checker.checkValue("10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0")); | ||
| } | ||
|  | ||
| @Test | ||
| void doiDoesNotAcceptInvalidInput() { | ||
| assertNotEquals(Optional.empty(), checker.checkValue("asdf")); | ||
| } | ||
|  | ||
| } | 
  
    
      This file contains hidden or 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 hidden or 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
    
  
  
    
              
        
          
          
            54 changes: 54 additions & 0 deletions
          
          54 
        
  src/test/java/org/jabref/logic/integrity/HTMLCharacterCheckerTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,54 @@ | ||
| package org.jabref.logic.integrity; | ||
|  | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|  | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.field.StandardField; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|  | ||
| public class HTMLCharacterCheckerTest { | ||
|  | ||
| private final HTMLCharacterChecker checker = new HTMLCharacterChecker(); | ||
| private final BibEntry entry = new BibEntry(); | ||
|  | ||
| @Test | ||
| void titleAcceptsNonHTMLEncodedCharacters() { | ||
| entry.setField(StandardField.TITLE, "Not a single {HTML} character"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void monthAcceptsNonHTMLEncodedCharacters() { | ||
| entry.setField(StandardField.MONTH, "#jan#"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void authorAcceptsNonHTMLEncodedCharacters() { | ||
| entry.setField(StandardField.AUTHOR, "A. Einstein and I. Newton"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void urlAcceptsNonHTMLEncodedCharacters() { | ||
| entry.setField(StandardField.URL, "http://www.thinkmind.org/index.php?view=article&articleid=cloud_computing_2013_1_20_20130"); | ||
| assertEquals(Collections.emptyList(), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void authorDoesNotAcceptHTMLEncodedCharacters() { | ||
| entry.setField(StandardField.AUTHOR, "Lenhard, Jãrg"); | ||
| assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.AUTHOR)), checker.check(entry)); | ||
| } | ||
|  | ||
| @Test | ||
| void journalDoesNotAcceptHTMLEncodedCharacters() { | ||
| entry.setField(StandardField.JOURNAL, "Ärling Ström for – ‱"); | ||
| assertEquals(List.of(new IntegrityMessage("HTML encoded character found", entry, StandardField.JOURNAL)), checker.check(entry)); | ||
| } | ||
|  | ||
| } | 
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.