### Question:
PropertiesSubstitutor extends Substitutor { public void deriveVariables() throws GeneratorException { if(serviceDef == null) { throw new GeneratorException("Service definition missing, unable " + "to derive variables"); } VelocityContext vc = getContext(); Object[] keys = vc.getKeys(); for (Object key : keys) { String keyStr = (String)key; String val = (String) vc.get(keyStr); if (key.equals("project_title")) { this.putKeyValuePair("project_midfix", serviceDef.getMidfix()); logger.debug("Note: Velocity variable \"project_midfix\" is derived from property \"project.title\""); this.putKeyValuePair("project_midfix_lc", serviceDef.getDirectory()); logger.debug("Note: Velocity variable \"project_midfix_lc\" is derived from property \"project.title\""); } else if (key.equals("global_package_name")) { String projectPackagePath = StringConverterUtil.packageNameToPackagePath(val); this.putKeyValuePair("project_package_path", projectPackagePath); logger.debug("Note: Velocity variable \"project_package_path\" is derived from property \"global.package.name\""); String projectNamespace = StringConverterUtil.packageNameToNamespace(val); this.putKeyValuePair("project_namespace", projectNamespace); logger.debug("Note: Velocity variable \"project_namespace\" is derived from property \"global.package.name\""); } else if (key.equals("global_project_prefix")) { String globalProjectPrefixLc = val.toLowerCase(); this.putKeyValuePair("global_project_prefix_lc", globalProjectPrefixLc); logger.debug("Note: Velocity variable \"global_project_prefix_lc\" is derived from property \"global.project.prefix\""); } } } PropertiesSubstitutor(String propertiesAbsPath); void addVariable(String key, String val); void deriveVariables(); @Override void processFile(File path); String getGlobalProjectPrefix(); String getProjectResourcesDir(); String getTemplateDir(); String getGenerateDir(); String getProjectMidfix(); String getProjectDirectory(); PropertyUtil getPropertyUtils(); String getProjectPackagePath(); String getProp(String string); String getContextProp(String string); ServiceDef getServiceDef(); void setServiceDef(ServiceDef serviceDef);  }### Answer:
@Test public void testDeriveVariables() throws Exception { String projectTitle = "Test Project"; double toolVersion = 1.0D; ServiceDef sdef = new ServiceDef(projectTitle, Double.toString(toolVersion)); st.setServiceDef(sdef); st.addVariable("project_title", sdef.getName()); st.addVariable("tool_version", sdef.getVersion()); st.addVariable("global_package_name", "org.apache.axis2"); st.deriveVariables(); assertTrue("Variable is not derived correctly.", st.getContextProp("project_midfix").equals("TestProject10")); assertTrue("Variable is not derived correctly.", st.getContextProp("project_midfix_lc").equals("testproject10")); assertTrue("Variable is not derived correctly.", st.getContextProp("project_package_path").equals("org/apache/axis2")); assertTrue("Variable is not derived correctly.", st.getContextProp("project_namespace").equals("http: ServiceDef pruSdef = st.getServiceDef(); assertEquals(sdef, pruSdef); }