Interpreter { public Properties getProperty() { Properties p = new Properties(); p.putAll(property); Map<String, InterpreterProperty> defaultProperties = Interpreter .findRegisteredInterpreterByClassName(getClassName()).getProperties(); for (String k : defaultProperties.keySet()) { if (!p.containsKey(k)) { String value = defaultProperties.get(k).getDefaultValue(); if (value != null) { p.put(k, defaultProperties.get(k).getDefaultValue()); } } } return p; } Interpreter(Properties property); abstract void open(); abstract void close(); abstract InterpreterResult interpret(String st, InterpreterContext context); abstract void cancel(InterpreterContext context); abstract FormType getFormType(); abstract int getProgress(InterpreterContext context); abstract List<String> completion(String buf, int cursor); Scheduler getScheduler(); void destroy(); void setProperty(Properties property); Properties getProperty(); String getProperty(String key); String getClassName(); void setInterpreterGroup(InterpreterGroup interpreterGroup); InterpreterGroup getInterpreterGroup(); URL[] getClassloaderUrls(); void setClassloaderUrls(URL[] classloaderUrls); static void register(String name, String className); static void register(String name, String group, String className); static void register(String name, String group, String className,
      Map<String, InterpreterProperty> properties); static RegisteredInterpreter findRegisteredInterpreterByClassName(String className); static Map<String, RegisteredInterpreter> registeredInterpreters; }
@Test public void testDefaultProperty() { Properties p = new Properties(); MockInterpreterA intp = new MockInterpreterA(p); assertEquals(1, intp.getProperty().size()); assertEquals("v1", intp.getProperty().get("p1")); assertEquals("v1", intp.getProperty("p1")); }
@Test public void testOverridedProperty() { Properties p = new Properties(); p.put("p1", "v2"); MockInterpreterA intp = new MockInterpreterA(p); assertEquals(1, intp.getProperty().size()); assertEquals("v2", intp.getProperty().get("p1")); assertEquals("v2", intp.getProperty("p1")); }
@Test public void testAdditionalProperty() { Properties p = new Properties(); p.put("p2", "v2"); MockInterpreterA intp = new MockInterpreterA(p); assertEquals(2, intp.getProperty().size()); assertEquals("v1", intp.getProperty().get("p1")); assertEquals("v1", intp.getProperty("p1")); assertEquals("v2", intp.getProperty().get("p2")); assertEquals("v2", intp.getProperty("p2")); }