StacktraceBuilder extends RobotDefaultAgentEventListener { @Override public void handleResourceImport(final ResourceImportEvent event) { if (event.isDynamicallyImported()) { stacktrace.getFirstFrameSatisfying(StackFrame::isSuiteContext).get().addLoadedResource(event.getPath()); } else { currentlyImportedResources.add(event.getPath()); } } StacktraceBuilder(final Stacktrace stacktrace, final ElementsLocator locator,
            final RobotBreakpointSupplier breakpointSupplier); @Override void handleSuiteStarted(final SuiteStartedEvent event); @Override void handleTestStarted(final TestStartedEvent event); @Override void handleKeywordAboutToStart(final KeywordStartedEvent event); @Override void handleKeywordStarted(final KeywordStartedEvent event); @Override void handleKeywordAboutToEnd(final KeywordEndedEvent event); @Override void handleKeywordEnded(final KeywordEndedEvent event); @Override void handleTestEnded(final TestEndedEvent event); @Override void handleSuiteEnded(final SuiteEndedEvent event); @Override void handleResourceImport(final ResourceImportEvent event); @Override void handleVariables(final VariablesEvent event); @Override void handleClosed();  }
@Test public void dynamicallyLoadedResourceIsAddedToSuiteFrame() { final Stacktrace stack = new Stacktrace(); stack.push(new StackFrame("Suite", FrameCategory.SUITE, 0, mock(StackFrameContext.class))); final StackFrame innerSuiteFrame = new StackFrame("Inner", FrameCategory.SUITE, 1, mock(StackFrameContext.class)); stack.push(innerSuiteFrame); stack.push(new StackFrame("Test", FrameCategory.TEST, 2, mock(StackFrameContext.class))); stack.push(new StackFrame("keyword", FrameCategory.KEYWORD, 2, mock(StackFrameContext.class))); final StacktraceBuilder builder = new StacktraceBuilder(stack, mock(ElementsLocator.class), new RobotBreakpointSupplier()); assertThat(stack.stream()).allSatisfy(f -> assertThat(f.getLoadedResources().isEmpty())); builder.handleResourceImport(new ResourceImportEvent(URI.create("file: builder.handleResourceImport(new ResourceImportEvent(URI.create("file: assertThat(innerSuiteFrame.getLoadedResources()).containsOnly(URI.create("file: URI.create("file: assertThat(stack.stream().filter(f -> f.getLoadedResources().isEmpty())).hasSize(3); }