Package org.junithelper.core.generator

Examples of org.junithelper.core.generator.TestCaseGenerator


                String encoding = UniversalDetectorUtil.getDetectedEncoding(EclipseIFileUtil
                        .getInputStreamFrom(targetClassFile));
                InputStream targetInputStream = EclipseIFileUtil.getInputStreamFrom(targetClassFile);
                String sourceCodeString = IOUtil.readAsString(targetInputStream, encoding);
                LineBreakProvider lineBreakProvider = new LineBreakProvider(config, null);
                TestCaseGenerator generator = TestCaseGeneratorFactory.create(config, lineBreakProvider);
                generator.initialize(new ClassMetaExtractor(config).extract(sourceCodeString));

                // ---------------
                // write test case
                outputStream = new FileOutputStream(testCaseCreateDirPath + StringValue.DirectorySeparator.General
                        + testCaseFileName);
                writer = new OutputStreamWriter(outputStream, getDetectedEncodingFrom(targetClassFile,
                        config.outputFileEncoding));
                writer.write(generator.getNewTestCaseSourceCode());

            } catch (InvalidPreferenceException ipe) {
                ipe.printStackTrace();
                openWarning(props, props.get(Dialog.Common.invalidPreference));
                return;
View Full Code Here


                            .getInputStreamFrom(testCaseFile));
                    String currentTestCodeString = IOUtil.readAsString(EclipseIFileUtil
                            .getInputStreamFrom(testCaseFile), testCaseFileEncoding);
                    CurrentLineBreak currentLineBreak = CurrentLineBreakDetector.detect(currentTestCodeString);
                    LineBreakProvider lineBreakProvider = new LineBreakProvider(config, currentLineBreak);
                    TestCaseGenerator generator = TestCaseGeneratorFactory.create(config, lineBreakProvider);
                    String newTestCodeString = generator.initialize(targetClassMeta)
                            .getTestCaseSourceCodeWithLackingTestMethod(currentTestCodeString);

                    // ----------------------------------------
                    // write file
                    OutputStreamWriter writer = null;
View Full Code Here

    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    FileReader fileReader = new CommonsIOFileReader();
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    for (File javaFile : javaFiles) {
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile.getAbsolutePath()
            .replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config))
            .replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator.getTestCaseSourceCodeWithLackingTestMethod(
            currentTestCaseSourceCode);
        if (!testCodeString.equals(currentTestCaseSourceCode)) {
          Stdout.p("  Modified: " + testFile.getAbsolutePath());
          new CommonsIOFileWriter(testFile).writeText(testCodeString);
        }
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
        Stdout.p("  Created: " + testFile.getAbsolutePath());
        new CommonsIOFileWriter(testFile).writeText(testCodeString);
      }
    }
  }
View Full Code Here

    }
    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    FileReader fileReader = new CommonsIOFileReader();
    for (File javaFile : javaFiles) {
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile.getAbsolutePath().replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config))
            .replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator.getUnifiedVersionTestCaseSourceCode(
            testCaseGenerator.getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode),
            JUnitVersion.version4);
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
      }
      new CommonsIOFileWriter(testFile).writeText(testCodeString);
      Stdout.p("  Forced JUnit 4.x: " + testFile.getAbsolutePath());
    }
  }
View Full Code Here

    }
    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    FileReader fileReader = new CommonsIOFileReader();
    for (File javaFile : javaFiles) {
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile.getAbsolutePath().replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config))
            .replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator.getUnifiedVersionTestCaseSourceCode(
            testCaseGenerator.getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode),
            JUnitVersion.version3);
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
      }
      new CommonsIOFileWriter(testFile).writeText(testCodeString);
      Stdout.p("  Forced JUnit 3.x: " + testFile.getAbsolutePath());
    }
  }
View Full Code Here

    }
    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    FileReader fileReader = new CommonsIOFileReader();
    for (File javaFile : javaFiles) {
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile.getAbsolutePath().replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config))
            .replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator.getUnifiedVersionTestCaseSourceCode(
            testCaseGenerator.getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode),
            JUnitVersion.version4);
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
      }
      new CommonsIOFileWriter(testFile).writeText(testCodeString);
      Stdout.p("  Forced JUnit 4.x: " + testFile.getAbsolutePath());
    }
  }
View Full Code Here

    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    FileReader fileReader = new CommonsIOFileReader();
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    for (File javaFile : javaFiles) {
      if (isNeedToExclude(javaFile)) {
        continue;
      }
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile
            .getAbsolutePath()
            .replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config)).replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator
            .getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode);
        if (!testCodeString.equals(currentTestCaseSourceCode)) {
          Stdout.p("  Modified: " + testFile.getAbsolutePath());
          new CommonsIOFileWriter(testFile).writeText(testCodeString);
        }
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
        Stdout.p("  Created: " + testFile.getAbsolutePath());
        new CommonsIOFileWriter(testFile).writeText(testCodeString);
      }
    }
  }
View Full Code Here

    }
    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    FileReader fileReader = new CommonsIOFileReader();
    for (File javaFile : javaFiles) {
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile.getAbsolutePath().replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config))
            .replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator.getUnifiedVersionTestCaseSourceCode(
            testCaseGenerator.getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode),
            JUnitVersion.version3);
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
      }
      new CommonsIOFileWriter(testFile).writeText(testCodeString);
      Stdout.p("  Forced JUnit 3.x: " + testFile.getAbsolutePath());
    }
  }
View Full Code Here

    // confirm input from stdin
    if (confirmToExecute() > 0) {
      return;
    }
    FileReader fileReader = new CommonsIOFileReader();
    TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
    for (File javaFile : javaFiles) {
      if (isNeedToExclude(javaFile)) {
        continue;
      }
      File testFile = null;
      String currentTestCaseSourceCode = null;
      try {
        testFile = new File(javaFile
            .getAbsolutePath()
            .replaceAll("\\\\", "/")
            .replaceFirst(getDirectoryPathOfProductSourceCode(config),
                getDirectoryPathOfTestSourceCode(config)).replaceFirst("\\.java", "Test.java"));
        currentTestCaseSourceCode = fileReader.readAsString(testFile);
      } catch (Exception e) {
      }
      testCaseGenerator.initialize(fileReader.readAsString(javaFile));
      String testCodeString = null;
      if (currentTestCaseSourceCode != null) {
        testCodeString = testCaseGenerator
            .getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode);
        if (!testCodeString.equals(currentTestCaseSourceCode)) {
          Stdout.p("  Modified: " + testFile.getAbsolutePath());
          new CommonsIOFileWriter(testFile).writeText(testCodeString);
        }
      } else {
        testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
        Stdout.p("  Created: " + testFile.getAbsolutePath());
        new CommonsIOFileWriter(testFile).writeText(testCodeString);
      }
    }
  }
View Full Code Here

                currentTestCaseSourceCode = fileReader.readAsString(testFile);
            } catch (Exception e) {
            }
            CurrentLineBreak currentLineBreak = CurrentLineBreakDetector.detect(currentTestCaseSourceCode);
            LineBreakProvider lineBreakProvider = new LineBreakProvider(config, currentLineBreak);
            TestCaseGenerator testCaseGenerator = TestCaseGeneratorFactory.create(config, lineBreakProvider);

            String targetSourceCodeString = fileReader.readAsString(javaFile);
            testCaseGenerator.initialize(targetSourceCodeString);
            String testCodeString = null;
            if (currentTestCaseSourceCode != null) {
                testCodeString = testCaseGenerator.getUnifiedVersionTestCaseSourceCode(testCaseGenerator
                        .getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode), JUnitVersion.version4);
            } else {
                testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
            }
            testCodeString = standardizeLineBreak(config, testCodeString);
            FileWriterFactory.create(testFile).writeText(testCodeString);
            Stdout.p("  Forced JUnit 4.x: " + testFile.getAbsolutePath());
        }
View Full Code Here

TOP

Related Classes of org.junithelper.core.generator.TestCaseGenerator

Copyright © 2018 www.massapicom. 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.