4141import org .junit .runner .RunWith ;
4242import org .robolectric .annotation .Config ;
4343
44+ import java .io .BufferedReader ;
4445import java .io .File ;
46+ import java .io .FileNotFoundException ;
47+ import java .io .FileReader ;
48+ import java .io .IOException ;
49+ import java .io .InputStreamReader ;
4550import java .util .List ;
4651
4752import static org .assertj .core .api .Assertions .assertThat ;
@@ -144,4 +149,46 @@ public void multiCurrencyTransactions_shouldResultInMultipleQifFiles(){
144149 assertThat (file .length ()).isGreaterThan (0L );
145150 }
146151
152+ //@Test
153+ public void description_and_memo_field_test () {
154+ // arrange
155+
156+ String expectedDescription = "my description" ;
157+ String expectedMemo = "my memo" ;
158+
159+ AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter (mDb );
160+ Account account = new Account ("Basic Account" );
161+ Transaction transaction = new Transaction ("One transaction" );
162+ transaction .setDescription (expectedDescription );
163+ transaction .setNote (expectedMemo );
164+ account .addTransaction (transaction );
165+ accountsDbAdapter .addRecord (account );
166+
167+ ExportParams exportParameters = new ExportParams (ExportFormat .QIF );
168+ exportParameters .setExportStartTime (TimestampHelper .getTimestampFromEpochZero ());
169+ exportParameters .setExportTarget (ExportParams .ExportTarget .SD_CARD );
170+ exportParameters .setDeleteTransactionsAfterExport (false );
171+
172+ // act
173+
174+ QifExporter qifExporter = new QifExporter (exportParameters , mDb );
175+ List <String > exportedFiles = qifExporter .generateExport ();
176+
177+ // assert
178+
179+ assertThat (exportedFiles ).hasSize (1 );
180+ File file = new File (exportedFiles .get (0 ));
181+ assertThat (file ).exists ().hasExtension ("qif" );
182+ StringBuilder fileContentsBuilder = new StringBuilder ();
183+ try {
184+ BufferedReader reader = new BufferedReader (new FileReader (file ));
185+ fileContentsBuilder .append (reader .readLine ());
186+ } catch (IOException e ) {
187+ e .printStackTrace ();
188+ }
189+ // todo: check the description & memo fields.
190+ String fileContent = fileContentsBuilder .toString ();
191+ assertThat (fileContent .contains (expectedDescription ));
192+ assertThat (fileContent .contains (expectedMemo ));
193+ }
147194}
0 commit comments