SourceCodeEditor implements IsWidget { public void init(SourceCodeType type, String code, Map<String,String> varMap, Command onSourceCodeChanged) { this.type = type; this.code = code; this.varMap = varMap == null ? new HashMap<>() : varMap; this.hasErrors = false; this.onSourceCodeChanged = onSourceCodeChanged; view.clearAll(); view.edit(type, code); view.focus(); for (String var : varMap.keySet()) { view.declareVariable(var, varMap.get(var)); } String error = validateSourceCode(code); if (error != null) { hasErrors = true; view.error(error); } } @Inject  SourceCodeEditor(View view, HtmlValidator htmlValidator, JsValidator jsValidator); @Override Widget asWidget(); String getCode(); boolean hasErrors(); void init(SourceCodeType type, String code, Map<String,String> varMap, Command onSourceCodeChanged); void focus(); String validateSourceCode(String newCode); void onVariableSelected(String var); boolean onSourceCodeChanged(String newCode);  }
@Test public void testEmpty() { reset(htmlValidator); presenter.init(SourceCodeType.HTML, null, new HashMap<>(), onChange); verify(htmlValidator, never()).validate(any()); reset(htmlValidator); presenter.init(SourceCodeType.HTML, "", new HashMap<>(), onChange); verify(htmlValidator, never()).validate(any()); reset(jsValidator); presenter.init(SourceCodeType.JAVASCRIPT, null, new HashMap<>(), onChange); verify(jsValidator, never()).validate(any(), anyCollection()); reset(jsValidator); presenter.init(SourceCodeType.JAVASCRIPT, "", new HashMap<>(), onChange); verify(jsValidator, never()).validate(any(), anyCollection()); }