HardSoftCodeLimiter implements CodeLimiter { public int hardLimit() { return hardLimit; } private  HardSoftCodeLimiter(int softLimit, int hardLimit, int resolution, Handler handler); static Builder builder(); int instructionCount(); int softLimit(); int hardLimit(); void check();  }
@Test public void testHardLimit() throws CodeException { TestHandler handler = new TestHandler(Limit.HARD, 6); CodeLimiter limiter = HardSoftCodeLimiter.builder() .setHardLimit(5) .setResolution(1) .setHandler(handler) .build(); JsonNode node = JsonUtils.decode("[0,1,2,3,4,5,6,7,8,9]"); Context ctx = new Context(node); ctx.setCodeLimiter(limiter); RootInst root = builder().repeated("@").var("@").end().eof().build(); try { ctx.execute(root); fail("Expected CODE_LIMIT_REACHED exception"); } catch (CodeExecuteException e) { assertTrue(handler.wasCalled()); assertEquals(handler.limitType(), Limit.HARD); assertEquals(e.getErrorInfo().getType(), CODE_LIMIT_REACHED); assertEquals(limiter.instructionCount(), 6); } }