Created
May 13, 2017 04:35
-
-
Save AlexMocioi/d7842345f61909c1c2a8401dc19e3a67 to your computer and use it in GitHub Desktop.
Junit and Mockito example
This file contains 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
@Test public void fromCen2FattPAConversionShouldCreateCsvIfConversionResultHasErrors() throws IOException, SyntaxErrorInInvoiceFormatException { | |
// given | |
given( fromCen.extension() ).willReturn(".xml"); | |
List<Exception> myErrors = Arrays.asList(new IllegalArgumentException("test exception")); | |
//Cen2FattPAConverter fromCen = Mockito.mock(Cen2FattPAConverter.class); | |
when(fromCen.convert(any())).thenReturn(new ConversionResult("bytes".getBytes(), myErrors)); | |
// when converting a mock invoice, errors should occur | |
Path outputFolder = FileSystems.getDefault().getPath(outputFolderFile.getAbsolutePath()); | |
InputStream invoiceSourceFormat = null; | |
ConversionCommand sut = new ConversionCommand(ruleRepository, toCen, fromCen, inputInvoice, outputFolder, invoiceSourceFormat); | |
PrintStream err = new PrintStream( new ByteArrayOutputStream() ); | |
PrintStream out = new PrintStream( new ByteArrayOutputStream() ); | |
// when | |
sut.execute(System.out, System.err); | |
// then a fromcen-errors.csv should be created for the errors along with the other files | |
List<File> files = asList( outputFolderFile.listFiles() ); | |
assertThat( files + " found", findFirstFileOrNull(outputFolderFile, f -> f.getName().equals("invoice-source.txt")), notNullValue() ); | |
assertThat( files + " found", findFirstFileOrNull(outputFolderFile, f -> f.getName().equals("invoice-cen.csv")), notNullValue() ); | |
assertThat( files + " found", findFirstFileOrNull(outputFolderFile, f -> f.getName().equals("invoice-target.xml")), notNullValue() ); | |
assertThat( files + " found", findFirstFileOrNull(outputFolderFile, f -> f.getName().equals("rule-report.csv")), notNullValue() ); | |
assertThat( files + " found", findFirstFileOrNull(outputFolderFile, f -> f.getName().equals("invoice-transformation.log")), notNullValue() ); | |
assertThat( files + " found", findFirstFileOrNull(outputFolderFile, f -> f.getName().equals("fromcen-errors.csv")), notNullValue() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment