Paragraph extends JobWithProgressPoller<InterpreterResult> implements Cloneable,
    JsonSerializable { 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);  Paragraph(Note note, JobListener listener);  Paragraph(Paragraph p2); Map<String, Paragraph> getUserParagraphMap(); Paragraph getUserParagraph(String user); @Override void setResult(InterpreterResult result); Paragraph cloneParagraphForUser(String user); void clearUserParagraphs(); void addUser(Paragraph p, String user); String getUser(); String getText(); void setText(String newText); void parseText(); AuthenticationInfo getAuthenticationInfo(); void setAuthenticationInfo(AuthenticationInfo subject); String getTitle(); void setTitle(String title); String getIntpText(); String getScriptText(); void setNote(Note note); Note getNote(); Map<String, String> getLocalProperties(); boolean isEnabled(); Interpreter getBindedInterpreter(); @VisibleForTesting void setInterpreter(Interpreter interpreter); Interpreter getInterpreter(); List<InterpreterCompletion> completion(String buffer, int cursor); int calculateCursorPosition(String buffer, int cursor); @Override InterpreterResult getReturn(); @Override int progress(); @Override Map<String, Object> info(); boolean shouldSkipRunParagraph(); boolean execute(boolean blocking); boolean execute(String interpreterGroupId, boolean blocking); @Override void setStatus(Status status); void setStatusToUserParagraph(Status status); Map<String, Object> getConfig(); void setConfig(Map<String, Object> config); void mergeConfig(Map<String, Object> newConfig); void updateConfig(Map<String, String> newConfig); void setReturn(InterpreterResult value, Throwable t); ApplicationState createOrGetApplicationState(HeliumPackage pkg); ApplicationState getApplicationState(String appId); List<ApplicationState> getAllApplicationStates(); boolean isValidInterpreter(String replName); void updateRuntimeInfos(String label, String tooltip, Map<String, String> infos,
      String group, String intpSettingId); Map<String, ParagraphRuntimeInfo> getRuntimeInfos(); void cleanRuntimeInfos(); void cleanOutputBuffer(); void checkpointOutput(); @VisibleForTesting void waitUntilFinished(); @VisibleForTesting void waitUntilRunning(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toJson(); static Paragraph fromJson(String json); void updateOutputBuffer(int index, InterpreterResult.Type type, String output); void recover(); public GUI settings; }
@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); 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); }