package com.mysema.maven.apt;

import java.io.File;
import java.io.IOException;

import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.io.Files;
import org.junit.Test;
import static org.junit.Assert.*;

public class FileSyncTest {

    @Test
    public void sync1() throws IOException {
        File source = Files.createTempDir();
        File sourceFile = new File(source, "inSource");
        sourceFile.createNewFile();
        File sourceFolder = new File(source, "inSourceFolder");
        sourceFolder.mkdir();
        File sourceFile2 = new File(sourceFolder, "inSource");
        sourceFile2.createNewFile();

        File target = Files.createTempDir();
        File targetFile = new File(target, "inTarget");
        targetFile.createNewFile();

        FileSync.syncFiles(source, target);
        assertTrue(new File(target, "inSource").exists());
        assertTrue(new File(target, "inSourceFolder" + File.separator + "inSource").exists());
        assertFalse(targetFile.exists());

        FileSync.syncFiles(source, target);
    }

    @Test
    public void sync2() throws IOException {
        File source = Files.createTempDir();
        File sourceFile = new File(source, "file");
        Files.write("abc", sourceFile, Charsets.UTF_8);
        File target = Files.createTempDir();
        File targetFile = new File(target, "file");
        Files.write("abc", targetFile, Charsets.UTF_8);
        long modified = targetFile.lastModified();

        FileSync.syncFiles(source, target);
        assertEquals(modified, targetFile.lastModified());
    }

    @Test
    public void sync3() throws IOException {
        Joiner joiner = Joiner.on(File.separator);
        File source = Files.createTempDir();
        File target = Files.createTempDir();
        File sourceFile1 = new File(source, joiner.join("com","mysema","querydsl","Query.java"));
        File sourceFile2 = new File(source, joiner.join("com","mysema","Entity.java"));
        File targetFile1 = new File(target, joiner.join("com","mysema","querydsl","OldQuery.java"));
        File targetFile2 = new File(target, joiner.join("com","mysema","querydsl","support","Example.java"));
        sourceFile1.getParentFile().mkdirs();
        sourceFile2.getParentFile().mkdirs();
        targetFile1.getParentFile().mkdirs();
        targetFile2.getParentFile().mkdirs();
        Files.write("abc", sourceFile1, Charsets.UTF_8);
        Files.write("def", sourceFile2, Charsets.UTF_8);
        Files.write("ghi", targetFile1, Charsets.UTF_8);
        Files.write("jkl", targetFile2, Charsets.UTF_8);

        FileSync.syncFiles(source, target);
        assertFalse(targetFile1.exists());
        assertFalse(targetFile2.exists());
        assertFalse(targetFile2.getParentFile().exists());
        assertTrue(new File(target, joiner.join("com","mysema","querydsl","Query.java")).exists());
        assertTrue(new File(target, joiner.join("com","mysema","Entity.java")).exists());
    }

}

@@ -72,16 +72,44 @@
 ception;
+%0Aimport java.nio.file.Paths;
 %0A%0Aimport
@@ -146,46 +146,8 @@
 ts;%0A
-import com.google.common.base.Joiner;%0A
 impo
@@ -1663,59 +1663,8 @@
 n %7B%0A
-        Joiner joiner = Joiner.on(File.separator);%0A
     
@@ -1780,37 +1780,44 @@
 1 = 
-new File(source, joiner.join(
+Paths.get(source.getAbsolutePath(), 
 %22com
@@ -1843,32 +1843,40 @@
 l%22,%22Query.java%22)
+.toFile(
 );%0A        File 
@@ -1893,37 +1893,44 @@
 2 = 
-new File(source, joiner.join(
+Paths.get(source.getAbsolutePath(), 
 %22com
@@ -1946,32 +1946,40 @@
 %22,%22Entity.java%22)
+.toFile(
 );%0A        File 
@@ -1996,37 +1996,44 @@
 1 = 
-new File(target, joiner.join(
+Paths.get(target.getAbsolutePath(), 
 %22com
@@ -2066,24 +2066,32 @@
 Query.java%22)
+.toFile(
 );%0A        F
@@ -2112,37 +2112,44 @@
 2 = 
-new File(target, joiner.join(
+Paths.get(target.getAbsolutePath(), 
 %22com
@@ -2195,16 +2195,24 @@
 e.java%22)
+.toFile(
 );%0A     
@@ -2831,37 +2831,44 @@
 rue(
-new File(target, joiner.join(
+Paths.get(target.getAbsolutePath(), 
 %22com
@@ -2894,32 +2894,40 @@
 l%22,%22Query.java%22)
+.toFile(
 ).exists());%0A   
@@ -2946,37 +2946,44 @@
 rue(
-new File(target, joiner.join(
+Paths.get(target.getAbsolutePath(), 
 %22com
@@ -3007,16 +3007,24 @@
 y.java%22)
+.toFile(
 ).exists

Use Paths for file path construction