JSRegistry { public static String convertToJSRegistry(PluginSimpleContent plugin) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); final StringBuilder sb = new StringBuilder(); if (plugin.getCodeMap().containsKey(CodeType.MAIN)) { sb.append(plugin.getCodeMap().get(CodeType.MAIN)); } if (plugin.getType().equals(PluginType.SCREEN)) { sb.append("$registerPlugin({"); } else if (plugin.getType().equals(PluginType.SPLASH)) { sb.append("$registerSplashScreen({"); } else if (plugin.getType().equals(PluginType.EDITOR)) { sb.append("$registerEditor({"); } else if (plugin.getType().equals(PluginType.PERSPECTIVE)) { sb.append("$registerPerspective({"); } sb.append("id:").append('"').append(plugin.getName()).append('"').append(","); if (plugin.getCodeMap().size() > 1) { for (CodeType ct : CodeType.values()) { if (ct.equals(CodeType.MAIN)) { continue; } if (plugin.getCodeMap().containsKey(ct)) { sb.append(ct.toString().toLowerCase()).append(": "); sb.append(prepareEntryValue(ct, plugin.getCodeMap().get(ct))).append(","); } } } if (plugin.getFrameworks() != null && !plugin.getFrameworks().isEmpty()) { final Framework fm = plugin.getFrameworks().iterator().next(); sb.append("type: ").append('"').append(fm.getType()).append('"').append(','); } if (!plugin.getType().equals(PluginType.PERSPECTIVE)) { sb.append("template: "); gson.toJson(plugin.getTemplate(), sb); } else { sb.append("view: {").append(plugin.getTemplate()).append("}"); } sb.append("});"); return sb.toString(); }  static String convertToJSRegistry(PluginSimpleContent plugin); static boolean JSFunctionNeedsToReturnValue(CodeType codeType);  }
@Test public void createEmptyScreenRegistry() { PluginSimpleContent pluginContent = getEmptyScreen(); assertEquals(loadSample(EMPTY_SCREEN_REGISTRY), JSRegistry.convertToJSRegistry(pluginContent)); }
@Test public void createScreenWithTitleRegistry() { PluginSimpleContent pluginContent = getScreenWithTitle(); assertEquals(loadSample(SCREEN_WITH_TITLE_REGISTRY), JSRegistry.convertToJSRegistry(pluginContent)); }
@Test public void createScreenWithTitleAndMainRegistry() { PluginSimpleContent pluginContent = getScreenWithMainAndTitle(); assertEquals(loadSample(SCREEN_WITH_TITLE_AND_NAME_REGISTRY), JSRegistry.convertToJSRegistry(pluginContent)); }
@Test public void createAngularScreenRegistry() { PluginSimpleContent pluginContent = getTodoAngularPluginSimpleContent(); assertEquals(loadSample(ANGULAR_TODO_REGISTRY), JSRegistry.convertToJSRegistry(pluginContent)); }
@Test public void createSplashScreenRegistry() { PluginSimpleContent pluginContent = getSplashScreen(); assertEquals(loadSample(SPLASH_SCREEN_REGISTRY), JSRegistry.convertToJSRegistry(pluginContent)); }