Пример #1
0
 private void saveModel(File f) {
   if (debugTest) System.out.println("Saving model into " + f.getAbsolutePath());
   File modelFile = new File(modelFilename);
   try {
     FileUtil.copyFile(modelFile, f);
   } catch (IOException ioe) {
     ioe.printStackTrace();
     fail("Couldn't copy file to " + f.toString());
   }
 }
  /**
   * Tests that the UnwovenClassFiles corresponding to classes on the inpath have the correct class
   * name when there is no output directory (ultimately tests
   * AjState.createUnwovenClassFile(BinarySourceFile) and ensures the unwovenClassFile has the
   * correct name. Makes a change to a class file on the inpath to ensure we enter this method
   * (there is a check that says are we the first build))
   */
  public void testPathResolutionAfterChangeInClassOnInpath() throws Exception {
    String inpathDir = inpathTestingDir + File.separator + "injarBin" + File.separator + "pkg";
    addInpathEntry(inpathDir);
    build("inpathTesting");

    // build again so that we enter
    // AjState.createUnwovenClassFile(BinarySourceFile)
    File from =
        new File(
            testdataSrcDir
                + File.separatorChar
                + "inpathTesting"
                + File.separatorChar
                + "newInpathClass"
                + File.separatorChar
                + "InpathClass.class");
    File destination = new File(inpathDir + File.separatorChar + "InpathClass.class");
    FileUtil.copyFile(from, destination);

    // get hold of the state for this project - expect to find one
    AjState state = getState();
    AjBuildConfig buildConfig = state.getBuildConfig();
    state.prepareForNextBuild(buildConfig);

    Map binarySources = state.getBinaryFilesToCompile(true);
    assertFalse(
        "expected there to be binary sources from the inpath setting but didn't find any",
        binarySources.isEmpty());

    List unwovenClassFiles =
        (List) binarySources.get(inpathDir + File.separator + "InpathClass.class");
    List fileNames = new ArrayList();
    // the unwovenClassFiles should have filenames that point to the output dir
    // (which in this case is the sandbox dir) and not where they came from.
    for (Iterator iterator = unwovenClassFiles.iterator(); iterator.hasNext(); ) {
      UnwovenClassFile ucf = (UnwovenClassFile) iterator.next();
      if (ucf.getFilename().indexOf(expectedOutputDir) == -1) {
        fileNames.add(ucf.getFilename());
      }
    }
    assertTrue(
        "expected to find UnwovenClassFile from directory\n"
            + expectedOutputDir
            + ", \n but found files "
            + fileNames,
        fileNames.isEmpty());
  }