CollectionSizer { public static int getCollectionSize( String range, int collectionSize ) { int min = Integer.parseInt( range.split( "-" )[0] ); int max = Integer.parseInt( range.split( "-" )[1] ); if ( min == 0 && max == 0 ) { return 0; } if ( min > collectionSize ) { min = collectionSize; } if ( max > collectionSize ) { max = collectionSize; } return min == max ? min : ints().rangeClosed( min, max ).get() - 1; }  static int getCollectionSize( String range, int collectionSize ); static int getCollectionSize( String range );  }
@Test public void verifyRandomCollectionSize() { assertThat( CollectionSizer.getCollectionSize( "1-10", 20 ) ).isBetween( 0, 9 ); assertThat( CollectionSizer.getCollectionSize( "1-10", 5 ) ).isBetween( 0, 4 ); assertThat( CollectionSizer.getCollectionSize( "0-0", 5 ) ).isEqualTo( 0 ); assertThat( CollectionSizer.getCollectionSize( "10-100", 50 ) ).isBetween( 9, 49 ); }