diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedResources.java index e4b2d44e..972609e2 100644 --- a/src/main/java/org/springframework/hateoas/PagedResources.java +++ b/src/main/java/org/springframework/hateoas/PagedResources.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -208,7 +208,7 @@ public class PagedResources extends Resources { * @param totalElements the total number of elements available */ public PageMetadata(long size, long number, long totalElements) { - this(size, number, totalElements, size == 0 ? 0 : totalElements / size); + this(size, number, totalElements, size == 0 ? 0 : (long) Math.ceil((double) totalElements / (double) size)); } /** diff --git a/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java b/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java index c0ba9bae..b54bc745 100644 --- a/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java +++ b/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,4 +95,12 @@ public class PagedResourcesUnitTest { public void allowsOneIndexedPages() { new PageMetadata(10, 1, 0); } + + /** + * @see #309 + */ + @Test + public void calculatesTotalPagesCorrectly() { + assertThat(new PageMetadata(5, 0, 16).getTotalPages(), is(4L)); + } }