package kz.kaznu.lucene;

import kz.kaznu.lucene.constants.Constants;
import kz.kaznu.lucene.index.MessageIndexer;
import kz.kaznu.lucene.utils.Helper;
import org.apache.lucene.document.Document;
import org.junit.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Random;

import static org.junit.Assert.*;

/**
 * User: Sanzhar Aubakirov
 * Date: 2/18/16
 */
public class BasicSearchExamplesTest {
    private final Random rnd = new Random(); // to generate safe name for index folder. After tests we removing folders
    private final MessageIndexer indexer = new MessageIndexer(Constants.TMP_DIR + "/tutorial_test" + rnd.nextInt());
    final ClassLoader classLoader = getClass().getClassLoader();
    final File file = new File(classLoader.getResource("tutorial.json").getFile());
    final List<Document> documents;

    public BasicSearchExamplesTest() throws FileNotFoundException {
        documents = Helper.readDocumentsFromFile(file);
    }

    @Test
    public void testSearch() throws Exception {
        indexer.index(true, documents); // create index

        final BasicSearchExamples searchWith = new BasicSearchExamples(indexer.readIndex());
        searchWith.searchInBody("корреспондент");
    }

    @Test
    public void testSearchWithMistake() throws Exception {
        indexer.index(true, documents); // create index

        final BasicSearchExamples searchWith = new BasicSearchExamples(indexer.readIndex());
        searchWith.searchInBody("кореспондент");
    }

    @Test
    public void fuzzySearchWithMistake() throws Exception {
        indexer.index(true, documents); // create index

        final BasicSearchExamples searchWith = new BasicSearchExamples(indexer.readIndex());
        searchWith.fuzzySearch("кореспондент");
    }

    @Test
    public void fuzzySearch() throws Exception {
        indexer.index(true, documents); // create index

        final BasicSearchExamples searchWith = new BasicSearchExamples(indexer.readIndex());
        searchWith.fuzzySearch("дорога");
    }
}
@@ -167,32 +167,96 @@
 che.
-lucene.document.Document
+commons.io.FileUtils;%0Aimport org.apache.lucene.document.Document;%0Aimport org.junit.After
 ;%0Aim
@@ -2136,10 +2136,155 @@
 );%0A    %7D
+%0A%0A    @After%0A    public void removeIndexes() %7B%0A        FileUtils.deleteQuietly(new File(indexer.getPathToIndexFolder())); // remove indexes%0A    %7D
 %0A%7D

Add index folder cleaning after test