### Question:
CardinalityLimiters { public static Function<String, String> first(int n) { return new FirstLimiter(Math.min(n, MAX_LIMIT)); } private  CardinalityLimiters(); static Function<String, String> first(int n); static Function<String, String> mostFrequent(int n); static Function<String, String> rollup(int n); static final String OTHERS; static final String AUTO_ROLLUP; }### Answer:
@Test public void first2() { Function<String, String> f = CardinalityLimiters.first(2); Assertions.assertEquals("a", f.apply("a")); Assertions.assertEquals("b", f.apply("b")); Assertions.assertEquals(CardinalityLimiters.OTHERS, f.apply("c")); Assertions.assertEquals("a", f.apply("a")); }
@Test public void firstToStringEmpty() { Function<String, String> f = CardinalityLimiters.first(2); Assertions.assertEquals("FirstLimiter()", f.toString()); }
@Test public void firstToStringPartial() { Function<String, String> f = CardinalityLimiters.first(2); Assertions.assertEquals("b", f.apply("b")); Assertions.assertEquals("FirstLimiter(b)", f.toString()); }
@Test public void firstToStringFull() { Function<String, String> f = CardinalityLimiters.first(2); Assertions.assertEquals("a", f.apply("a")); Assertions.assertEquals("b", f.apply("b")); Assertions.assertEquals("FirstLimiter(a,b)", f.toString()); }
@Test public void firstSerializability() { Function<String, String> limiter = CardinalityLimiters.first(2); limiter.apply("a"); limiter.apply("b"); limiter.apply("c"); checkSerde(limiter); }