Skip to content

Instantly share code, notes, and snippets.

@karadaisy
Created May 20, 2013 16:53
Show Gist options
  • Select an option

  • Save karadaisy/5613537 to your computer and use it in GitHub Desktop.

Select an option

Save karadaisy/5613537 to your computer and use it in GitHub Desktop.
Testing gradle duplicate handling behavior
package org.gradle.api.internal.file.copy
import org.gradle.api.Project
import org.gradle.api.file.FileTree
import org.gradle.api.file.FileVisitDetails
import org.gradle.api.file.RelativePath
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Shared
import spock.lang.Specification
class DuplicateHandlingCopySpecVisitorTest extends Specification {
@Shared Project project = new ProjectBuilder().build()
FileCopySpecVisitor delegate = Mock()
org.gradle.internal.nativeplatform.filesystem.FileSystem fileSystem = Mock()
ReadableCopySpec copySpec = Mock()
FileTree fileTree = Mock()
def visitor = new MappingCopySpecVisitor(
new DuplicateHandlingCopySpecVisitor(delegate), fileSystem)
def duplicatesIncludedByDefaultInZipAndTar() {
FileVisitDetails file1 = Mock()
FileVisitDetails file2 = Mock()
FileVisitDetails file3 = Mock()
given:
file1.relativePath >> new RelativePath(true, 'path/file1.txt')
file2.relativePath >> new RelativePath(true, 'path/file2.txt')
file3.relativePath >> new RelativePath(true, 'path/file1.txt')
fileTree.files >> [ file1, file2, file3 ]
copySpec.destPath >> new RelativePath(false, '/root')
copySpec.allCopyActions >> []
copySpec.source >> fileTree
when:
visitor.visitSpec(copySpec)
fileTree.files.each { visitor.visitFile it }
then:
1 * delegate.visitSpec(copySpec)
1 * delegate.visitFile({ it.relativePath.pathString == '/root/path/file1.txt' })
1 * delegate.visitFile({ it.relativePath.pathString == '/root/path/file2.txt' })
1 * delegate.visitFile({ it.relativePath.pathString == '/root/path/file1.txt' })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment