Explain and test rename/copy behavior of test API of changes

The test API of changes already supported the creation of renames
and copies in various flavors as proven by the added tests. It's not
always straight-forward, though. How to achieve some of the more special
states is explained in the new Javadoc descriptions.

We could of course add more fluent builder functions for special
situations like renames with modified content or copies. However, those
situations are more tricky to generate as they are dependent on some
other factors (e.g. new content must be at least 60% similar to old
one) which might not be possible to enforce in the API. In addition,
we'd need to apply special care to make other factors explicit (e.g.
copy must happen at the same time as a rename), which might not be easy
to express in the API.

Change-Id: I8a9ecc8a911bddbcb932f84de2b3ab068bc58df5
This commit is contained in:
Alice Kober-Sotzek
2020-08-13 14:53:50 +02:00
parent 6724617e25
commit e8c2d19c0e
2 changed files with 150 additions and 0 deletions

View File

@@ -48,11 +48,28 @@ public class FileContentBuilder<T> {
return builder;
}
/** Deletes the file. */
public T delete() {
modificationToBuilderAdder.accept(new DeleteFileModification(filePath));
return builder;
}
/**
* Renames the file while keeping its content.
*
* <p>If you want to both rename the file and adjust its content, delete the old path via {@link
* #delete()} and provide the desired content for the new path via {@link #content(String)}. If
* you use that approach, make sure to use a new content which is similar enough to the old (at
* least 60% line similarity) as otherwise Gerrit/Git won't identify it as a rename.
*
* <p>To create copied files, you need to go even one step further. Also rename the file you copy
* at the same time (-> delete old path + add two paths with the old content)! If you also want to
* adjust the content of the copy, you need to also slightly modify the content of the renamed
* file. Adjust the content of the copy slightly more if you want to control which file ends up as
* copy and which as rename (but keep the 60% line similarity threshold in mind).
*
* @param newFilePath new path of the file
*/
public T renameTo(String newFilePath) {
modificationToBuilderAdder.accept(new RenameFileModification(filePath, newFilePath));
return builder;