public final class MockManifest extends java.lang.Object implements FileManifest
FileManifest
that doesn't actually store files on disk.
This manifest is useful for testing SmithyBuildPlugin implementations.
Modifier and Type | Class and Description |
---|---|
static class |
MockManifest.StoreMode
The way in which files are stored.
|
Constructor and Description |
---|
MockManifest()
Creates a mock manifest that stores files in memory and uses a
base directory of "/".
|
MockManifest(java.nio.file.Path baseDir)
Creates a mock manifest that stores files in memory.
|
MockManifest(java.nio.file.Path baseDir,
MockManifest.StoreMode storeMode) |
Modifier and Type | Method and Description |
---|---|
java.nio.file.Path |
addFile(java.nio.file.Path path)
Adds a path to the manifest.
|
byte[] |
expectFileBytes(java.nio.file.Path file)
Expects that the given file was stored and returns the bytes.
|
byte[] |
expectFileBytes(java.lang.String file)
Expects that the given file was stored and returns the bytes.
|
java.lang.String |
expectFileString(java.nio.file.Path file)
Expects that the given file was stored and returns a UTF-8 string.
|
java.lang.String |
expectFileString(java.lang.String file)
Expects that the given file was stored and returns a UTF-8 string.
|
java.nio.file.Path |
getBaseDir()
Gets the base directory of the manifest.
|
java.util.Optional<byte[]> |
getFileBytes(java.nio.file.Path file)
Gets the bytes of a stored file.
|
java.util.Optional<byte[]> |
getFileBytes(java.lang.String file)
Gets the bytes of a stored file.
|
java.util.Set<java.nio.file.Path> |
getFiles()
Gets all of the files in the result.
|
java.util.Optional<java.lang.String> |
getFileString(java.nio.file.Path file)
Gets the contents of a stored file as a String.
|
java.util.Optional<java.lang.String> |
getFileString(java.lang.String file)
Gets the contents of a stored file as a String.
|
java.nio.file.Path |
writeFile(java.nio.file.Path path,
java.io.InputStream fileContentsInputStream)
Adds a file to the result using the contents of an
InputStream . |
java.nio.file.Path |
writeFile(java.nio.file.Path path,
java.io.Reader fileContentsReader)
Adds a file to the result using the contents of a
Reader . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addAllFiles, create, getFilesIn, getFilesIn, hasFile, hasFile, resolvePath, writeFile, writeFile, writeFile, writeFile, writeFile, writeFile, writeJson, writeJson
public MockManifest(java.nio.file.Path baseDir, MockManifest.StoreMode storeMode)
baseDir
- Base directory of the manifest.storeMode
- How files are stored in the mock.public MockManifest(java.nio.file.Path baseDir)
baseDir
- Base directory of the manifest.public MockManifest()
public java.nio.file.Path getBaseDir()
FileManifest
getBaseDir
in interface FileManifest
public java.util.Set<java.nio.file.Path> getFiles()
FileManifest
The order of files returned should be stable across calls.
getFiles
in interface FileManifest
public java.nio.file.Path addFile(java.nio.file.Path path)
FileManifest
The given path must be relative or within the base directory.
addFile
in interface FileManifest
path
- Path to add.public java.nio.file.Path writeFile(java.nio.file.Path path, java.io.Reader fileContentsReader)
FileManifest
Reader
.
This method will write the contents of a Reader to a file.
writeFile
in interface FileManifest
path
- Relative path to the file to create.fileContentsReader
- Reader to consume and write to the file.public java.nio.file.Path writeFile(java.nio.file.Path path, java.io.InputStream fileContentsInputStream)
FileManifest
InputStream
.
This method will write the contents of an input stream to a file.
writeFile
in interface FileManifest
path
- Relative path to the file to create.fileContentsInputStream
- InputStream to consume and write to the file.public java.util.Optional<java.lang.String> getFileString(java.nio.file.Path file)
file
- Relative or absolute path to the file to retrieve.SmithyBuildException
- if the file cannot be read as UTF-8.public java.util.Optional<java.lang.String> getFileString(java.lang.String file)
file
- Relative or absolute path to the file to retrieve.SmithyBuildException
- if the file cannot be read as UTF-8.public java.lang.String expectFileString(java.nio.file.Path file)
file
- File to retrieve.java.nio.file.InvalidPathException
- if the file cannot be found.public java.lang.String expectFileString(java.lang.String file)
file
- File to retrieve.java.nio.file.InvalidPathException
- if the file cannot be found.public java.util.Optional<byte[]> getFileBytes(java.nio.file.Path file)
file
- Relative or absolute path to the file to retrieve.public java.util.Optional<byte[]> getFileBytes(java.lang.String file)
file
- Relative or absolute path to the file to retrieve.public byte[] expectFileBytes(java.nio.file.Path file)
file
- File to retrieve.java.nio.file.InvalidPathException
- if the file cannot be found.public byte[] expectFileBytes(java.lang.String file)
file
- File to retrieve.java.nio.file.InvalidPathException
- if the file cannot be found.