close resource leaks and use tryWithResource

This commit is contained in:
dvo
2017-06-02 15:24:03 +02:00
committed by Dominik Vogt
parent a771b1e769
commit faf4d1def3
8 changed files with 258 additions and 236 deletions

View File

@@ -401,27 +401,18 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
public void testZExport()
{
final InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505newEdge.pdf";
// the writing part
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505newEdge.pdf";
try
{
// automatically add Zugferd to all outgoing invoices
ZUGFeRDExporter ze = new ZUGFeRDExporter();
ze.PDFmakeA3compliant(SOURCE_PDF, "My Application", System.getProperty("user.name"), true);
ze.PDFattachZugferdFile(this);
ze.export(TARGET_PDF);
// the writing part
// automatically add Zugferd to all outgoing invoices
try (ZUGFeRDExporter ze = new ZUGFeRDExporter()) {
try(final InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf")){
ze.PDFmakeA3compliant(SOURCE_PDF, "My Application", System.getProperty("user.name"), true);
}
ze.PDFattachZugferdFile(this);
ze.export(TARGET_PDF);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (TransformerException e)
{
e.printStackTrace();
}
catch (Exception e)
catch (Exception e)
{
e.printStackTrace();
}

View File

@@ -10,14 +10,13 @@ import java.util.GregorianCalendar;
import javax.xml.transform.TransformerException;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExportableTransaction
{
@@ -326,7 +325,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
public void setVATPercent(BigDecimal VATPercent)
{
VATPercent = VATPercent;
this.VATPercent = VATPercent;
}
}
@@ -363,8 +362,10 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
public void testAImport() throws IOException
{
ZUGFeRDImporter zi = new ZUGFeRDImporter();
InputStream inputStream = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505.pdf");
zi.extractLowLevel(inputStream);
try (InputStream inputStream = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505.pdf")) {
zi.extractLowLevel(inputStream);
}
// Reading ZUGFeRD
String amount = null;
@@ -400,27 +401,19 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
*/
public void testZExport()
{
final InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505new.pdf";
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505new.pdf";
// the writing part
try
{
// automatically add Zugferd to all outgoing invoices
ZUGFeRDExporter ze = new ZUGFeRDExporter();
ze.PDFmakeA3compliant(SOURCE_PDF, "My Application", System.getProperty("user.name"), true);
ze.PDFattachZugferdFile(this);
ze.export(TARGET_PDF);
// automatically add Zugferd to all outgoing invoices
try (ZUGFeRDExporter ze = new ZUGFeRDExporter()) {
try (final InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf")) {
ze.PDFmakeA3compliant(SOURCE_PDF, "My Application", System.getProperty("user.name"), true);
}
ze.PDFattachZugferdFile(this);
ze.export(TARGET_PDF);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (TransformerException e)
{
e.printStackTrace();
}
catch (Exception e)
catch (Exception e)
{
e.printStackTrace();
}