/*************************GO-LICENSE-START*********************************
 * Copyright 2014 ThoughtWorks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *************************GO-LICENSE-END***********************************/

package com.thoughtworks.go.domain.materials.tfs;

import java.io.File;

import com.thoughtworks.go.util.TempFiles;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class WorkingFolderTest {

    @Test
    public void shouldAlwaysMatchLocalDirToTheCanonicalPathOfTheGivenFile() throws Exception {
        TempFiles tempFiles = new TempFiles();
        File parent = tempFiles.createUniqueFolder("parent");
        File child = new File(parent.getAbsolutePath() + "/child");
        child.mkdir();
        File grandchild = new File(child.getAbsolutePath() + "/grandchild");
        grandchild.mkdir();

        WorkingFolder workingFolder = new WorkingFolder("$/helloworld", grandchild.getAbsolutePath());
        assertThat(workingFolder.matchesLocalDir(new File(child.getAbsolutePath() + "/../child/grandchild")), is(true));
        tempFiles.cleanUp();
    }
}

@@ -796,30 +796,8 @@
 s;%0A%0A
-import java.io.File;%0A%0A
 impo
@@ -852,20 +852,91 @@
 g.junit.
-Test
+After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.io.File
 ;%0A%0Aimpor
@@ -1045,16 +1045,241 @@
 erTest %7B
+%0A    private TempFiles tempFiles;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        tempFiles = new TempFiles();%0A    %7D%0A%0A    @After%0A    public void tearDown() throws Exception %7B%0A        tempFiles.cleanUp();%0A    %7D
 %0A%0A    @T
@@ -1381,55 +1381,8 @@
 n %7B%0A
-        TempFiles tempFiles = new TempFiles();%0A
     
@@ -1718,32 +1718,33 @@
 andchild.get
-Absolute
+Canonical
 Path());%0A   
@@ -1752,49 +1752,26 @@
     
-assertThat(workingFolder.matchesLocalDir(
+File grandChild = 
 new 
@@ -1828,48 +1828,171 @@
 ld%22)
-), is(true));%0A        tempFiles.cleanUp(
+;%0A        assertThat(%22Working folder (%22 + workingFolder + %22) does not match: %22 + grandChild.getCanonicalPath(), workingFolder.matchesLocalDir(grandChild), is(true)
 );%0A 

Fix failing WorkingFolderTest