Fix tests
authorNiki Roo <niki@nikiroo.be>
Mon, 26 Mar 2018 20:33:16 +0000 (22:33 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 26 Mar 2018 20:33:16 +0000 (22:33 +0200)
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/test/LibraryTest.java

index 97863e7b29e7b26f7489895374405c414b5f6847..275926cd93164788258381b094fcef594cde7bbf 100644 (file)
@@ -20,7 +20,6 @@ import be.nikiroo.fanfix.output.InfoCover;
 import be.nikiroo.fanfix.supported.InfoReader;
 import be.nikiroo.utils.IOUtils;
 import be.nikiroo.utils.Image;
-import be.nikiroo.utils.MarkableFileInputStream;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -468,10 +467,8 @@ public class LocalLibrary extends BasicLibrary {
                                                                // not normal!!
                                                                throw new IOException(
                                                                                "Cannot understand the LUID of "
-                                                                                               + infoFile
-                                                                                               + ": "
-                                                                                               + (meta == null ? "[meta is NULL]"
-                                                                                                               : meta.getLuid()), e);
+                                                                                               + infoFile + ": "
+                                                                                               + meta.getLuid(), e);
                                                        }
                                                } catch (IOException e) {
                                                        // We should not have not-supported files in the
index fc61e7ddf86bb5ec8688b390b26ae706295c31c4..cf85b71e9f9b96d9e5c732122eaff202d013530d 100644 (file)
@@ -2,6 +2,8 @@ package be.nikiroo.fanfix.test;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import be.nikiroo.fanfix.data.Chapter;
@@ -25,29 +27,37 @@ class LibraryTest extends TestLauncher {
                final String luid1 = "001"; // A
                final String luid2 = "002"; // B
                final String luid3 = "003"; // B then A, then B
+               final String name1 = "My story 1";
+               final String name2 = "My story 2";
+               final String name3 = "My story 3";
+               final String name3ex = "My story 3 [edited]";
                final String source1 = "Source A";
                final String source2 = "Source B";
                final String author1 = "Unknown author";
                final String author2 = "Another other otter author";
 
+               final String errMess = "The resulting stories in the list are not what we expected";
+
                addSeries(new TestLauncher("Local", args) {
                        {
                                addTest(new TestCase("getList") {
                                        @Override
                                        public void test() throws Exception {
                                                List<MetaData> metas = lib.getList();
-                                               assertEquals(0, metas.size());
+                                               assertEquals(errMess, Arrays.asList(),
+                                                               titlesAsList(metas));
                                        }
                                });
 
                                addTest(new TestCase("save") {
                                        @Override
                                        public void test() throws Exception {
-                                               lib.save(story(luid1, "My story 1", source1, author1),
-                                                               luid1, null);
+                                               lib.save(story(luid1, name1, source1, author1), luid1,
+                                                               null);
 
                                                List<MetaData> metas = lib.getList();
-                                               assertEquals(1, metas.size());
+                                               assertEquals(errMess, Arrays.asList(name1),
+                                                               titlesAsList(metas));
                                        }
                                });
 
@@ -56,17 +66,20 @@ class LibraryTest extends TestLauncher {
                                        public void test() throws Exception {
                                                List<MetaData> metas = null;
 
-                                               lib.save(story(luid2, "My story 2", source2, author1),
-                                                               luid2, null);
+                                               lib.save(story(luid2, name2, source2, author1), luid2,
+                                                               null);
 
                                                metas = lib.getList();
-                                               assertEquals(2, metas.size());
+                                               assertEquals(errMess, Arrays.asList(name1, name2),
+                                                               titlesAsList(metas));
 
-                                               lib.save(story(luid3, "My story 3", source2, author1),
-                                                               luid3, null);
+                                               lib.save(story(luid3, name3, source2, author1), luid3,
+                                                               null);
 
                                                metas = lib.getList();
-                                               assertEquals(3, metas.size());
+                                               assertEquals(errMess,
+                                                               Arrays.asList(name1, name2, name3),
+                                                               titlesAsList(metas));
                                        }
                                });
 
@@ -74,12 +87,13 @@ class LibraryTest extends TestLauncher {
                                        @Override
                                        public void test() throws Exception {
                                                // same luid as a previous one
-                                               lib.save(
-                                                               story(luid3, "My story 3 [edited]", source2,
-                                                                               author2), luid3, null);
+                                               lib.save(story(luid3, name3ex, source2, author2),
+                                                               luid3, null);
 
                                                List<MetaData> metas = lib.getList();
-                                               assertEquals(3, metas.size());
+                                               assertEquals(errMess,
+                                                               Arrays.asList(name1, name2, name3ex),
+                                                               titlesAsList(metas));
                                        }
                                });
 
@@ -178,6 +192,25 @@ class LibraryTest extends TestLauncher {
                IOUtils.deltree(tmp);
        }
 
+       /**
+        * Return the (sorted) list of titles present in this list of
+        * {@link MetaData}s.
+        * 
+        * @param metas
+        *            the meta
+        * 
+        * @return the sorted list
+        */
+       private List<String> titlesAsList(List<MetaData> metas) {
+               List<String> list = new ArrayList<String>();
+               for (MetaData meta : metas) {
+                       list.add(meta.getTitle());
+               }
+
+               Collections.sort(list);
+               return list;
+       }
+
        private Story story(String luid, String title, String source, String author) {
                Story story = new Story();