Package my.home.dsl.deepclone

Source Code of my.home.dsl.deepclone.DeepCloneAdvancedGeneratorTest

package my.home.dsl.deepclone;

import com.google.inject.Inject;
import java.util.Map;
import my.home.dsl.DeepCloneInjectorProvider;
import my.home.dsl.deepClone.Model;
import my.home.dsl.deepclone.test.utils.MyValidationHelper;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.generator.InMemoryFileSystemAccess;
import org.eclipse.xtext.junit4.InjectWith;
import org.eclipse.xtext.junit4.XtextRunner;
import org.eclipse.xtext.junit4.util.ParseHelper;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Parse sample DeepClone DSL file and test DeepClone to Java generator.
* Files are generated to memory, see {@link InMemoryFileSystemAccess}, perfect for testing.
* @see http://christiandietrich.wordpress.com/2012/05/08/unittesting-xtend-generators/
*
* @author espinosa
*/
@RunWith(XtextRunner.class)
@InjectWith(DeepCloneInjectorProvider.class)
@SuppressWarnings("all")
public class DeepCloneAdvancedGeneratorTest {
  @Inject
  private IGenerator generatorDslToJava;
 
  @Inject
  private ParseHelper<Model> parseHelper;
 
  @Inject
  private MyValidationHelper myValidationHelper;
 
  @Test
  public void modelWithOneCollectionFieldShouldValidateGenerics() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("deepClone");
      _builder.newLine();
      _builder.newLine();
      _builder.append("package a.b.c.cloners");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.c.ListWrapper1 ListWrapper1Cloner {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("personNames  // List<String>");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final String code = _builder.toString();
      final Model model = this.parseHelper.parse(code);
      StringConcatenation _builder_1 = new StringConcatenation();
      String _string = _builder_1.toString();
      MyValidationHelper.ValidationResult _validate = this.myValidationHelper.validate(model);
      String _issuesToString = _validate.issuesToString();
      String _trim = _issuesToString.trim();
      Assert.assertEquals(_string, _trim);
      InMemoryFileSystemAccess _inMemoryFileSystemAccess = new InMemoryFileSystemAccess();
      final InMemoryFileSystemAccess fsa = _inMemoryFileSystemAccess;
      Resource _eResource = model.eResource();
      this.generatorDslToJava.doGenerate(_eResource, fsa);
      Map<String,CharSequence> _textFiles = fsa.getTextFiles();
      int _size = _textFiles.size();
      Assert.assertEquals(1, _size);
      final String topClonerJavaFileName = (IFileSystemAccess.DEFAULT_OUTPUT + "a/b/c/cloners/ListWrapper1Cloner.java");
      Map<String,CharSequence> _textFiles_1 = fsa.getTextFiles();
      boolean _containsKey = _textFiles_1.containsKey(topClonerJavaFileName);
      Assert.assertTrue(_containsKey);
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append("package a.b.c.cloners;");
      _builder_2.newLine();
      _builder_2.append("public class ListWrapper1Cloner {");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("public a.b.c.ListWrapper1 apply(a.b.c.ListWrapper1 other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("a.b.c.ListWrapper1 it = new a.b.c.ListWrapper1();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setPersonNames(personNamesCollectionCloner(it.getPersonNames(), other.getPersonNames()));");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("private java.util.List<java.lang.String> personNamesCollectionCloner(java.util.List<java.lang.String> thisCollection, java.util.List<java.lang.String> otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (otherCollection == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (thisCollection == null) thisCollection = new java.util.ArrayList<java.lang.String>();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("for (java.lang.String otherCollectionItem : otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("thisCollection.add(otherCollectionItem);");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return thisCollection;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("}");
      _builder_2.newLine();
      String _string_1 = _builder_2.toString();
      Map<String,CharSequence> _textFiles_2 = fsa.getTextFiles();
      CharSequence _get = _textFiles_2.get(topClonerJavaFileName);
      String _string_2 = _get.toString();
      Assert.assertEquals(_string_1, _string_2);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
 
  @Test
  public void modelWithCollectionTypesWithGenericsShouldValidateAndGenerateLoopsForCollectionTypes1() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("deepClone");
      _builder.newLine();
      _builder.newLine();
      _builder.append("package a.b.c.cloners");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.m2.Book BookCloner789 {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("author");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("sections {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("description");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("-paragraphs");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final String code = _builder.toString();
      final Model model = this.parseHelper.parse(code);
      StringConcatenation _builder_1 = new StringConcatenation();
      String _string = _builder_1.toString();
      MyValidationHelper.ValidationResult _validate = this.myValidationHelper.validate(model);
      String _issuesToString = _validate.issuesToString();
      String _trim = _issuesToString.trim();
      Assert.assertEquals(_string, _trim);
      InMemoryFileSystemAccess _inMemoryFileSystemAccess = new InMemoryFileSystemAccess();
      final InMemoryFileSystemAccess fsa = _inMemoryFileSystemAccess;
      Resource _eResource = model.eResource();
      this.generatorDslToJava.doGenerate(_eResource, fsa);
      Map<String,CharSequence> _textFiles = fsa.getTextFiles();
      int _size = _textFiles.size();
      Assert.assertEquals(1, _size);
      final String topClonerJavaFileName = (IFileSystemAccess.DEFAULT_OUTPUT + "a/b/c/cloners/BookCloner789.java");
      Map<String,CharSequence> _textFiles_1 = fsa.getTextFiles();
      boolean _containsKey = _textFiles_1.containsKey(topClonerJavaFileName);
      Assert.assertTrue(_containsKey);
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append("package a.b.c.cloners;");
      _builder_2.newLine();
      _builder_2.append("public class BookCloner789 {");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("public a.b.m2.Book apply(a.b.m2.Book other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("a.b.m2.Book it = new a.b.m2.Book();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setName(other.getName());");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setAuthor(other.getAuthor());");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setSections(sectionsCollectionCloner(it.getSections(), other.getSections()));");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("private java.util.List<a.b.m2.Section> sectionsCollectionCloner(java.util.List<a.b.m2.Section> thisCollection, java.util.List<a.b.m2.Section> otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (otherCollection == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (thisCollection == null) thisCollection = new java.util.ArrayList<a.b.m2.Section>();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("for (a.b.m2.Section otherCollectionItem : otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("thisCollection.add(sectionsCloner.apply(otherCollectionItem));");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return thisCollection;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("private final SectionsCloner sectionsCloner = new SectionsCloner();");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("public static class SectionsCloner {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("public a.b.m2.Section apply(a.b.m2.Section other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("a.b.m2.Section it = new a.b.m2.Section();");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("it.setName(other.getName());");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("it.setDescription(other.getDescription());");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("}");
      _builder_2.newLine();
      String _string_1 = _builder_2.toString();
      Map<String,CharSequence> _textFiles_2 = fsa.getTextFiles();
      CharSequence _get = _textFiles_2.get(topClonerJavaFileName);
      String _string_2 = _get.toString();
      Assert.assertEquals(_string_1, _string_2);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
 
  @Test
  public void validationShouldDetectMultiple() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("deepClone");
      _builder.newLine();
      _builder.newLine();
      _builder.append("package a.b.c.cloners");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.m2.Book BookCloner987 {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("author");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("sections {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("description");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("paragraphs");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("paragraphs {");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("number");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("text");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final String code = _builder.toString();
      final Model model = this.parseHelper.parse(code);
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("Field paragraphs is declared more then once in container BookCloner987.sections, line: 11, object: SimpleField");
      _builder_1.newLine();
      _builder_1.append("Field paragraphs is declared more then once in container BookCloner987.sections, line: 12, object: ComplexField");
      _builder_1.newLine();
      String _string = _builder_1.toString();
      String _trim = _string.trim();
      MyValidationHelper.ValidationResult _validate = this.myValidationHelper.validate(model);
      String _issuesToString = _validate.issuesToString();
      String _trim_1 = _issuesToString.trim();
      Assert.assertEquals(_trim, _trim_1);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
 
  @Test
  public void modelWithCollectionTypesWithGenericsShouldValidateAndGenerateLoopsForCollectionTypes2() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("deepClone");
      _builder.newLine();
      _builder.newLine();
      _builder.append("package a.b.c.cloners");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.m2.Book BookCloner987 {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("author");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("sections {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("description");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("paragraphs {");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("number");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("text");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final String code = _builder.toString();
      final Model model = this.parseHelper.parse(code);
      StringConcatenation _builder_1 = new StringConcatenation();
      String _string = _builder_1.toString();
      MyValidationHelper.ValidationResult _validate = this.myValidationHelper.validate(model);
      String _issuesToString = _validate.issuesToString();
      String _trim = _issuesToString.trim();
      Assert.assertEquals(_string, _trim);
      InMemoryFileSystemAccess _inMemoryFileSystemAccess = new InMemoryFileSystemAccess();
      final InMemoryFileSystemAccess fsa = _inMemoryFileSystemAccess;
      Resource _eResource = model.eResource();
      this.generatorDslToJava.doGenerate(_eResource, fsa);
      Map<String,CharSequence> _textFiles = fsa.getTextFiles();
      int _size = _textFiles.size();
      Assert.assertEquals(1, _size);
      final String topClonerJavaFileName = (IFileSystemAccess.DEFAULT_OUTPUT + "a/b/c/cloners/BookCloner987.java");
      Map<String,CharSequence> _textFiles_1 = fsa.getTextFiles();
      boolean _containsKey = _textFiles_1.containsKey(topClonerJavaFileName);
      Assert.assertTrue(_containsKey);
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append("package a.b.c.cloners;");
      _builder_2.newLine();
      _builder_2.append("public class BookCloner987 {");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("public a.b.m2.Book apply(a.b.m2.Book other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("a.b.m2.Book it = new a.b.m2.Book();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setName(other.getName());");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setAuthor(other.getAuthor());");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setSections(sectionsCollectionCloner(it.getSections(), other.getSections()));");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("private java.util.List<a.b.m2.Section> sectionsCollectionCloner(java.util.List<a.b.m2.Section> thisCollection, java.util.List<a.b.m2.Section> otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (otherCollection == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (thisCollection == null) thisCollection = new java.util.ArrayList<a.b.m2.Section>();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("for (a.b.m2.Section otherCollectionItem : otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("thisCollection.add(sectionsCloner.apply(otherCollectionItem));");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return thisCollection;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("private final SectionsCloner sectionsCloner = new SectionsCloner();");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("public static class SectionsCloner {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("public a.b.m2.Section apply(a.b.m2.Section other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("a.b.m2.Section it = new a.b.m2.Section();");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("it.setName(other.getName());");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("it.setDescription(other.getDescription());");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("it.setParagraphs(paragraphsCollectionCloner(it.getParagraphs(), other.getParagraphs()));");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("private java.util.Set<a.b.m2.Paragraph> paragraphsCollectionCloner(java.util.Set<a.b.m2.Paragraph> thisCollection, java.util.Set<a.b.m2.Paragraph> otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("if (otherCollection == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("if (thisCollection == null) thisCollection = new java.util.HashSet<a.b.m2.Paragraph>();");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("for (a.b.m2.Paragraph otherCollectionItem : otherCollection) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t\t");
      _builder_2.append("thisCollection.add(paragraphsCloner.apply(otherCollectionItem));");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("return thisCollection;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("private final ParagraphsCloner paragraphsCloner = new ParagraphsCloner();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("public static class ParagraphsCloner {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("public a.b.m2.Paragraph apply(a.b.m2.Paragraph other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t\t\t");
      _builder_2.append("a.b.m2.Paragraph it = new a.b.m2.Paragraph();");
      _builder_2.newLine();
      _builder_2.append("\t\t\t\t");
      _builder_2.append("it.setNumber(other.getNumber());");
      _builder_2.newLine();
      _builder_2.append("\t\t\t\t");
      _builder_2.append("it.setText(other.getText());");
      _builder_2.newLine();
      _builder_2.append("\t\t\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("}");
      _builder_2.newLine();
      String _string_1 = _builder_2.toString();
      Map<String,CharSequence> _textFiles_2 = fsa.getTextFiles();
      CharSequence _get = _textFiles_2.get(topClonerJavaFileName);
      String _string_2 = _get.toString();
      Assert.assertEquals(_string_1, _string_2);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
 
  @Test
  public void modelWithClonerReferences() {
    try {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("deepClone");
      _builder.newLine();
      _builder.newLine();
      _builder.append("package a.b.m");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.m.Book {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("-author");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("&section SectionDeep");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.m.Section SectionDeep {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("description");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("paragraph {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("number");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("text");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("a.b.m.Section SectionReduced {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("name");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("description");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("-paragraph");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      final String code = _builder.toString();
      final Model model = this.parseHelper.parse(code);
      StringConcatenation _builder_1 = new StringConcatenation();
      String _string = _builder_1.toString();
      MyValidationHelper.ValidationResult _validate = this.myValidationHelper.validate(model);
      String _issuesToString = _validate.issuesToString();
      String _trim = _issuesToString.trim();
      Assert.assertEquals(_string, _trim);
      InMemoryFileSystemAccess _inMemoryFileSystemAccess = new InMemoryFileSystemAccess();
      final InMemoryFileSystemAccess fsa = _inMemoryFileSystemAccess;
      Resource _eResource = model.eResource();
      this.generatorDslToJava.doGenerate(_eResource, fsa);
      Map<String,CharSequence> _textFiles = fsa.getTextFiles();
      int _size = _textFiles.size();
      Assert.assertEquals(3, _size);
      final String bookCloner = (IFileSystemAccess.DEFAULT_OUTPUT + "a/b/m/BookCloner.java");
      Map<String,CharSequence> _textFiles_1 = fsa.getTextFiles();
      boolean _containsKey = _textFiles_1.containsKey(bookCloner);
      Assert.assertTrue(_containsKey);
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append("package a.b.m;");
      _builder_2.newLine();
      _builder_2.append("public class BookCloner {");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("public a.b.m.Book apply(a.b.m.Book other) {");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("if (other == null) return null;");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("a.b.m.Book it = new a.b.m.Book();");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setName(other.getName());");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("it.setSection(sectionCloner.apply(other.getSection()));");
      _builder_2.newLine();
      _builder_2.append("\t\t");
      _builder_2.append("return it;");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("}");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.newLine();
      _builder_2.append("\t");
      _builder_2.append("private final a.b.m.SectionDeep sectionCloner = new a.b.m.SectionDeep();");
      _builder_2.newLine();
      _builder_2.append("}");
      _builder_2.newLine();
      String _string_1 = _builder_2.toString();
      Map<String,CharSequence> _textFiles_2 = fsa.getTextFiles();
      CharSequence _get = _textFiles_2.get(bookCloner);
      String _string_2 = _get.toString();
      Assert.assertEquals(_string_1, _string_2);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
}
TOP

Related Classes of my.home.dsl.deepclone.DeepCloneAdvancedGeneratorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.