### Question:
ObservedContextFactory extends ContextFactory { @Override protected void observeInstructionCount(Context cx, int instructionCount) { final ObservedJavaScriptContext context = (ObservedJavaScriptContext) cx; final long timeout = TimeUnit.MILLISECONDS.convert(manager.getConfiguration().getScriptExecutionTimeout(), TimeUnit.SECONDS); if (timeout > 0 && currentTimeMillis() - context.getStartTime() > timeout) { throw new Error("Interrupt."); } } ObservedContextFactory(StandardScriptEngineManager manager);   }### Answer:
@Test(expectedExceptions = Error.class) public void testThrowsErrorWhenInterrupted() { ObservedContextFactory.ObservedJavaScriptContext mockContext = mock(ObservedContextFactory.ObservedJavaScriptContext.class); int instructionCount = 0; setTimeout(1); when(mockContext.getStartTime()).thenReturn(1l); testContextFactory.observeInstructionCount(mockContext, instructionCount); }
@Test public void testTimeoutDisabledNoInterrupt() { ObservedContextFactory.ObservedJavaScriptContext mockContext = mock(ObservedContextFactory.ObservedJavaScriptContext.class); int instructionCount = 0; setTimeout(0); testContextFactory.observeInstructionCount(mockContext, instructionCount); }