Ignore:
Timestamp:
2016-07-02T02:48:15+02:00 (8 years ago)
Author:
donvip
Message:

add non-regression unit tests

Location:
applications/editors/josm/plugins/pdfimport
Files:
11 added
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pdfimport/.classpath

    r32520 r32524  
    33        <classpathentry kind="src" path="src"/>
    44        <classpathentry kind="src" path="resources"/>
     5        <classpathentry kind="src" path="test/unit"/>
    56        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
    67        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
     
    89        <classpathentry kind="lib" path="lib/jempbox-1.8.12.jar"/>
    910        <classpathentry kind="lib" path="lib/pdfbox-1.8.12.jar"/>
     11        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    1012        <classpathentry kind="output" path="bin"/>
    1113</classpath>
  • applications/editors/josm/plugins/pdfimport/src/pdfimport/pdfbox/PdfBoxParser.java

    r30701 r32524  
    55import java.awt.geom.Rectangle2D;
    66import java.io.File;
     7import java.io.IOException;
    78import java.util.List;
    89
     
    2223        }
    2324
    24         public void parse(File file, int maxPaths, ProgressMonitor monitor) throws Exception
    25         {
    26                 monitor.beginTask(tr("Parsing PDF", 1));
     25    public void parse(File file, int maxPaths, ProgressMonitor monitor) throws IOException {
     26        monitor.beginTask(tr("Parsing PDF", 1));
    2727
    28                 PDDocument document = PDDocument.load( file);
     28        try (PDDocument document = PDDocument.load(file)) {
    2929
    30                 if( document.isEncrypted() ){
    31                         throw new Exception(tr("Encrypted documents not supported."));
    32                 }
     30            if (document.isEncrypted()) {
     31                throw new IllegalArgumentException(tr("Encrypted documents not supported."));
     32            }
    3333
    34                 List<?> allPages = document.getDocumentCatalog().getAllPages();
     34            List<?> allPages = document.getDocumentCatalog().getAllPages();
    3535
    36                 if (allPages.size() != 1) {
    37                         throw new Exception(tr("The PDF file must have exactly one page."));
    38                 }
     36            if (allPages.size() != 1) {
     37                throw new IllegalArgumentException(tr("The PDF file must have exactly one page."));
     38            }
     39           
     40            PDPage page = (PDPage) allPages.get(0);
     41            PDRectangle pageSize = page.findMediaBox();
     42            Integer rotationVal = page.getRotation();
     43            int rotation = 0;
     44            if (rotationVal != null) {
     45                rotation = rotationVal.intValue();
     46            }
     47   
     48            new PageDrawer().drawPage(new GraphicsProcessor(target, rotation, maxPaths, monitor), page);
     49            this.target.bounds = new Rectangle2D.Double(
     50                    pageSize.getLowerLeftX(),
     51                    pageSize.getLowerLeftY(),
     52                    pageSize.getWidth(),
     53                    pageSize.getHeight());
     54        }
    3955
    40                 PDPage page = (PDPage)allPages.get(0);
    41                 PDRectangle pageSize = page.findMediaBox();
    42                 Integer rotationVal = page.getRotation();
    43                 int rotation = 0;
    44                 if (rotationVal != null){
    45                         rotation = rotationVal.intValue();
    46                 }
    47 
    48                 GraphicsProcessor p = new GraphicsProcessor(target, rotation, maxPaths, monitor);
    49                 PageDrawer drawer = new PageDrawer();
    50                 drawer.drawPage(p, page);
    51                 this.target.bounds = new Rectangle2D.Double(pageSize.getLowerLeftX(), pageSize.getLowerLeftY(), pageSize.getWidth(), pageSize.getHeight());
    52 
    53                 monitor.finishTask();
    54         }
     56        monitor.finishTask();
     57    }
    5558}
Note: See TracChangeset for help on using the changeset viewer.