@ -72,7 +72,6 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
. findGitDir ( d ) . getGitDir ( ) ) ;
}
@SuppressWarnings ( "unused" )
@Test
public void emptyRepositoryFormatVersion ( ) throws Exception {
Repository r = createWorkRepository ( ) ;
@ -81,10 +80,11 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
ConfigConstants . CONFIG_KEY_REPO_FORMAT_VERSION , "" ) ;
config . save ( ) ;
new FileRepository ( r . getDirectory ( ) ) ;
try ( FileRepository repo = new FileRepository ( r . getDirectory ( ) ) ) {
// Unused
}
}
@SuppressWarnings ( "unused" )
@Test
public void invalidRepositoryFormatVersion ( ) throws Exception {
Repository r = createWorkRepository ( ) ;
@ -93,15 +93,13 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
ConfigConstants . CONFIG_KEY_REPO_FORMAT_VERSION , "notanumber" ) ;
config . save ( ) ;
try {
new FileRepository ( r . getDirectory ( ) ) ;
try ( FileRepository repo = new FileRepository ( r . getDirectory ( ) ) ) {
fail ( "IllegalArgumentException not thrown" ) ;
} catch ( IllegalArgumentException e ) {
assertNotNull ( e . getMessage ( ) ) ;
}
}
@SuppressWarnings ( "unused" )
@Test
public void unknownRepositoryFormatVersion ( ) throws Exception {
Repository r = createWorkRepository ( ) ;
@ -110,22 +108,20 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
ConfigConstants . CONFIG_KEY_REPO_FORMAT_VERSION , 999999 ) ;
config . save ( ) ;
try {
new FileRepository ( r . getDirectory ( ) ) ;
try ( FileRepository repo = new FileRepository ( r . getDirectory ( ) ) ) {
fail ( "IOException not thrown" ) ;
} catch ( IOException e ) {
assertNotNull ( e . getMessage ( ) ) ;
}
}
@SuppressWarnings ( "resource" /* java 7 */ )
@Test
public void absoluteGitDirRef ( ) throws Exception {
Repository repo1 = createWorkRepository ( ) ;
File dir = createTempDirectory ( "dir" ) ;
File dotGit = new File ( dir , Constants . DOT_GIT ) ;
new FileWriter ( dotGit ) . append (
"gitdir: " + repo1 . getDirectory ( ) . getAbsolutePath ( ) ) . close ( ) ;
try ( FileWriter writer = new FileWriter ( dotGit ) ) {
writer . append ( "gitdir: " + repo1 . getDirectory ( ) . getAbsolutePath ( ) ) . close ( ) ;
FileRepositoryBuilder builder = new FileRepositoryBuilder ( ) ;
builder . setWorkTree ( dir ) ;
@ -136,16 +132,16 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
. getDirectory ( ) . getAbsolutePath ( ) ) ;
assertEquals ( dir , repo2 . getWorkTree ( ) ) ;
}
}
@SuppressWarnings ( "resource" /* java 7 */ )
@Test
public void relativeGitDirRef ( ) throws Exception {
Repository repo1 = createWorkRepository ( ) ;
File dir = new File ( repo1 . getWorkTree ( ) , "dir" ) ;
assertTrue ( dir . mkdir ( ) ) ;
File dotGit = new File ( dir , Constants . DOT_GIT ) ;
new FileWriter ( dotGit ) . append ( "gitdir: ../" + Constants . DOT_GIT )
. close ( ) ;
try ( FileWriter writer = new FileWriter ( dotGit ) ) {
writer . append ( "gitdir: ../" + Constants . DOT_GIT ) . close ( ) ;
FileRepositoryBuilder builder = new FileRepositoryBuilder ( ) ;
builder . setWorkTree ( dir ) ;
@ -158,14 +154,15 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
. getDirectory ( ) . getCanonicalPath ( ) ) ;
assertEquals ( dir , repo2 . getWorkTree ( ) ) ;
}
}
@SuppressWarnings ( "resource" /* java 7 */ )
@Test
public void scanWithGitDirRef ( ) throws Exception {
Repository repo1 = createWorkRepository ( ) ;
File dir = createTempDirectory ( "dir" ) ;
File dotGit = new File ( dir , Constants . DOT_GIT ) ;
new FileWriter ( dotGit ) . append (
try ( FileWriter writer = new FileWriter ( dotGit ) ) {
writer . append (
"gitdir: " + repo1 . getDirectory ( ) . getAbsolutePath ( ) ) . close ( ) ;
FileRepositoryBuilder builder = new FileRepositoryBuilder ( ) ;
@ -182,3 +179,4 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
assertEquals ( dir , repo2 . getWorkTree ( ) ) ;
}
}
}