SourceForge.net Logo

Create It

The entry point for Cotta is the TFileFactory:

// find src directory under current directory TDirectory src = new TFileFactory().dir(“src”) // find buildnumber file TFile file = src.file(”./buildnumber”);

Use It

You can do all the normal operations on TDirectory and TFile, including loading the file content:

public void increaseBuildNumber(TFile file) { String content = file.load(); // Increase the build number // (Let’s not get into the business of error handling for now) int buildnumber = Integer.parseInt(content); file.save(String.valueOf(buildnumber++)); }

Test It

You can test the code above, without any hassle or fear of touching your physical file system:

public void testShouldIncreaseBuildNumberInFile() throws Exception { TFileFactory factory = new TFileFactory(new InMemoryFileSystem()); TFile file = factory.file(”./src/buildmaster”); file.save(“3”); ... buildnumber.increaseBuildNumber(file); assert_equals(“4”, file.load()); }

More

Like it, want more? It is all in the Cotta Document