package net.sf.jabref.importer;


import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import net.sf.jabref.importer.fileformat.ImportFormat;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ImportFileFilterTest {

    @Test
    public void nameWithSingleExtensions() {
        ImportFormat importFormatSingleExtension = new ImportFormat() {
            @Override
            protected boolean isRecognizedFormat(BufferedReader input) throws IOException {
                return false;
            }

            @Override
            protected ParserResult importDatabase(BufferedReader input) throws IOException {
                return null;
            }

            @Override
            public String getFormatName() {
                return "Single Extension";
            }

            @Override
            public List<String> getExtensions() {
                return Collections.singletonList(".abc");
            }

            @Override
            public String getDescription() {
                return null;
            }
        };

        ImportFileFilter importFileFilter = new ImportFileFilter(importFormatSingleExtension);
        assertEquals("Single Extension (*.abc)", importFileFilter.getDescription());
    }

    @Test
    public void nameWithMultipleExtensions() {
        ImportFormat importFormatMultipleExtensions = new ImportFormat() {
            @Override
            protected boolean isRecognizedFormat(BufferedReader input) throws IOException {
                return false;
            }

            @Override
            protected ParserResult importDatabase(BufferedReader input) throws IOException {
                return null;
            }

            @Override
            public String getFormatName() {
                return "Multiple Extensions";
            }

            @Override
            public List<String> getExtensions() {
                return Arrays.asList(".abc", ".xyz");
            }

            @Override
            public String getDescription() {
                return null;
            }
        };

        ImportFileFilter importFileFilter = new ImportFileFilter(importFormatMultipleExtensions);
        assertEquals("Multiple Extensions (*.abc, *.xyz)", importFileFilter.getDescription());
    }

}

@@ -31,67 +31,8 @@
 ;%0A%0A%0A
-import java.io.BufferedReader;%0Aimport java.io.IOException;%0A
 impo
@@ -85,31 +85,8 @@
 ons;
-%0Aimport java.util.List;
 %0A%0Aim
@@ -208,16 +208,97 @@
 Equals;%0A
+import static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0A
 %0Apublic 
@@ -433,20 +433,21 @@
 nsion = 
-new 
+mock(
 ImportFo
@@ -454,420 +454,86 @@
 rmat
-() %7B%0A            @Override%0A            protected boolean isRecognizedFormat(BufferedReader input) throws IOException %7B%0A                return false;%0A            %7D%0A%0A            @Override%0A            protected ParserResult importDatabase(BufferedReader input) throws IOException %7B%0A                return null;%0A            %7D%0A%0A            @Override%0A            public String getFormatName() %7B%0A                r
+.class);%0A        when(importFormatSingleExtension.getFormatName()).thenR
 eturn
- 
+(
 %22Sin
@@ -546,16 +546,17 @@
 tension%22
+)
 ;%0A      
@@ -561,110 +561,69 @@
     
- 
-   %7D%0A%0A            @Override%0A            public List%3CString%3E getExtensions() %7B%0A                r
+when(importFormatSingleExtension.getExtensions()).thenR
 eturn
- 
+(
 Coll
@@ -655,144 +655,9 @@
 bc%22)
-;%0A            %7D%0A%0A            @Override%0A            public String getDescription() %7B%0A                return null;%0A            %7D%0A        %7D
+)
 ;%0A%0A 
@@ -953,20 +953,21 @@
 sions = 
-new 
+mock(
 ImportFo
@@ -974,429 +974,146 @@
 rmat
-() %7B%0A            @Override%0A            protected boolean isRecognizedFormat(BufferedReader input) throws IOException %7B%0A                return false;%0A            %7D%0A%0A            @Override%0A            protected ParserResult importDatabase(BufferedReader input) throws IOException %7B%0A                return null;%0A            %7D%0A%0A            @Override%0A            public String getFormatName() %7B%0A                return %22
+.class);%0A        when(importFormatMultipleExtensions.getFormatName()).thenReturn(%22Multiple Extensions%22);%0A        when(importFormat
 Multiple
  Ext
@@ -1100,33 +1100,32 @@
 rtFormatMultiple
- 
 Extensions%22;%0A   
@@ -1122,121 +1122,37 @@
 ions
-%22;%0A            %7D%0A%0A            @Override%0A            public List%3CString%3E getExtensions() %7B%0A                r
+.getExtensions()).thenR
 eturn
- 
+(
 Arra
@@ -1180,144 +1180,9 @@
 yz%22)
-;%0A            %7D%0A%0A            @Override%0A            public String getDescription() %7B%0A                return null;%0A            %7D%0A        %7D
+)
 ;%0A%0A 

test ImportFileFilter with Mockito (#1522)