Top Description Fields Constructors Methods
org.eclipse.jgit.junit

public abstract Class RepositoryTestCase

extends LocalDiskRepositoryTestCase
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.junit.Assert.assertEquals

Base class for most JGit unit tests. Sets up a predefined test repository and has support for creating additional repositories and destroying them when the tests are finished.

Field Summary

Modifier and TypeField and Description
protected FileRepository
db

Test repository, initialized for this test case.

protected File
trash

Working directory of db.

Inherited from org.eclipse.jgit.junit.LocalDiskRepositoryTestCase:
ASSUME_UNCHANGEDauthorcommitterCONTENTCONTENT_IDcurrentTestLENGTHmockSystemReaderMOD_TIMErandSMUDGEtestRoot

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
assertEqualsFile(File
expected file
expected
,
File
actual file
actual
)

Assert files are equal

protected boolean

Returns:

if the file exists
check
(String
file name
name
)

Check if file exists

protected static void
checkFile(File
file
f
,
String
expected content
checkData
)

Check content of a file.

protected void
checkoutBranch(String
branch name
branchName
)

Checkout a branch

protected RevCommit

Returns:

the created commit
commitFile
(String
file name
filename
,
String
file content
contents
,
String
branch name
branch
)

Commit a file with the specified contents on the specified branch, creating the branch if it didn't exist before.

protected static void
copyFile(File
file to copy
src
,
File
destination of the copy
dst
)

Copy a file

protected void
createBranch(ObjectId
new value to create the branch on
objectId
,
String
branch name
branchName
)

Create a branch

protected DirCacheEntry

Returns:

the DirCacheEntry
createEntry
(String
file path
path
,
FileMode
file mode
mode
)

Create DirCacheEntry

protected DirCacheEntry

Returns:

the DirCacheEntry
createEntry
(final String
file path
path
,
final FileMode
file mode
mode
,
final String
file content
content
)

Create DirCacheEntry

protected DirCacheEntry

Returns:

the DirCacheEntry
createEntry
(final String
file path
path
,
final FileMode
file mode
mode
,
final int
stage index of the new entry
stage
,
final String
file content
content
)

Create DirCacheEntry

protected void
deleteTrashFile(String
file name
name
)

Delete a trash file

public static Instant

Returns:

return the last measured value of the filesystem timer which is greater than then the lastmodification time of lastfile.
fsTick
(File
the file on which we want to wait until the filesystem timer has advanced more than the lastmodification timestamp of this file
lastFile
)

Waits until it is guaranteed that a subsequent file modification has a younger modification timestamp than the modification timestamp of the given file.

public List<Ref>

Returns:

list of refs
getRefs
()

Get all Refs

public String

Returns:

a string encoding the index state
indexState
(int
a bitmask constructed out of the constants MOD_TIME, SMUDGE, LENGTH, CONTENT_ID and CONTENT controlling which info is present in the resulting string.
includedOptions
)

Represent the state of the index in one String.

public static String

Returns:

a name of that object. Is not guaranteed to be unique. Use nameTemplates containing "%n" to always have unique names
lookup
(Object
the object to lookup
l
,
String
the name for that object. Can contain "%n" which will be replaced by a running number before used as a name. If the lookup table already contains the object this parameter will be ignored
nameTemplate
,
Map<Object, String>
a table storing object-name mappings.
lookupTable
)

Helper method to map arbitrary objects to user-defined names.

protected String

Returns:

the file's content
read
(String
file name
name
)

Read content of a file

protected void
resetIndex(FileTreeIterator
a org.eclipse.jgit.treewalk.FileTreeIterator which determines which files should go into the new index
treeItr
)

Resets the index to represent exactly some filesystem content.

public void
public static String

Returns:

the resulting string with slashes
slashify
(String
the string in which backslashes should be replaced
str
)

Replaces '\' by '/'

public void
protected File

Returns:

the trash file
writeTrashFile
(String
file name
name
,
String
file content
data
)

Write a trash file

protected File

Returns:

the trash file
writeTrashFile
(final String
in working tree
subdir
,
final String
file name
name
,
final String
file content
data
)

Write a trash file

protected File

Returns:

the File object associated to the last written file.
writeTrashFiles
(boolean
if set to true then between two write operations this method will wait to ensure that the second file will get a different lastmodification timestamp than the first file.
ensureDistinctTimestamps
,
String...
the contents which should be written into the files
contents
)

Writes a number of files in the working tree.

Inherited from org.eclipse.jgit.junit.LocalDiskRepositoryTestCase:
addRepoToClosecreateBareRepositorycreateRepositorycreateRepositorycreateTempDirectorycreateTempFilecreateUniqueTestGitDircreateWorkRepositorygetCeilingsgetTemporaryDirectoryindexStatereadrecursiveDeleterunHooktickwritewrite

Field Detail

dbback to summary
protected FileRepository db

Test repository, initialized for this test case.

trashback to summary
protected File trash

Working directory of db.

Constructor Detail

RepositoryTestCaseback to summary
public RepositoryTestCase()

Method Detail

assertEqualsFileback to summary
public static void assertEqualsFile(File expected, File actual) throws IOException

Assert files are equal

Parameters
expected:File

expected file

actual:File

actual file

Exceptions
IOException:
if an IO error occurred
checkback to summary
protected boolean check(String name)

Check if file exists

Parameters
name:String

file name

Returns:boolean

if the file exists

checkFileback to summary
protected static void checkFile(File f, String checkData) throws IOException

Check content of a file.

Parameters
f:File

file

checkData:String

expected content

Exceptions
IOException:
if an IO error occurred
checkoutBranchback to summary
protected void checkoutBranch(String branchName) throws IOException

Checkout a branch

Parameters
branchName:String

branch name

Exceptions
IOException:
if an IO error occurred
commitFileback to summary
protected RevCommit commitFile(String filename, String contents, String branch)

Commit a file with the specified contents on the specified branch, creating the branch if it didn't exist before.

It switches back to the original branch after the commit if there was one.

Parameters
filename:String

file name

contents:String

file content

branch:String

branch name

Returns:RevCommit

the created commit

copyFileback to summary
protected static void copyFile(File src, File dst) throws IOException

Copy a file

Parameters
src:File

file to copy

dst:File

destination of the copy

Exceptions
IOException:
if an IO error occurred
createBranchback to summary
protected void createBranch(ObjectId objectId, String branchName) throws IOException

Create a branch

Parameters
objectId:ObjectId

new value to create the branch on

branchName:String

branch name

Exceptions
IOException:
if an IO error occurred
createEntryback to summary
protected DirCacheEntry createEntry(String path, FileMode mode)

Create DirCacheEntry

Parameters
path:String

file path

mode:FileMode

file mode

Returns:DirCacheEntry

the DirCacheEntry

createEntryback to summary
protected DirCacheEntry createEntry(final String path, final FileMode mode, final String content)

Create DirCacheEntry

Parameters
path:String

file path

mode:FileMode

file mode

content:String

file content

Returns:DirCacheEntry

the DirCacheEntry

createEntryback to summary
protected DirCacheEntry createEntry(final String path, final FileMode mode, final int stage, final String content)

Create DirCacheEntry

Parameters
path:String

file path

mode:FileMode

file mode

stage:int

stage index of the new entry

content:String

file content

Returns:DirCacheEntry

the DirCacheEntry

deleteTrashFileback to summary
protected void deleteTrashFile(String name) throws IOException

Delete a trash file

Parameters
name:String

file name

Exceptions
IOException:
if an IO error occurred
fsTickback to summary
public static Instant fsTick(File lastFile) throws InterruptedException, IOException

Waits until it is guaranteed that a subsequent file modification has a younger modification timestamp than the modification timestamp of the given file. This is done by touching a temporary file, reading the lastmodified attribute and, if needed, sleeping. After sleeping this loop starts again until the filesystem timer has advanced enough. The temporary file will be created as a sibling of lastFile.

Parameters
lastFile:File

the file on which we want to wait until the filesystem timer has advanced more than the lastmodification timestamp of this file

Returns:Instant

return the last measured value of the filesystem timer which is greater than then the lastmodification time of lastfile.

Exceptions
InterruptedException:
if thread was interrupted
IOException:
if an IO error occurred
Since
5.1.9
getRefsback to summary
public List<Ref> getRefs() throws IOException

Get all Refs

Returns:List<Ref>

list of refs

Exceptions
IOException:
if an IO error occurred
indexStateback to summary
public String indexState(int includedOptions) throws IOException

Represent the state of the index in one String. This representation is useful when writing tests which do assertions on the state of the index. By default information about path, mode, stage (if different from 0) is included. A bitmask controls which additional info about modificationTimes, smudge state and length is included.

The format of the returned string is described with this BNF:

result = ( "[" path mode stage? time? smudge? length? sha1? content? "]" )* .
mode = ", mode:" number .
stage = ", stage:" number .
time = ", time:t" timestamp-index .
smudge = "" | ", smudged" .
length = ", length:" number .
sha1 = ", sha1:" hex-sha1 .
content = ", content:" blob-data .
'stage' is only presented when the stage is different from 0. All reported time stamps are mapped to strings like "t0", "t1", ... "tn". The smallest reported time-stamp will be called "t0". This allows to write assertions against the string although the concrete value of the time stamps is unknown.
Parameters
includedOptions:int

a bitmask constructed out of the constants MOD_TIME, SMUDGE, LENGTH, CONTENT_ID and CONTENT controlling which info is present in the resulting string.

Returns:String

a string encoding the index state

Exceptions
IOException:
if an IO error occurred
lookupback to summary
public static String lookup(Object l, String nameTemplate, Map<Object, String> lookupTable)

Helper method to map arbitrary objects to user-defined names. This can be used create short names for objects to produce small and stable debug output. It is guaranteed that when you lookup the same object multiple times even with different nameTemplates this method will always return the same name which was derived from the first nameTemplate. nameTemplates can contain "%n" which will be replaced by a running number before used as a name.

Parameters
l:Object

the object to lookup

nameTemplate:String

the name for that object. Can contain "%n" which will be replaced by a running number before used as a name. If the lookup table already contains the object this parameter will be ignored

lookupTable:Map<Object, String>

a table storing object-name mappings.

Returns:String

a name of that object. Is not guaranteed to be unique. Use nameTemplates containing "%n" to always have unique names

readback to summary
protected String read(String name) throws IOException

Read content of a file

Parameters
name:String

file name

Returns:String

the file's content

Exceptions
IOException:
if an IO error occurred
resetIndexback to summary
protected void resetIndex(FileTreeIterator treeItr) throws FileNotFoundException, IOException

Resets the index to represent exactly some filesystem content. E.g. the following call will replace the index with the working tree content:

resetIndex(new FileSystemIterator(db))

This method can be used by testcases which first prepare a new commit somewhere in the filesystem (e.g. in the working-tree) and then want to have an index which matches their prepared content.

Parameters
treeItr:FileTreeIterator

a org.eclipse.jgit.treewalk.FileTreeIterator which determines which files should go into the new index

Exceptions
FileNotFoundException:
file was not found
IOException:
if an IO error occurred
setUpback to summary
public void setUp() throws Exception

Overrides org.eclipse.jgit.junit.LocalDiskRepositoryTestCase.setUp.

Doc from org.eclipse.jgit.junit.LocalDiskRepositoryTestCase.setUp.

Setup test

Annotations
@Override
@Before
Exceptions
Exception:
if an error occurred
slashifyback to summary
public static String slashify(String str)

Replaces '\' by '/'

Parameters
str:String

the string in which backslashes should be replaced

Returns:String

the resulting string with slashes

Since
4.2
tearDownback to summary
public void tearDown() throws Exception

Overrides org.eclipse.jgit.junit.LocalDiskRepositoryTestCase.tearDown.

Doc from org.eclipse.jgit.junit.LocalDiskRepositoryTestCase.tearDown.

Tear down the test

Annotations
@Override
@After
Exceptions
Exception:
if an error occurred
writeTrashFileback to summary
protected File writeTrashFile(String name, String data) throws IOException

Write a trash file

Parameters
name:String

file name

data:String

file content

Returns:File

the trash file

Exceptions
IOException:
if an IO error occurred
writeTrashFileback to summary
protected File writeTrashFile(final String subdir, final String name, final String data) throws IOException

Write a trash file

Parameters
subdir:String

in working tree

name:String

file name

data:String

file content

Returns:File

the trash file

Exceptions
IOException:
if an IO error occurred
writeTrashFilesback to summary
protected File writeTrashFiles(boolean ensureDistinctTimestamps, String... contents) throws IOException, InterruptedException

Writes a number of files in the working tree. The first content specified will be written into a file named '0', the second into a file named "1" and so on. If null is specified as content then this file is skipped.

Parameters
ensureDistinctTimestamps:boolean

if set to true then between two write operations this method will wait to ensure that the second file will get a different lastmodification timestamp than the first file.

contents:String[]

the contents which should be written into the files

Returns:File

the File object associated to the last written file.

Exceptions
IOException:
if an IO error occurred
InterruptedException:
if thread was interrupted