package org.openbankdata.bank.americanexpress.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.openbankdata.core.client.BankResponse;
import org.openbankdata.core.client.MockedBankResponse;
import org.openbankdata.core.client.Pagination;
import org.openbankdata.core.client.PaginationStrategy;
import org.junit.Before;
import org.junit.Test;
public class AmericanExpressTransactionPaginationStrategyTest {
private PaginationStrategy mPaginationStrategy;
@Before
public void setUp() {
mPaginationStrategy = new AmericanExpressTransactionPaginationStrategy();
}
@Test
public void testPagination() {
// Given
// Two pages are available
BankResponse mockedResponse = mockedBankResponse();
// When
// The first page has been requested.
Pagination pagination = mPaginationStrategy.parsePagination(mockedResponse);
// Then
assertNotNull("The pagination should not be null", pagination);
assertEquals("The previous page should have been set.", 0, pagination.getPrev());
assertEquals("The next page should have been set", 1, pagination.getNext());
assertEquals("The first page should have been set", 0, pagination.getFirst());
assertEquals("The last page should have been set", 1, pagination.getLast());
}
@Test
public void testParameterName() {
assertEquals("Correct pagination parameter", "BPIndex",
mPaginationStrategy.getPaginationParameter());
}
private BankResponse mockedBankResponse() {
MockedBankResponse response =
new MockedBankResponse("americanexpress-paginated-transactions-1.htm");
response.code(200);
return response;
}
}