Commits

kulti committed ccf3469

Extracted IPdfParser interface

  • Participants
  • Parent commits 3af7311

Comments (0)

Files changed (5)

pdf_book_reader/src/ru/homeless/kulti/pdf_book_reader/BookState.java

 public class BookState
 {
     private IBookView bookView;
-    private PdfParser pdfParser;
+    private IPdfParser pdfParser;
     private int currentPageNumber;
 
-    public BookState(IBookView bookView)
+    public BookState(IBookView bookView, IPdfParser pdfParser)
     {
         this.bookView = bookView;
-        pdfParser = new PdfParser();
+        this.pdfParser = pdfParser;
     }
     
     public void openFile(String fileName)

pdf_book_reader/src/ru/homeless/kulti/pdf_book_reader/IPdfParser.java

+package ru.homeless.kulti.pdf_book_reader;
+
+import java.io.IOException;
+
+public interface IPdfParser
+{
+    public void open(String fileName) throws IOException;
+    public int getNumberOfPages();
+    public String getPageContent(int pageNum) throws IOException;
+}

pdf_book_reader/src/ru/homeless/kulti/pdf_book_reader/PdfBookReaderActivity.java

         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         
-        bookState = new BookState(this);
+        bookState = new BookState(this, new PdfParser());
         pageContent = (TextView)findViewById(R.id.pageContent);
 
         bookState.openFile("/sdcard/test.pdf");

pdf_book_reader/src/ru/homeless/kulti/pdf_book_reader/PdfParser.java

 import com.itextpdf.text.pdf.PdfReader;
 import com.itextpdf.text.pdf.parser.*;
 
-public class PdfParser
+public class PdfParser implements IPdfParser
 {
     private PdfReader document = null;
     
+    @Override
     public void open(String fileName) throws IOException
     {
         try
         }
     }
 
+    @Override
     public int getNumberOfPages()
     {
         return document.getNumberOfPages();
     }
 
+    @Override
     public String getPageContent(int pageNum) throws IOException
     {
         PdfReaderContentParser parser = new PdfReaderContentParser(document);

pdf_book_reader_test/src/ru/homeless/kulti/pdf_book_reader/test/BookStateTest.java

 package ru.homeless.kulti.pdf_book_reader.test;
 
+import java.io.IOException;
+
 import ru.homeless.kulti.pdf_book_reader.BookState;
 import ru.homeless.kulti.pdf_book_reader.IBookView;
+import ru.homeless.kulti.pdf_book_reader.IPdfParser;
 import android.test.AndroidTestCase;
 
 public class BookStateTest extends AndroidTestCase
         }
     };
     
+    private class IPdfParserStub implements IPdfParser
+    {
+        @Override
+        public int getNumberOfPages()
+        {
+            return 0;
+        }
+
+        @Override
+        public String getPageContent(int pageNum) throws IOException
+        {
+            return "";
+        }
+
+        @Override
+        public void open(String fileName) throws IOException
+        {
+        }
+    };
+    
     private IBookViewStub bookView;
     private BookState bookState;
 
     {
         super.setUp();
         bookView = new IBookViewStub();
-        bookState = new BookState(bookView);
+        bookState = new BookState(bookView, new IPdfParserStub());
     }
     
     public void testPageNavigation()
     {
-        bookState.openFile("/sdcard/test.pdf");
         bookState.goToPage(1);
         assertEquals(1, bookState.currentPageNumber());
         bookState.goToNextPage();