@Test public void onSourceCodeOpenButtonClick() { ToolkitView view = mock(ToolkitView.class); File file = new File("src/test/resources/parse_error.txt"); when(view.pickFileToParse()).thenReturn(file); SourceCodeModel model = mock(SourceCodeModel.class); AstNode astNode = mock(AstNode.class); when(model.getHighlightedSourceCode()).thenReturn("my_mocked_highlighted_source_code"); when(model.getAstNode()).thenReturn(astNode); when(model.getXml()).thenReturn("my_mocked_xml"); ToolkitPresenter presenter = new ToolkitPresenter((ConfigurationModel) when(mock(ConfigurationModel.class).getCharset()).thenReturn(StandardCharsets.UTF_8).getMock(), model); presenter.setView(view); presenter.onSourceCodeOpenButtonClick(); verify(view).pickFileToParse(); verify(view).clearConsole(); verify(view).displayHighlightedSourceCode("my_mocked_highlighted_source_code"); verify(model).setSourceCode(file, StandardCharsets.UTF_8); verify(view).displayAst(astNode); verify(view).displayXml("my_mocked_xml"); verify(view).scrollSourceCodeTo(new Point(0, 0)); verify(view).setFocusOnAbstractSyntaxTreeView(); verify(view).enableXPathEvaluateButton(); }
public void onSourceCodeOpenButtonClick() { File fileToParse = view.pickFileToParse(); if (fileToParse != null) { view.clearConsole(); try { view.displayHighlightedSourceCode(new String(Files.readAllBytes(Paths.get(fileToParse.getPath())), configurationModel.getCharset())); } catch (IOException e) { throw new RuntimeException(e); } model.setSourceCode(fileToParse, configurationModel.getCharset()); view.displayHighlightedSourceCode(model.getHighlightedSourceCode()); view.displayAst(model.getAstNode()); view.displayXml(model.getXml()); view.scrollSourceCodeTo(new Point(0, 0)); view.setFocusOnAbstractSyntaxTreeView(); view.enableXPathEvaluateButton(); } }
ToolkitPresenter { public void onSourceCodeOpenButtonClick() { File fileToParse = view.pickFileToParse(); if (fileToParse != null) { view.clearConsole(); try { view.displayHighlightedSourceCode(new String(Files.readAllBytes(Paths.get(fileToParse.getPath())), configurationModel.getCharset())); } catch (IOException e) { throw new RuntimeException(e); } model.setSourceCode(fileToParse, configurationModel.getCharset()); view.displayHighlightedSourceCode(model.getHighlightedSourceCode()); view.displayAst(model.getAstNode()); view.displayXml(model.getXml()); view.scrollSourceCodeTo(new Point(0, 0)); view.setFocusOnAbstractSyntaxTreeView(); view.enableXPathEvaluateButton(); } } }
ToolkitPresenter { public void onSourceCodeOpenButtonClick() { File fileToParse = view.pickFileToParse(); if (fileToParse != null) { view.clearConsole(); try { view.displayHighlightedSourceCode(new String(Files.readAllBytes(Paths.get(fileToParse.getPath())), configurationModel.getCharset())); } catch (IOException e) { throw new RuntimeException(e); } model.setSourceCode(fileToParse, configurationModel.getCharset()); view.displayHighlightedSourceCode(model.getHighlightedSourceCode()); view.displayAst(model.getAstNode()); view.displayXml(model.getXml()); view.scrollSourceCodeTo(new Point(0, 0)); view.setFocusOnAbstractSyntaxTreeView(); view.enableXPathEvaluateButton(); } } ToolkitPresenter(ConfigurationModel configurationModel, SourceCodeModel model); }
ToolkitPresenter { public void onSourceCodeOpenButtonClick() { File fileToParse = view.pickFileToParse(); if (fileToParse != null) { view.clearConsole(); try { view.displayHighlightedSourceCode(new String(Files.readAllBytes(Paths.get(fileToParse.getPath())), configurationModel.getCharset())); } catch (IOException e) { throw new RuntimeException(e); } model.setSourceCode(fileToParse, configurationModel.getCharset()); view.displayHighlightedSourceCode(model.getHighlightedSourceCode()); view.displayAst(model.getAstNode()); view.displayXml(model.getXml()); view.scrollSourceCodeTo(new Point(0, 0)); view.setFocusOnAbstractSyntaxTreeView(); view.enableXPathEvaluateButton(); } } ToolkitPresenter(ConfigurationModel configurationModel, SourceCodeModel model); void setView(ToolkitView view); void run(String title); void onSourceCodeOpenButtonClick(); void onSourceCodeParseButtonClick(); void onXPathEvaluateButtonClick(); void onSourceCodeKeyTyped(); void onSourceCodeTextCursorMoved(); void onAstSelectionChanged(); void onConfigurationPropertyFocusLost(String name); }
ToolkitPresenter { public void onSourceCodeOpenButtonClick() { File fileToParse = view.pickFileToParse(); if (fileToParse != null) { view.clearConsole(); try { view.displayHighlightedSourceCode(new String(Files.readAllBytes(Paths.get(fileToParse.getPath())), configurationModel.getCharset())); } catch (IOException e) { throw new RuntimeException(e); } model.setSourceCode(fileToParse, configurationModel.getCharset()); view.displayHighlightedSourceCode(model.getHighlightedSourceCode()); view.displayAst(model.getAstNode()); view.displayXml(model.getXml()); view.scrollSourceCodeTo(new Point(0, 0)); view.setFocusOnAbstractSyntaxTreeView(); view.enableXPathEvaluateButton(); } } ToolkitPresenter(ConfigurationModel configurationModel, SourceCodeModel model); void setView(ToolkitView view); void run(String title); void onSourceCodeOpenButtonClick(); void onSourceCodeParseButtonClick(); void onXPathEvaluateButtonClick(); void onSourceCodeKeyTyped(); void onSourceCodeTextCursorMoved(); void onAstSelectionChanged(); void onConfigurationPropertyFocusLost(String name);  }