Search in sources :

Example 1 with HasToString

use of org.hamcrest.object.HasToString in project xwiki-platform by xwiki.

the class XWikiHibernateRecycleBinStoreTest method getAllDeletedDocuments.

@Test
public void getAllDeletedDocuments() throws Exception {
    XWikiDocument document = mock(XWikiDocument.class);
    when(document.getFullName()).thenReturn("Space.Page");
    when(document.getLanguage()).thenReturn("ro");
    List<XWikiDeletedDocument> deletedVersions = Arrays.asList(mock(XWikiDeletedDocument.class, "v1"), mock(XWikiDeletedDocument.class, "v2"));
    Criteria criteria = mock(Criteria.class);
    when(criteria.list()).thenReturn(deletedVersions);
    when(session.createCriteria(XWikiDeletedDocument.class)).thenReturn(criteria);
    assertArrayEquals(deletedVersions.toArray(new XWikiDeletedDocument[2]), mocker.getComponentUnderTest().getAllDeletedDocuments(document, xcontext, true));
    // Too bad the restrictions don't implement equals..
    verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("fullName=Space.Page"))));
    verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("language=ro"))));
    verify(criteria).addOrder(argThat(new HasToString<Order>(equalTo("date desc"))));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) HasToString(org.hamcrest.object.HasToString) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) Criteria(org.hibernate.Criteria) Test(org.junit.Test)

Example 2 with HasToString

use of org.hamcrest.object.HasToString in project xwiki-platform by xwiki.

the class XWikiHibernateRecycleBinStoreTest method getAllDeletedDocumentsWhenLanguageIsEmpty.

@Test
public void getAllDeletedDocumentsWhenLanguageIsEmpty() throws Exception {
    Criteria criteria = mock(Criteria.class);
    when(session.createCriteria(XWikiDeletedDocument.class)).thenReturn(criteria);
    mocker.getComponentUnderTest().getAllDeletedDocuments(mock(XWikiDocument.class), xcontext, true);
    // Too bad the restrictions don't implement equals..
    verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("fullName=null"))));
    verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("language= or language is null"))));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) HasToString(org.hamcrest.object.HasToString) Criteria(org.hibernate.Criteria) Test(org.junit.Test)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 HasToString (org.hamcrest.object.HasToString)2 Criteria (org.hibernate.Criteria)2 Test (org.junit.Test)2 XWikiDeletedDocument (com.xpn.xwiki.doc.XWikiDeletedDocument)1