TraceCategoryRegistry implements ITraceCategoryRegistry { @Override public long get(String name) { return categories.computeIfAbsent(name, this::nextCode); } TraceCategoryRegistry(); @Override long get(String name); @Override String getName(long categoryCode); String nameAt(int n); static int mostSignificantBit(long n); @Override String toString();  }
@Test public void limit() { TraceCategoryRegistry registry = new TraceCategoryRegistry(); int success = 0; int fail = 0; String expectedError = "Cannot add category"; String actualError = null; for (int i = 0; i < ITraceCategoryRegistry.NO_CATEGORIES + 1; ++i) { try { final String name = "cat" + Integer.toHexString(i); registry.get(name); ++success; } catch (IllegalStateException ise) { actualError = ise.getMessage(); ++fail; } } Assert.assertEquals(64, success); Assert.assertEquals(1, fail); Assert.assertTrue(actualError.contains(expectedError)); }