package de.tudarmstadt.ukp.wikipedia.api; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import org.junit.Assume; import org.junit.Test; import org.mockito.Mockito; import de.tudarmstadt.ukp.wikipedia.api.exception.WikiApiException; public class TestPageQueryIterable { @Test public void PageQueryIterableTest() { Wikipedia wiki = Mockito.mock(Wikipedia.class); PageQuery pageQuery = Mockito.mock(PageQuery.class); Session session = Mockito.mock(Session.class); Query query = Mockito.mock(Query.class); Transaction trans = Mockito.mock(Transaction.class); Page page = Mockito.mock(Page.class); List pageIds = new ArrayList(); pageIds.add(1); Mockito.when(wiki.__getHibernateSession()).thenReturn(session); Mockito.when(session.createQuery(Mockito.anyString())).thenReturn(query); Mockito.when(session.getTransaction()).thenReturn(trans); Mockito.when(query.list()).thenReturn(pageIds); Mockito.when(pageQuery.getTitlePattern()).thenReturn(""); try { Mockito.when(wiki.getPage(Mockito.anyInt())).thenReturn(page); Mockito.when(page.getPlainText()).thenReturn("the rabbit is in the hole"); } catch (WikiApiException e) { Assume.assumeNoException(e); } boolean disambig = false; boolean articles = false; int maxCategories = Integer.MAX_VALUE; int maxIndegree = Integer.MAX_VALUE; int maxOutdegree = Integer.MAX_VALUE; int maxRedirects = Integer.MAX_VALUE; int maxTokens = Integer.MAX_VALUE; int minCat = 0; int minIndegree = 0; int minOutdegree = 0; int minRedirects = 0; int minTokens = 0; Mockito.when(pageQuery.onlyDisambiguationPages()).thenReturn(disambig); Mockito.when(pageQuery.onlyArticlePages()).thenReturn(articles); Mockito.when(pageQuery.getTitlePattern()).thenReturn("blah"); Mockito.when(pageQuery.getMaxCategories()).thenReturn(maxCategories); Mockito.when(pageQuery.getMaxIndegree()).thenReturn(maxIndegree); Mockito.when(pageQuery.getMaxOutdegree()).thenReturn(maxOutdegree); Mockito.when(pageQuery.getMaxRedirects()).thenReturn(maxRedirects); Mockito.when(pageQuery.getMaxTokens()).thenReturn(maxTokens); Mockito.when(pageQuery.getMinCategories()).thenReturn(minCat); Mockito.when(pageQuery.getMinIndegree()).thenReturn(minIndegree); Mockito.when(pageQuery.getMinOutdegree()).thenReturn(minOutdegree); Mockito.when(pageQuery.getMinRedirects()).thenReturn(minRedirects); Mockito.when(pageQuery.getMinTokens()).thenReturn(minTokens); try { PageQueryIterable it = new PageQueryIterable(wiki, pageQuery); Iterator pit = it.iterator(); assertTrue(pit.hasNext()); } catch (WikiApiException e) { Assume.assumeNoException(e); } disambig = true; try { PageQueryIterable it = new PageQueryIterable(wiki, pageQuery); Iterator pit = it.iterator(); assertTrue(pit.hasNext()); } catch (WikiApiException e) { Assume.assumeNoException(e); } articles = true; try { PageQueryIterable it = new PageQueryIterable(wiki, pageQuery); Iterator pit = it.iterator(); assertTrue(pit.hasNext()); } catch (WikiApiException e) { Assume.assumeNoException(e); } } }