Don't allow duplicates in premium/reserved lists

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148458642
This commit is contained in:
mcilwain 2017-02-24 07:26:43 -08:00 committed by Ben McIlwain
parent ea3a8dfa9d
commit dd400f30f5
6 changed files with 52 additions and 14 deletions

View file

@ -273,6 +273,18 @@ public class PremiumListTest {
}
}
@Test
public void testParse_cannotIncludeDuplicateLabels() {
thrown.expect(
IllegalStateException.class,
"List 'tld' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
PremiumList.get("tld")
.get()
.parse(
ImmutableList.of(
"lol,USD 100", "rofl,USD 90", "paper,USD 80", "wood,USD 70", "lol,USD 200"));
}
/** Persists a premium list with a specified number of nonsense entries. */
private PremiumList persistHumongousPremiumList(String name, int size) {
String[] entries = new String[size];

View file

@ -291,6 +291,21 @@ public class ReservedListTest {
.build());
}
@Test
public void testParse_cannotIncludeDuplicateLabels() {
ReservedList rl = new ReservedList.Builder().setName("blah").build();
thrown.expect(
IllegalStateException.class,
"List 'blah' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
rl.parse(
ImmutableList.of(
"lol,FULLY_BLOCKED",
"rofl,FULLY_BLOCKED",
"paper,FULLY_BLOCKED",
"wood,FULLY_BLOCKED",
"lol,FULLY_BLOCKED"));
}
/** Gets the name of a reserved list. */
public static final Function<Key<ReservedList>, String> GET_NAME_FUNCTION =
new Function<Key<ReservedList>, String>() {