@Test public void should_extract_variable_from_angular_object_registry() throws Exception { final String noteId = "noteId"; final AngularObjectRegistry registry = mock(AngularObjectRegistry.class); final Note note = mock(Note.class); final Map<String, Input> inputs = new HashMap<>(); inputs.put("name", null); inputs.put("age", null); inputs.put("job", null); final String scriptBody = "My name is ${name} and I am ${age=20} years old. " + "My occupation is ${ job = engineer | developer | artists}"; final Paragraph paragraph = new Paragraph(note, null, null, null); final String paragraphId = paragraph.getId(); final AngularObject nameAO = AngularObjectBuilder.build("name", "DuyHai DOAN", noteId, paragraphId); final AngularObject ageAO = AngularObjectBuilder.build("age", 34, noteId, null); when(note.getId()).thenReturn(noteId); when(registry.get("name", noteId, paragraphId)).thenReturn(nameAO); when(registry.get("age", noteId, null)).thenReturn(ageAO); final String expected = "My name is DuyHai DOAN and I am 34 years old. " + "My occupation is ${ job = engineer | developer | artists}"; final String actual = paragraph.extractVariablesFromAngularRegistry(scriptBody, inputs, registry); verify(registry).get("name", noteId, paragraphId); verify(registry).get("age", noteId, null); assertEquals(actual, expected); }
String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) { final String noteId = this.getNote().getId(); final String paragraphId = this.getId(); final Set<String> keys = new HashSet<>(inputs.keySet()); for (String varName : keys) { final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId); final AngularObject noteScoped = angularRegistry.get(varName, noteId, null); final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped; if (angularObject != null) { inputs.remove(varName); final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]"; scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString()); } } return scriptBody; }
Paragraph extends Job implements Serializable, Cloneable { String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) { final String noteId = this.getNote().getId(); final String paragraphId = this.getId(); final Set<String> keys = new HashSet<>(inputs.keySet()); for (String varName : keys) { final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId); final AngularObject noteScoped = angularRegistry.get(varName, noteId, null); final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped; if (angularObject != null) { inputs.remove(varName); final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]"; scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString()); } } return scriptBody; } }
Paragraph extends Job implements Serializable, Cloneable { String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) { final String noteId = this.getNote().getId(); final String paragraphId = this.getId(); final Set<String> keys = new HashSet<>(inputs.keySet()); for (String varName : keys) { final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId); final AngularObject noteScoped = angularRegistry.get(varName, noteId, null); final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped; if (angularObject != null) { inputs.remove(varName); final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]"; scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString()); } } return scriptBody; } @VisibleForTesting  Paragraph();  Paragraph(String paragraphId, Note note, JobListener listener,
      InterpreterFactory factory, InterpreterSettingManager interpreterSettingManager);  Paragraph(Note note, JobListener listener, InterpreterFactory factory,
      InterpreterSettingManager interpreterSettingManager); }
Paragraph extends Job implements Serializable, Cloneable { String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) { final String noteId = this.getNote().getId(); final String paragraphId = this.getId(); final Set<String> keys = new HashSet<>(inputs.keySet()); for (String varName : keys) { final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId); final AngularObject noteScoped = angularRegistry.get(varName, noteId, null); final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped; if (angularObject != null) { inputs.remove(varName); final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]"; scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString()); } } return scriptBody; } @VisibleForTesting  Paragraph();  Paragraph(String paragraphId, Note note, JobListener listener,
      InterpreterFactory factory, InterpreterSettingManager interpreterSettingManager);  Paragraph(Note note, JobListener listener, InterpreterFactory factory,
      InterpreterSettingManager interpreterSettingManager); Map<String, Paragraph> getUserParagraphMap(); Paragraph getUserParagraph(String user); @Override void setResult(Object results); Paragraph cloneParagraphForUser(String user); void clearUserParagraphs(); void addUser(Paragraph p, String user); String getUser(); String getText(); void setText(String newText); AuthenticationInfo getAuthenticationInfo(); void setAuthenticationInfo(AuthenticationInfo authenticationInfo); String getTitle(); void setTitle(String title); void setNote(Note note); Note getNote(); boolean isEnabled(); String getRequiredReplName(); static String getRequiredReplName(String text); String getScriptBody(); static String getScriptBody(String text); Interpreter getRepl(String name); Interpreter getCurrentRepl(); List<InterpreterCompletion> getInterpreterCompletion(); List<InterpreterCompletion> completion(String buffer, int cursor); void setInterpreterFactory(InterpreterFactory factory); void setInterpreterSettingManager(InterpreterSettingManager interpreterSettingManager); InterpreterResult getResult(); @Override Object getReturn(); Object getPreviousResultFormat(); @Override int progress(); @Override Map<String, Object> info(); boolean isBlankParagraph(); InterpreterContextRunner getInterpreterContextRunner(); void setStatusToUserParagraph(Status status); Map<String, Object> getConfig(); void setConfig(Map<String, Object> config); void setReturn(InterpreterResult value, Throwable t); @Override Object clone(); ApplicationState createOrGetApplicationState(HeliumPackage pkg); ApplicationState getApplicationState(String appId); List<ApplicationState> getAllApplicationStates(); String getMagic(); }
Paragraph extends Job implements Serializable, Cloneable { String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) { final String noteId = this.getNote().getId(); final String paragraphId = this.getId(); final Set<String> keys = new HashSet<>(inputs.keySet()); for (String varName : keys) { final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId); final AngularObject noteScoped = angularRegistry.get(varName, noteId, null); final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped; if (angularObject != null) { inputs.remove(varName); final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]"; scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString()); } } return scriptBody; } @VisibleForTesting  Paragraph();  Paragraph(String paragraphId, Note note, JobListener listener,
      InterpreterFactory factory, InterpreterSettingManager interpreterSettingManager);  Paragraph(Note note, JobListener listener, InterpreterFactory factory,
      InterpreterSettingManager interpreterSettingManager); Map<String, Paragraph> getUserParagraphMap(); Paragraph getUserParagraph(String user); @Override void setResult(Object results); Paragraph cloneParagraphForUser(String user); void clearUserParagraphs(); void addUser(Paragraph p, String user); String getUser(); String getText(); void setText(String newText); AuthenticationInfo getAuthenticationInfo(); void setAuthenticationInfo(AuthenticationInfo authenticationInfo); String getTitle(); void setTitle(String title); void setNote(Note note); Note getNote(); boolean isEnabled(); String getRequiredReplName(); static String getRequiredReplName(String text); String getScriptBody(); static String getScriptBody(String text); Interpreter getRepl(String name); Interpreter getCurrentRepl(); List<InterpreterCompletion> getInterpreterCompletion(); List<InterpreterCompletion> completion(String buffer, int cursor); void setInterpreterFactory(InterpreterFactory factory); void setInterpreterSettingManager(InterpreterSettingManager interpreterSettingManager); InterpreterResult getResult(); @Override Object getReturn(); Object getPreviousResultFormat(); @Override int progress(); @Override Map<String, Object> info(); boolean isBlankParagraph(); InterpreterContextRunner getInterpreterContextRunner(); void setStatusToUserParagraph(Status status); Map<String, Object> getConfig(); void setConfig(Map<String, Object> config); void setReturn(InterpreterResult value, Throwable t); @Override Object clone(); ApplicationState createOrGetApplicationState(HeliumPackage pkg); ApplicationState getApplicationState(String appId); List<ApplicationState> getAllApplicationStates(); String getMagic(); public GUI settings; }