99
1010import java .io .ByteArrayInputStream ;
1111import java .io .ByteArrayOutputStream ;
12- import java .io .InputStream ;
1312import java .nio .charset .StandardCharsets ;
1413import java .util .Arrays ;
1514import java .util .List ;
@@ -23,18 +22,14 @@ public void testEmptySource() throws Exception {
2322 final String emptySource =
2423 "{\" app_version\" :\" 0.11.6\" ,\" app_version_int\" : 47,\" subscriptions\" :[]}" ;
2524
26- final List < SubscriptionItem > items = ImportExportJsonHelper .readFrom (
25+ final var items = ImportExportJsonHelper .readFrom (
2726 new ByteArrayInputStream (emptySource .getBytes (StandardCharsets .UTF_8 )));
2827 assertTrue (items .isEmpty ());
2928 }
3029
3130 @ Test
3231 public void testInvalidSource () {
33- final List <String > invalidList = Arrays .asList (
34- "{}" ,
35- "" ,
36- null ,
37- "gibberish" );
32+ final var invalidList = Arrays .asList ("{}" , "" , null , "gibberish" );
3833
3934 for (final String invalidContent : invalidList ) {
4035 try {
@@ -58,38 +53,24 @@ public void testInvalidSource() {
5853 @ Test
5954 public void ultimateTest () throws Exception {
6055 // Read from file
61- final List < SubscriptionItem > itemsFromFile = readFromFile ();
56+ final var itemsFromFile = readFromFile ();
6257
6358 // Test writing to an output
6459 final String jsonOut = testWriteTo (itemsFromFile );
6560
6661 // Read again
67- final List < SubscriptionItem > itemsSecondRead = readFromWriteTo (jsonOut );
62+ final var itemsSecondRead = readFromWriteTo (jsonOut );
6863
6964 // Check if both lists have the exact same items
70- if (itemsFromFile .size () != itemsSecondRead . size ( )) {
65+ if (! itemsFromFile .equals ( itemsSecondRead )) {
7166 fail ("The list of items were different from each other" );
7267 }
73-
74- for (int i = 0 ; i < itemsFromFile .size (); i ++) {
75- final SubscriptionItem item1 = itemsFromFile .get (i );
76- final SubscriptionItem item2 = itemsSecondRead .get (i );
77-
78- final boolean equals = item1 .getServiceId () == item2 .getServiceId ()
79- && item1 .getUrl ().equals (item2 .getUrl ())
80- && item1 .getName ().equals (item2 .getName ());
81-
82- if (!equals ) {
83- fail ("The list of items were different from each other" );
84- }
85- }
8668 }
8769
8870 private List <SubscriptionItem > readFromFile () throws Exception {
89- final InputStream inputStream = getClass ().getClassLoader ().getResourceAsStream (
90- "import_export_test.json" );
91- final List <SubscriptionItem > itemsFromFile = ImportExportJsonHelper .readFrom (
92- inputStream );
71+ final var inputStream = getClass ().getClassLoader ()
72+ .getResourceAsStream ("import_export_test.json" );
73+ final var itemsFromFile = ImportExportJsonHelper .readFrom (inputStream );
9374
9475 if (itemsFromFile .isEmpty ()) {
9576 fail ("ImportExportJsonHelper.readFrom(input) returned a null or empty list" );
@@ -99,7 +80,7 @@ private List<SubscriptionItem> readFromFile() throws Exception {
9980 }
10081
10182 private String testWriteTo (final List <SubscriptionItem > itemsFromFile ) {
102- final ByteArrayOutputStream out = new ByteArrayOutputStream ();
83+ final var out = new ByteArrayOutputStream ();
10384 ImportExportJsonHelper .writeTo (itemsFromFile , out );
10485 final String jsonOut = out .toString (StandardCharsets .UTF_8 );
10586
@@ -111,10 +92,8 @@ private String testWriteTo(final List<SubscriptionItem> itemsFromFile) {
11192 }
11293
11394 private List <SubscriptionItem > readFromWriteTo (final String jsonOut ) throws Exception {
114- final ByteArrayInputStream inputStream = new ByteArrayInputStream (
115- jsonOut .getBytes (StandardCharsets .UTF_8 ));
116- final List <SubscriptionItem > secondReadItems = ImportExportJsonHelper .readFrom (
117- inputStream );
95+ final var inputStream = new ByteArrayInputStream (jsonOut .getBytes (StandardCharsets .UTF_8 ));
96+ final var secondReadItems = ImportExportJsonHelper .readFrom (inputStream );
11897
11998 if (secondReadItems .isEmpty ()) {
12099 fail ("second call to readFrom returned an empty list" );
0 commit comments