package com.bkromhout.minerva.test;

import com.bkromhout.minerva.data.SuperBook;
import com.bkromhout.minerva.data.UniqueIdFactory;
import com.bkromhout.minerva.realm.RBook;
import nl.siegmann.epublib.domain.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Utility class which creates SuperBooks for testing.
 */
public class TestBookFactory {
    /**
     * Number currently being used to help generate a {@link TestSuperBook}.
     */
    private long genNum;

    public TestBookFactory() {
        this.genNum = 0L;
    }

    /**
     * Create a new {@link SuperBook} wrapped in a {@link TestSuperBook}.
     * @return A {@link TestSuperBook} guaranteed to be different from any others generated by this instance.
     */
    public final TestSuperBook generate() {
        genNum += 1L;
        String title = "Test Book " + genNum;
        Book book = new Book();
        Metadata metadata = book.getMetadata();
        metadata.addTitle(new DcmesElement(title));
        metadata.addAuthor(new Author("Author " + genNum));
        metadata.addDescription(new DcmesElement("Description " + genNum));
        metadata.setSubjects(Collections.singletonList(new DcmesElement("Subject " + genNum)));
        metadata.addType(new DcmesElement("Type " + genNum));
        metadata.setFormat("application/epub+zip");
        metadata.addPublisher(new DcmesElement("Publisher " + genNum));
        metadata.addDate(new Date("Create Date " + genNum, Date.Event.CREATION));
        metadata.addDate(new Date("Publish Date " + genNum, Date.Event.PUBLICATION));
        metadata.addDate(new Date("Modified Date " + genNum, Date.Event.MODIFICATION));
        return new TestSuperBook(book, "path/to/book_" + genNum, title.getBytes(), genNum);
    }

    /**
     * Create {@code num} new {@link SuperBook}s wrapped in {@link TestSuperBook}s.
     * @param num Number of {@link TestSuperBook}s to generate.
     * @return A list of {@link TestSuperBook}s guaranteed to be different from each other and any others generated by
     * this instance.
     */
    public final List<TestSuperBook> generateMultiple(int num) {
        ArrayList<TestSuperBook> tsbList = new ArrayList<>(num);
        for (int i = 0; i < num; i++) tsbList.add(generate());
        return tsbList;
    }

    /**
     * Converts a list of {@link TestSuperBook}s to a list of {@link RBook}s.
     * @param tsbList List of {@link TestSuperBook}s.
     * @return List of {@link RBook}s.
     * @throws IllegalStateException if temporary unique IDs haven't been set up yet
     * ({@link UniqueIdFactory#areTempIdsSetUp()} returns {@code false}.)
     */
    public static List<RBook> toRBooks(List<TestSuperBook> tsbList) {
        if (!UniqueIdFactory.getInstance().areTempIdsSetUp())
            throw new IllegalStateException("Must set up temporary unique IDs prior to creating RBooks for testing.");

        ArrayList<RBook> books = new ArrayList<>(tsbList.size());
        for (TestSuperBook tsb : tsbList) books.add(new RBook(tsb));
        return books;
    }
}

@@ -382,16 +382,81 @@
 ctory %7B%0A
+    public static final String BASE_TEST_PATH = %22path/to/book_%22;%0A
     /**%0A
@@ -1787,31 +1787,30 @@
 k(book, 
-%22path/to/book_%22
+BASE_TEST_PATH
  + genNu

Use a constant for path base