mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-24 21:07:26 +08:00
LuceneQueryTest: Added a few tests to verify QueryException is thrown if Lucene throws an IOException.
This commit is contained in:
parent
300d9c0e65
commit
dfdcacf7ca
@ -30,6 +30,7 @@ import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.QueryException;
|
||||
@ -42,9 +43,9 @@ import com.mysema.query.types.path.PathMetadataFactory;
|
||||
|
||||
/**
|
||||
* Tests for LuceneQuery
|
||||
*
|
||||
*
|
||||
* @author vema
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class LuceneQueryTest {
|
||||
|
||||
@ -131,6 +132,17 @@ public class LuceneQueryTest {
|
||||
assertEquals(1, query.count());
|
||||
}
|
||||
|
||||
@Test(expected = QueryException.class)
|
||||
public void count_Index_Problem() throws IOException {
|
||||
searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock();
|
||||
query = new LuceneQuery(new LuceneSerializer(true, true), searcher);
|
||||
expect(searcher.maxDoc()).andThrow(new IOException());
|
||||
replay(searcher);
|
||||
query.where(title.eq("Jurassic Park"));
|
||||
query.count();
|
||||
verify(searcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countDistinct() {
|
||||
query.where(year.between(1900, 3000));
|
||||
@ -273,6 +285,31 @@ public class LuceneQueryTest {
|
||||
assertEquals("Introduction to Algorithms", documents.get(1).get("title"));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test(expected = QueryException.class)
|
||||
public void list_Index_Problem_In_Max_Doc() throws IOException {
|
||||
searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock();
|
||||
query = new LuceneQuery(new LuceneSerializer(true, true), searcher);
|
||||
expect(searcher.maxDoc()).andThrow(new IOException());
|
||||
replay(searcher);
|
||||
query.where(title.eq("Jurassic Park"));
|
||||
query.list();
|
||||
verify(searcher);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test(expected = QueryException.class)
|
||||
public void list_Sorted_Index_Problem_In_Max_Doc() throws IOException {
|
||||
searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock();
|
||||
query = new LuceneQuery(new LuceneSerializer(true, true), searcher);
|
||||
expect(searcher.maxDoc()).andThrow(new IOException());
|
||||
replay(searcher);
|
||||
query.where(title.eq("Jurassic Park"));
|
||||
query.orderBy(title.asc());
|
||||
query.list();
|
||||
verify(searcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uniqueResult() {
|
||||
query.where(title.startsWith("Nummi"));
|
||||
@ -302,6 +339,17 @@ public class LuceneQueryTest {
|
||||
verify(searcher);
|
||||
}
|
||||
|
||||
@Test(expected = QueryException.class)
|
||||
public void uniqueResult_Sorted_Index_Problem_In_Max_Doc() throws IOException {
|
||||
searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock();
|
||||
query = new LuceneQuery(new LuceneSerializer(true, true), searcher);
|
||||
expect(searcher.maxDoc()).andThrow(new IOException());
|
||||
replay(searcher);
|
||||
query.where(title.eq("Jurassic Park"));
|
||||
query.uniqueResult();
|
||||
verify(searcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void count_Returns_0_Because_No_Documents_In_Index() throws IOException {
|
||||
searcher = createMockBuilder(IndexSearcher.class).addMockedMethod("maxDoc").createMock();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user