package com.gentics.mesh.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;

import com.gentics.mesh.core.data.page.impl.PageImpl;
import com.gentics.mesh.core.rest.common.ListResponse;
import com.gentics.mesh.query.impl.PagingParameter;
public class RestModelPagingHelperTest {

	@Test
	public void testPagingOffsetCorrection() {
		TestListResponse response = new TestListResponse();
		PageImpl<?> page = mock(PageImpl.class);

		int nPages = 3;
		int nCurrentPage = 0;
		int nTotalElements = 1000;
		int nElements = 200;
		long nPageSize = 21;

		PagingParameter info = new PagingParameter(nCurrentPage + 1, (int) nPageSize);

		when(page.getNumber()).thenReturn(nCurrentPage);
		when(page.getTotalPages()).thenReturn(nPages);
		when(page.getNumberOfElements()).thenReturn(nElements);
		when(page.getTotalElements()).thenReturn(nTotalElements);
		when(page.getPerPage()).thenReturn(nPageSize);

		page.setPaging(response);

		assertNotNull(response.getMetainfo());
		assertEquals(nCurrentPage, response.getMetainfo().getCurrentPage());
		assertEquals(nPages, response.getMetainfo().getPageCount());
		assertEquals(nTotalElements, response.getMetainfo().getTotalCount());
		assertEquals(info.getPerPage(), response.getMetainfo().getPerPage());
	}

}

@SuppressWarnings("rawtypes")
class TestListResponse extends ListResponse {

}

@@ -220,16 +220,89 @@
 t.Test;%0A
+import org.mockito.Mockito;%0A%0Aimport com.gentics.mesh.core.data.page.Page;
 %0Aimport 
@@ -455,16 +455,17 @@
 ameter;%0A
+%0A
 public c
@@ -551,20 +551,16 @@
 n() %7B%0A%09%09
-Test
 ListResp
@@ -579,20 +579,16 @@
 e = new 
-Test
 ListResp
@@ -605,15 +605,8 @@
 Page
-Impl%3C?%3E
  pag
@@ -1099,16 +1099,76 @@
 eSize);%0A
+%09%09Mockito.doCallRealMethod().when(page).setPaging(response);
 %0A%09%09page.
@@ -1518,84 +1518,4 @@
 %0A%0A%7D%0A
-%0A@SuppressWarnings(%22rawtypes%22)%0Aclass TestListResponse extends ListResponse %7B%0A%0A%7D%0A

Fix RestModelPagingHelperTest