ForLoopIterationContext extends DefaultContext { @Override public StackFrameContext moveTo(final RunningKeyword keyword, final RobotBreakpointSupplier breakpointSupplier) { if (keyword.getType() != KeywordCallType.NORMAL_CALL) { throw new IllegalDebugContextStateException("Only normal keyword can be called when executing loop"); } if (forLoopExecutable != null) { return CommonContextsTransitions.moveToExecutable(new ArrayList<>(), locationUri, forLoopExecutable.getLoopExecutable().getInnerExecutables(), 0, keyword, breakpointSupplier); } else { return this; } } @VisibleForTesting  ForLoopIterationContext(final URI locationUri, final FileRegion region, final String errorMsg); @VisibleForTesting  ForLoopIterationContext(final ExecutableWithDescriptor forLoopExecutable, final URI locationUri,
            final FileRegion region); @VisibleForTesting  ForLoopIterationContext(final ExecutableWithDescriptor forLoopExecutable, final URI locationUri,
            final FileRegion region, final String errorMsg); static StackFrameContext findContextForLoopIteration(final StackFrameContext currentContext,
            final String keywordName); @Override boolean isErroneous(); @Override Optional<String> getErrorMessage(); @Override Optional<URI> getAssociatedPath(); @Override Optional<FileRegion> getFileRegion(); @Override StackFrameContext moveTo(final RunningKeyword keyword, final RobotBreakpointSupplier breakpointSupplier);  }
@Test public void itIsIllegalToMoveToKeywordOfTypeDifferentThanNormal() { final ForLoopIterationContext context = new ForLoopIterationContext(mock(ExecutableWithDescriptor.class), URI.create("file: new FileRegion(new FilePosition(2, 0, 15), new FilePosition(2, 5, 20)), null); for (final KeywordCallType type : EnumSet.complementOf(EnumSet.of(KeywordCallType.NORMAL_CALL))) { assertThatExceptionOfType(IllegalDebugContextStateException.class).isThrownBy( () -> context.moveTo(new RunningKeyword("lib", "kw", type), mock(RobotBreakpointSupplier.class))) .withMessage("Only normal keyword can be called when executing loop") .withNoCause(); } }
@Test public void sameContextIsReturned_whenMovingToAnyTypeOfKeywordAndThereIsNoElement() { final ForLoopIterationContext context = new ForLoopIterationContext(URI.create("file: new FileRegion(new FilePosition(2, 0, 15), new FilePosition(2, 5, 20)), null); final StackFrameContext contextAfterMove = context .moveTo(new RunningKeyword("_", "_", KeywordCallType.NORMAL_CALL), mock(RobotBreakpointSupplier.class)); assertThat(contextAfterMove).isSameAs(context); }