mirror of
https://github.com/google/nomulus.git
synced 2025-07-24 03:30:46 +02:00
Clean up test "load resources" methods and classes
There is a big mix of different "load Resources" from different libraries depending on where you were and what type of resource you want. Now there is a clear hirarchy: ResourceUtils: for use in actual (non-test) code, reads a file from a context directory TestDataHelper (uses ResourceUtils): for use in tests, reads a file from a context directory + "/testdata". Also caches the resource so calling it multiple times with the same file will not read the file multiple times. Library specific helpers (e.g. ToolsTestData) (uses TestDataHelper): for use in that library's tests only, reads from a specific testdata directory. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177027533
This commit is contained in:
parent
bbe2584da4
commit
95647528b8
12 changed files with 66 additions and 75 deletions
|
@ -16,10 +16,9 @@ package google.registry.tmch;
|
|||
|
||||
import static com.google.common.base.CharMatcher.whitespace;
|
||||
import static com.google.common.io.BaseEncoding.base64;
|
||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
import google.registry.testing.TestDataHelper;
|
||||
|
||||
/** Utility class providing easy access to contents of the {@code testdata/} directory. */
|
||||
public final class TmchTestData {
|
||||
|
@ -29,12 +28,12 @@ public final class TmchTestData {
|
|||
|
||||
/** Returns {@link ByteSource} for file in {@code tmch/testdata/} directory. */
|
||||
public static ByteSource loadBytes(String filename) {
|
||||
return readResourceBytes(TmchTestData.class, "testdata/" + filename);
|
||||
return TestDataHelper.loadBytes(TmchTestData.class, filename);
|
||||
}
|
||||
|
||||
/** Loads data from file in {@code tmch/testdata/} as a String. */
|
||||
public static String loadString(String filename) {
|
||||
return readResourceUtf8(TmchTestData.class, "testdata/" + filename);
|
||||
return TestDataHelper.loadFile(TmchTestData.class, filename);
|
||||
}
|
||||
|
||||
/** Extracts SMD XML from an ASCII-armored file. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue