@Test public void testGenerate() throws Exception { when(viewDefinition.getId()).thenReturn("svg-cancel"); doAnswer(new Answer<StringBuffer>() { @Override public StringBuffer answer(final InvocationOnMock invocationOnMock) throws Throwable { final ViewFactory factoryArgument = (ViewFactory) invocationOnMock.getArguments()[0]; assertEquals(SVG_NAME, factoryArgument.getSimpleName()); assertEquals(SVG_PKG, factoryArgument.getPackage()); assertEquals(SVG_FQCN, factoryArgument.getImplementedType()); assertTrue(factoryArgument.getViewDefinitions().size() == 1); assertEquals(viewDefinition, factoryArgument.getViewDefinitions().get(0)); return new StringBuffer("done"); } }).when(viewFactoryGenerator).generate(any(ViewFactory.class)); final SVGGeneratorRequest request = new SVGGeneratorRequest(SVG_NAME, SVG_PKG, SVG_FQCN, "", "MyViewBuilderType.class", mock(Messager.class)); request.getViewSources().put(SVG_CANCEL_NAME, SVG_CANCEL_PATH); tested.generate(request); verify(viewDefinition, times(1)).setFactoryMethodName(eq(SVG_CANCEL_NAME)); verify(viewFactoryGenerator, times(1)).generate(any(ViewFactory.class)); }
@Override public StringBuffer generate(final SVGGeneratorRequest request) throws GeneratorException { final String name = request.getName(); final String pkg = request.getPkg(); final String typeOf = request.getImplementedType(); final String cssPath = request.getCssPath(); final String viewBuilderType = request.getViewBuilderType(); final Map<String, String> viewSources = request.getViewSources(); final ViewFactoryImpl viewFactory = new ViewFactoryImpl(name, pkg, typeOf, viewBuilderType); final StyleSheetDefinition[] styleSheetDefinition = new StyleSheetDefinition[1]; if (null != cssPath && cssPath.trim().length() > 0) { final InputStream cssStream = loadResource(cssPath); if (null != cssStream) { try { styleSheetDefinition[0] = SVGStyleTranslator.parseStyleSheetDefinition(cssPath, cssStream); viewFactory.setStyleSheetDefinition(styleSheetDefinition[0]); } catch (Exception e) { throw new RuntimeException("Error while processing the glocal CSS file [" + cssPath + "] ", e); } } } final Set<String> processedSvgIds = new LinkedHashSet<>(); viewSources.forEach((fMethodName, svgPath) -> { parseSVGViewSource(fMethodName, svgPath, styleSheetDefinition[0], result -> { result.setId(fMethodName); result.setFactoryMethodName(fMethodName); viewFactory.getViewDefinitions().add(result); }); processedSvgIds.add(fMethodName); }); final List<ViewDefinition<?>> referencedViewDefinitions = new LinkedList<>(); viewFactory.getViewDefinitions().stream() .flatMap(v -> v.getSVGViewRefs().stream()) .filter(vd -> !processedSvgIds.contains(vd.getViewRefId())) .forEach(vd -> parseSVGViewSource(vd.getViewRefId(), vd.getFilePath(), styleSheetDefinition[0], result -> { final String id = SVGGeneratorFormatUtils.getValidInstanceId(result); result.setFactoryMethodName(id); referencedViewDefinitions.add(result); processedSvgIds.add(id); })); viewFactory.getViewDefinitions().addAll(referencedViewDefinitions); return viewFactoryGenerator.generate(viewFactory); }
SVGGeneratorImpl implements SVGGenerator { @Override public StringBuffer generate(final SVGGeneratorRequest request) throws GeneratorException { final String name = request.getName(); final String pkg = request.getPkg(); final String typeOf = request.getImplementedType(); final String cssPath = request.getCssPath(); final String viewBuilderType = request.getViewBuilderType(); final Map<String, String> viewSources = request.getViewSources(); final ViewFactoryImpl viewFactory = new ViewFactoryImpl(name, pkg, typeOf, viewBuilderType); final StyleSheetDefinition[] styleSheetDefinition = new StyleSheetDefinition[1]; if (null != cssPath && cssPath.trim().length() > 0) { final InputStream cssStream = loadResource(cssPath); if (null != cssStream) { try { styleSheetDefinition[0] = SVGStyleTranslator.parseStyleSheetDefinition(cssPath, cssStream); viewFactory.setStyleSheetDefinition(styleSheetDefinition[0]); } catch (Exception e) { throw new RuntimeException("Error while processing the glocal CSS file [" + cssPath + "] ", e); } } } final Set<String> processedSvgIds = new LinkedHashSet<>(); viewSources.forEach((fMethodName, svgPath) -> { parseSVGViewSource(fMethodName, svgPath, styleSheetDefinition[0], result -> { result.setId(fMethodName); result.setFactoryMethodName(fMethodName); viewFactory.getViewDefinitions().add(result); }); processedSvgIds.add(fMethodName); }); final List<ViewDefinition<?>> referencedViewDefinitions = new LinkedList<>(); viewFactory.getViewDefinitions().stream() .flatMap(v -> v.getSVGViewRefs().stream()) .filter(vd -> !processedSvgIds.contains(vd.getViewRefId())) .forEach(vd -> parseSVGViewSource(vd.getViewRefId(), vd.getFilePath(), styleSheetDefinition[0], result -> { final String id = SVGGeneratorFormatUtils.getValidInstanceId(result); result.setFactoryMethodName(id); referencedViewDefinitions.add(result); processedSvgIds.add(id); })); viewFactory.getViewDefinitions().addAll(referencedViewDefinitions); return viewFactoryGenerator.generate(viewFactory); } }
SVGGeneratorImpl implements SVGGenerator { @Override public StringBuffer generate(final SVGGeneratorRequest request) throws GeneratorException { final String name = request.getName(); final String pkg = request.getPkg(); final String typeOf = request.getImplementedType(); final String cssPath = request.getCssPath(); final String viewBuilderType = request.getViewBuilderType(); final Map<String, String> viewSources = request.getViewSources(); final ViewFactoryImpl viewFactory = new ViewFactoryImpl(name, pkg, typeOf, viewBuilderType); final StyleSheetDefinition[] styleSheetDefinition = new StyleSheetDefinition[1]; if (null != cssPath && cssPath.trim().length() > 0) { final InputStream cssStream = loadResource(cssPath); if (null != cssStream) { try { styleSheetDefinition[0] = SVGStyleTranslator.parseStyleSheetDefinition(cssPath, cssStream); viewFactory.setStyleSheetDefinition(styleSheetDefinition[0]); } catch (Exception e) { throw new RuntimeException("Error while processing the glocal CSS file [" + cssPath + "] ", e); } } } final Set<String> processedSvgIds = new LinkedHashSet<>(); viewSources.forEach((fMethodName, svgPath) -> { parseSVGViewSource(fMethodName, svgPath, styleSheetDefinition[0], result -> { result.setId(fMethodName); result.setFactoryMethodName(fMethodName); viewFactory.getViewDefinitions().add(result); }); processedSvgIds.add(fMethodName); }); final List<ViewDefinition<?>> referencedViewDefinitions = new LinkedList<>(); viewFactory.getViewDefinitions().stream() .flatMap(v -> v.getSVGViewRefs().stream()) .filter(vd -> !processedSvgIds.contains(vd.getViewRefId())) .forEach(vd -> parseSVGViewSource(vd.getViewRefId(), vd.getFilePath(), styleSheetDefinition[0], result -> { final String id = SVGGeneratorFormatUtils.getValidInstanceId(result); result.setFactoryMethodName(id); referencedViewDefinitions.add(result); processedSvgIds.add(id); })); viewFactory.getViewDefinitions().addAll(referencedViewDefinitions); return viewFactoryGenerator.generate(viewFactory); } SVGGeneratorImpl(final SVGDocumentTranslator translator,
                            final SVGViewFactoryGenerator viewFactoryGenerator); }
SVGGeneratorImpl implements SVGGenerator { @Override public StringBuffer generate(final SVGGeneratorRequest request) throws GeneratorException { final String name = request.getName(); final String pkg = request.getPkg(); final String typeOf = request.getImplementedType(); final String cssPath = request.getCssPath(); final String viewBuilderType = request.getViewBuilderType(); final Map<String, String> viewSources = request.getViewSources(); final ViewFactoryImpl viewFactory = new ViewFactoryImpl(name, pkg, typeOf, viewBuilderType); final StyleSheetDefinition[] styleSheetDefinition = new StyleSheetDefinition[1]; if (null != cssPath && cssPath.trim().length() > 0) { final InputStream cssStream = loadResource(cssPath); if (null != cssStream) { try { styleSheetDefinition[0] = SVGStyleTranslator.parseStyleSheetDefinition(cssPath, cssStream); viewFactory.setStyleSheetDefinition(styleSheetDefinition[0]); } catch (Exception e) { throw new RuntimeException("Error while processing the glocal CSS file [" + cssPath + "] ", e); } } } final Set<String> processedSvgIds = new LinkedHashSet<>(); viewSources.forEach((fMethodName, svgPath) -> { parseSVGViewSource(fMethodName, svgPath, styleSheetDefinition[0], result -> { result.setId(fMethodName); result.setFactoryMethodName(fMethodName); viewFactory.getViewDefinitions().add(result); }); processedSvgIds.add(fMethodName); }); final List<ViewDefinition<?>> referencedViewDefinitions = new LinkedList<>(); viewFactory.getViewDefinitions().stream() .flatMap(v -> v.getSVGViewRefs().stream()) .filter(vd -> !processedSvgIds.contains(vd.getViewRefId())) .forEach(vd -> parseSVGViewSource(vd.getViewRefId(), vd.getFilePath(), styleSheetDefinition[0], result -> { final String id = SVGGeneratorFormatUtils.getValidInstanceId(result); result.setFactoryMethodName(id); referencedViewDefinitions.add(result); processedSvgIds.add(id); })); viewFactory.getViewDefinitions().addAll(referencedViewDefinitions); return viewFactoryGenerator.generate(viewFactory); } SVGGeneratorImpl(final SVGDocumentTranslator translator,
                            final SVGViewFactoryGenerator viewFactoryGenerator); @Override StringBuffer generate(final SVGGeneratorRequest request); }
SVGGeneratorImpl implements SVGGenerator { @Override public StringBuffer generate(final SVGGeneratorRequest request) throws GeneratorException { final String name = request.getName(); final String pkg = request.getPkg(); final String typeOf = request.getImplementedType(); final String cssPath = request.getCssPath(); final String viewBuilderType = request.getViewBuilderType(); final Map<String, String> viewSources = request.getViewSources(); final ViewFactoryImpl viewFactory = new ViewFactoryImpl(name, pkg, typeOf, viewBuilderType); final StyleSheetDefinition[] styleSheetDefinition = new StyleSheetDefinition[1]; if (null != cssPath && cssPath.trim().length() > 0) { final InputStream cssStream = loadResource(cssPath); if (null != cssStream) { try { styleSheetDefinition[0] = SVGStyleTranslator.parseStyleSheetDefinition(cssPath, cssStream); viewFactory.setStyleSheetDefinition(styleSheetDefinition[0]); } catch (Exception e) { throw new RuntimeException("Error while processing the glocal CSS file [" + cssPath + "] ", e); } } } final Set<String> processedSvgIds = new LinkedHashSet<>(); viewSources.forEach((fMethodName, svgPath) -> { parseSVGViewSource(fMethodName, svgPath, styleSheetDefinition[0], result -> { result.setId(fMethodName); result.setFactoryMethodName(fMethodName); viewFactory.getViewDefinitions().add(result); }); processedSvgIds.add(fMethodName); }); final List<ViewDefinition<?>> referencedViewDefinitions = new LinkedList<>(); viewFactory.getViewDefinitions().stream() .flatMap(v -> v.getSVGViewRefs().stream()) .filter(vd -> !processedSvgIds.contains(vd.getViewRefId())) .forEach(vd -> parseSVGViewSource(vd.getViewRefId(), vd.getFilePath(), styleSheetDefinition[0], result -> { final String id = SVGGeneratorFormatUtils.getValidInstanceId(result); result.setFactoryMethodName(id); referencedViewDefinitions.add(result); processedSvgIds.add(id); })); viewFactory.getViewDefinitions().addAll(referencedViewDefinitions); return viewFactoryGenerator.generate(viewFactory); } SVGGeneratorImpl(final SVGDocumentTranslator translator,
                            final SVGViewFactoryGenerator viewFactoryGenerator); @Override StringBuffer generate(final SVGGeneratorRequest request);  }