Browse Source

Convert all JGit unit tests to JUnit 4

Eclipse has some problem re-running single JUnit tests if
the tests are in Junit 3 format, but the JUnit 4 launcher
is used. This was quite unnecessary and the move was not
completed. We still have no JUnit4 test.

This completes the extermination of JUnit3. Most of the
work was global searce/replace using regular expression,
followed by numerous invocarions of quick-fix and organize
imports and verification that we had the same number of
tests before and after.

- Annotations were introduced.
- All references to JUnit3 classes removed
- Half-good replacement for getting the test name. This was
  needed to make the TestRngs work. The initialization of
  TestRngs was also made lazily since we can not longer find
  out the test name in runtime in the @Before methods.
- Renamed test classes to end with Test, with the exception
  of TestTranslateBundle, which fails from Maven
- Moved JGitTestUtil to the junit support bundle

Change-Id: Iddcd3da6ca927a7be773a9c63ebf8bb2147e2d13
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.11
Robin Rosenberg 14 years ago committed by Shawn O. Pearce
parent
commit
d9e07a574a
  1. 1
      org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
  2. 0
      org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests (Java 6).launch
  3. 0
      org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests.launch
  4. 2
      org.eclipse.jgit.http.test/org.eclipse.jgit.http--All-Tests.launch
  5. 9
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java
  6. 11
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java
  7. 16
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java
  8. 13
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java
  9. 14
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java
  10. 15
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java
  11. 18
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ErrorServletTest.java
  12. 11
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java
  13. 18
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletInitTest.java
  14. 10
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java
  15. 9
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
  16. 18
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
  17. 4
      org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
  18. 9
      org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java
  19. 6
      org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java
  20. 10
      org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java
  21. 6
      org.eclipse.jgit.junit/META-INF/MANIFEST.MF
  22. 53
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
  23. 35
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
  24. 13
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  25. 3
      org.eclipse.jgit.test/META-INF/MANIFEST.MF
  26. 21
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java
  27. 11
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
  28. 2
      org.eclipse.jgit.test/pom.xml
  29. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
  30. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
  31. 19
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
  32. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
  33. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
  34. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
  35. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
  36. 22
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  37. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
  38. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
  39. 29
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
  40. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java
  41. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
  42. 26
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
  43. 26
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java
  44. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
  45. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java
  46. 25
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
  47. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java
  48. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespaceTest.java
  49. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespaceTest.java
  50. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespaceTest.java
  51. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java
  52. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
  53. 34
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
  54. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
  55. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
  56. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
  57. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
  58. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
  59. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
  60. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java
  61. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
  62. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java
  63. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java
  64. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java
  65. 157
      org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java
  66. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java
  67. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
  68. 36
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbreviatedObjectIdTest.java
  69. 37
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
  70. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConstantsEncodingTest.java
  71. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
  72. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  73. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexTreeWalkerTest.java
  74. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java
  75. 98
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
  76. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdRefTest.java
  77. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java
  78. 30
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectLoaderTest.java
  79. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
  80. 37
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
  81. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
  82. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
  83. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
  84. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
  85. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
  86. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java
  87. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SymbolicRefTest.java
  88. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
  89. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java
  90. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
  91. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorLeafOnlyTest.java
  92. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPostOrderTest.java
  93. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPreOrderTest.java
  94. 22
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
  95. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckoutTest.java
  96. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
  97. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
  98. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java
  99. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
  100. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/NonTranslatedBundle.java
  101. Some files were not shown because too many files have changed in this diff Show More

1
org.eclipse.jgit.http.test/META-INF/MANIFEST.MF

@ -8,7 +8,6 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: javax.servlet;version="[2.5.0,3.0.0)", Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
javax.servlet.http;version="[2.5.0,3.0.0)", javax.servlet.http;version="[2.5.0,3.0.0)",
junit.framework;version="[4.0.0,5.0.0)",
org.eclipse.jetty.continuation;version="[7.1.0,8.0.0)", org.eclipse.jetty.continuation;version="[7.1.0,8.0.0)",
org.eclipse.jetty.http;version="[7.1.0,8.0.0)", org.eclipse.jetty.http;version="[7.1.0,8.0.0)",
org.eclipse.jetty.http.security;version="[7.1.0,8.0.0)", org.eclipse.jetty.http.security;version="[7.1.0,8.0.0)",

0
org.eclipse.jgit.http.test/org.eclipse.jgit.core.http --All-Tests (Java 6).launch → org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests (Java 6).launch

0
org.eclipse.jgit.http.test/org.eclipse.jgit.core.http --All-Tests.launch → org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests.launch

2
org.eclipse.jgit.http.test/org.eclipse.jgit.http--All-Tests.launch

@ -9,7 +9,7 @@
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.jgit.http.test"/> <stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.jgit.http.test"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> <booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.http.test"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.http.test"/>
</launchConfiguration> </launchConfiguration>

9
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java

@ -43,6 +43,9 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.Collections; import java.util.Collections;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -70,13 +73,16 @@ import org.eclipse.jgit.transport.ReceivePack;
import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class AdvertiseErrorTest extends HttpTestCase { public class AdvertiseErrorTest extends HttpTestCase {
private FileRepository remoteRepository; private FileRepository remoteRepository;
private URIish remoteURI; private URIish remoteURI;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository<FileRepository> src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
@ -120,6 +126,7 @@ public class AdvertiseErrorTest extends HttpTestCase {
cfg.save(); cfg.save();
} }
@Test
public void testPush_CreateBranch() throws Exception { public void testPush_CreateBranch() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
final RevBlob Q_txt = src.blob("new text"); final RevBlob Q_txt = src.blob("new text");

11
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
@ -54,19 +56,23 @@ import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.junit.Before;
import org.junit.Test;
public class AsIsServiceTest extends LocalDiskRepositoryTestCase { public class AsIsServiceTest extends LocalDiskRepositoryTestCase {
private Repository db; private Repository db;
private AsIsFileService service; private AsIsFileService service;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
db = createBareRepository(); db = createBareRepository();
service = new AsIsFileService(); service = new AsIsFileService();
} }
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException { public void testDisabledSingleton() throws ServiceNotAuthorizedException {
service = AsIsFileService.DISABLED; service = AsIsFileService.DISABLED;
try { try {
@ -84,12 +90,14 @@ public class AsIsServiceTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_Default() throws ServiceNotEnabledException, public void testCreate_Default() throws ServiceNotEnabledException,
ServiceNotAuthorizedException { ServiceNotAuthorizedException {
service.access(new R(null, "1.2.3.4"), db); service.access(new R(null, "1.2.3.4"), db);
service.access(new R("bob", "1.2.3.4"), db); service.access(new R("bob", "1.2.3.4"), db);
} }
@Test
public void testCreate_Disabled() throws ServiceNotAuthorizedException, public void testCreate_Disabled() throws ServiceNotAuthorizedException,
IOException { IOException {
final StoredConfig cfg = db.getConfig(); final StoredConfig cfg = db.getConfig();
@ -111,6 +119,7 @@ public class AsIsServiceTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_Enabled() throws ServiceNotEnabledException, public void testCreate_Enabled() throws ServiceNotEnabledException,
ServiceNotAuthorizedException { ServiceNotAuthorizedException {
db.getConfig().setBoolean("http", null, "getanyfile", true); db.getConfig().setBoolean("http", null, "getanyfile", true);

16
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java

@ -43,6 +43,11 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
@ -57,19 +62,23 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.ReceivePack;
import org.junit.Before;
import org.junit.Test;
public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
private Repository db; private Repository db;
private ReceivePackFactory factory; private ReceivePackFactory factory;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
db = createBareRepository(); db = createBareRepository();
factory = new DefaultReceivePackFactory(); factory = new DefaultReceivePackFactory();
} }
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException { public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = ReceivePackFactory.DISABLED; factory = ReceivePackFactory.DISABLED;
@ -95,6 +104,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_NullUser() throws ServiceNotEnabledException { public void testCreate_NullUser() throws ServiceNotEnabledException {
try { try {
factory.create(new R(null, "localhost"), db); factory.create(new R(null, "localhost"), db);
@ -104,6 +114,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_EmptyStringUser() throws ServiceNotEnabledException { public void testCreate_EmptyStringUser() throws ServiceNotEnabledException {
try { try {
factory.create(new R("", "localhost"), db); factory.create(new R("", "localhost"), db);
@ -113,6 +124,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_AuthUser() throws ServiceNotEnabledException, public void testCreate_AuthUser() throws ServiceNotEnabledException,
ServiceNotAuthorizedException { ServiceNotAuthorizedException {
ReceivePack rp; ReceivePack rp;
@ -130,6 +142,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
assertEquals(author.getWhen(), id.getWhen()); assertEquals(author.getWhen(), id.getWhen());
} }
@Test
public void testCreate_Disabled() throws ServiceNotAuthorizedException, public void testCreate_Disabled() throws ServiceNotAuthorizedException,
IOException { IOException {
final StoredConfig cfg = db.getConfig(); final StoredConfig cfg = db.getConfig();
@ -158,6 +171,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_Enabled() throws ServiceNotEnabledException, public void testCreate_Enabled() throws ServiceNotEnabledException,
ServiceNotAuthorizedException, IOException { ServiceNotAuthorizedException, IOException {
final StoredConfig cfg = db.getConfig(); final StoredConfig cfg = db.getConfig();

13
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java

@ -43,6 +43,10 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
@ -56,19 +60,23 @@ import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.UploadPack;
import org.junit.Before;
import org.junit.Test;
public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
private Repository db; private Repository db;
private UploadPackFactory factory; private UploadPackFactory factory;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
db = createBareRepository(); db = createBareRepository();
factory = new DefaultUploadPackFactory(); factory = new DefaultUploadPackFactory();
} }
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException { public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = UploadPackFactory.DISABLED; factory = UploadPackFactory.DISABLED;
@ -94,6 +102,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_Default() throws ServiceNotEnabledException, public void testCreate_Default() throws ServiceNotEnabledException,
ServiceNotAuthorizedException { ServiceNotAuthorizedException {
UploadPack up; UploadPack up;
@ -107,6 +116,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
assertSame(db, up.getRepository()); assertSame(db, up.getRepository());
} }
@Test
public void testCreate_Disabled() throws ServiceNotAuthorizedException, public void testCreate_Disabled() throws ServiceNotAuthorizedException,
IOException { IOException {
final StoredConfig cfg = db.getConfig(); final StoredConfig cfg = db.getConfig();
@ -128,6 +138,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCreate_Enabled() throws ServiceNotEnabledException, public void testCreate_Enabled() throws ServiceNotEnabledException,
ServiceNotAuthorizedException { ServiceNotAuthorizedException {
db.getConfig().setBoolean("http", null, "uploadpack", true); db.getConfig().setBoolean("http", null, "uploadpack", true);

14
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java

@ -46,6 +46,11 @@ package org.eclipse.jgit.http.test;
import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT; import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT;
import static org.eclipse.jgit.util.HttpSupport.HDR_PRAGMA; import static org.eclipse.jgit.util.HttpSupport.HDR_PRAGMA;
import static org.eclipse.jgit.util.HttpSupport.HDR_USER_AGENT; import static org.eclipse.jgit.util.HttpSupport.HDR_USER_AGENT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -70,6 +75,8 @@ import org.eclipse.jgit.transport.HttpTransport;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class DumbClientDumbServerTest extends HttpTestCase { public class DumbClientDumbServerTest extends HttpTestCase {
private Repository remoteRepository; private Repository remoteRepository;
@ -80,7 +87,8 @@ public class DumbClientDumbServerTest extends HttpTestCase {
private RevCommit A, B; private RevCommit A, B;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
@ -102,6 +110,7 @@ public class DumbClientDumbServerTest extends HttpTestCase {
src.update(master, B); src.update(master, B);
} }
@Test
public void testListRemote() throws IOException { public void testListRemote() throws IOException {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
@ -164,6 +173,7 @@ public class DumbClientDumbServerTest extends HttpTestCase {
assertEquals(200, head.getStatus()); assertEquals(200, head.getStatus());
} }
@Test
public void testInitialClone_Loose() throws Exception { public void testInitialClone_Loose() throws Exception {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
assertFalse(dst.hasObject(A_txt)); assertFalse(dst.hasObject(A_txt));
@ -186,6 +196,7 @@ public class DumbClientDumbServerTest extends HttpTestCase {
assertEquals(200, loose.get(0).getStatus()); assertEquals(200, loose.get(0).getStatus());
} }
@Test
public void testInitialClone_Packed() throws Exception { public void testInitialClone_Packed() throws Exception {
new TestRepository(remoteRepository).packAndPrune(); new TestRepository(remoteRepository).packAndPrune();
@ -225,6 +236,7 @@ public class DumbClientDumbServerTest extends HttpTestCase {
assertEquals(200, event.getStatus()); assertEquals(200, event.getStatus());
} }
@Test
public void testPushNotSupported() throws Exception { public void testPushNotSupported() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
final RevCommit Q = src.commit().create(); final RevCommit Q = src.commit().create();

15
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java

@ -47,6 +47,12 @@ import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
import static org.eclipse.jgit.util.HttpSupport.HDR_PRAGMA; import static org.eclipse.jgit.util.HttpSupport.HDR_PRAGMA;
import static org.eclipse.jgit.util.HttpSupport.HDR_USER_AGENT; import static org.eclipse.jgit.util.HttpSupport.HDR_USER_AGENT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -75,6 +81,8 @@ import org.eclipse.jgit.transport.HttpTransport;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class DumbClientSmartServerTest extends HttpTestCase { public class DumbClientSmartServerTest extends HttpTestCase {
private Repository remoteRepository; private Repository remoteRepository;
@ -85,7 +93,8 @@ public class DumbClientSmartServerTest extends HttpTestCase {
private RevCommit A, B; private RevCommit A, B;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
@ -118,6 +127,7 @@ public class DumbClientSmartServerTest extends HttpTestCase {
src.update(master, B); src.update(master, B);
} }
@Test
public void testListRemote() throws IOException { public void testListRemote() throws IOException {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
@ -179,6 +189,7 @@ public class DumbClientSmartServerTest extends HttpTestCase {
assertEquals("text/plain", head.getResponseHeader(HDR_CONTENT_TYPE)); assertEquals("text/plain", head.getResponseHeader(HDR_CONTENT_TYPE));
} }
@Test
public void testInitialClone_Small() throws Exception { public void testInitialClone_Small() throws Exception {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
assertFalse(dst.hasObject(A_txt)); assertFalse(dst.hasObject(A_txt));
@ -204,6 +215,7 @@ public class DumbClientSmartServerTest extends HttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE)); .getResponseHeader(HDR_CONTENT_TYPE));
} }
@Test
public void testInitialClone_Packed() throws Exception { public void testInitialClone_Packed() throws Exception {
new TestRepository(remoteRepository).packAndPrune(); new TestRepository(remoteRepository).packAndPrune();
@ -239,6 +251,7 @@ public class DumbClientSmartServerTest extends HttpTestCase {
HDR_CONTENT_TYPE)); HDR_CONTENT_TYPE));
} }
@Test
public void testPushNotSupported() throws Exception { public void testPushNotSupported() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
final RevCommit Q = src.commit().create(); final RevCommit Q = src.commit().create();

18
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ErrorServletTest.java

@ -43,21 +43,24 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertEquals;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import junit.framework.TestCase;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jgit.http.server.glue.ErrorServlet; import org.eclipse.jgit.http.server.glue.ErrorServlet;
import org.eclipse.jgit.junit.http.AppServer; import org.eclipse.jgit.junit.http.AppServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ErrorServletTest extends TestCase { public class ErrorServletTest {
private AppServer server; private AppServer server;
protected void setUp() throws Exception { @Before
super.setUp(); public void setUp() throws Exception {
server = new AppServer(); server = new AppServer();
@ -68,13 +71,14 @@ public class ErrorServletTest extends TestCase {
server.setUp(); server.setUp();
} }
protected void tearDown() throws Exception { @After
public void tearDown() throws Exception {
if (server != null) { if (server != null) {
server.tearDown(); server.tearDown();
} }
super.tearDown();
} }
@Test
public void testHandler() throws Exception { public void testHandler() throws Exception {
final URI uri = server.getURI(); final URI uri = server.getURI();
assertEquals(404, ((HttpURLConnection) uri.resolve("/404").toURL() assertEquals(404, ((HttpURLConnection) uri.resolve("/404").toURL()

11
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java

@ -43,6 +43,13 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -51,8 +58,10 @@ import org.eclipse.jgit.http.server.resolver.FileResolver;
import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.junit.Test;
public class FileResolverTest extends LocalDiskRepositoryTestCase { public class FileResolverTest extends LocalDiskRepositoryTestCase {
@Test
public void testUnreasonableNames() throws ServiceNotEnabledException { public void testUnreasonableNames() throws ServiceNotEnabledException {
assertUnreasonable(""); assertUnreasonable("");
assertUnreasonable("a\\b"); assertUnreasonable("a\\b");
@ -83,6 +92,7 @@ public class FileResolverTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testExportOk() throws IOException { public void testExportOk() throws IOException {
final Repository a = createBareRepository(); final Repository a = createBareRepository();
final String name = a.getDirectory().getName(); final String name = a.getDirectory().getName();
@ -116,6 +126,7 @@ public class FileResolverTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testNotAGitRepository() throws IOException, public void testNotAGitRepository() throws IOException,
ServiceNotEnabledException { ServiceNotEnabledException {
final Repository a = createBareRepository(); final Repository a = createBareRepository();

18
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletInitTest.java

@ -43,30 +43,35 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List; import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import junit.framework.TestCase;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jgit.http.server.GitServlet; import org.eclipse.jgit.http.server.GitServlet;
import org.eclipse.jgit.junit.http.AppServer; import org.eclipse.jgit.junit.http.AppServer;
import org.eclipse.jgit.junit.http.MockServletConfig; import org.eclipse.jgit.junit.http.MockServletConfig;
import org.eclipse.jgit.junit.http.RecordingLogger; import org.eclipse.jgit.junit.http.RecordingLogger;
import org.junit.After;
import org.junit.Test;
public class GitServletInitTest extends TestCase { public class GitServletInitTest {
private AppServer server; private AppServer server;
protected void tearDown() throws Exception { @After
public void tearDown() throws Exception {
if (server != null) { if (server != null) {
server.tearDown(); server.tearDown();
server = null; server = null;
} }
super.tearDown();
} }
@Test
public void testDefaultConstructor_NoBasePath() throws Exception { public void testDefaultConstructor_NoBasePath() throws Exception {
GitServlet s = new GitServlet(); GitServlet s = new GitServlet();
try { try {
@ -77,6 +82,7 @@ public class GitServletInitTest extends TestCase {
} }
} }
@Test
public void testDefaultConstructor_WithBasePath() throws Exception { public void testDefaultConstructor_WithBasePath() throws Exception {
MockServletConfig c = new MockServletConfig(); MockServletConfig c = new MockServletConfig();
c.setInitParameter("base-path", "."); c.setInitParameter("base-path", ".");
@ -87,6 +93,7 @@ public class GitServletInitTest extends TestCase {
s.destroy(); s.destroy();
} }
@Test
public void testInitUnderContainer_NoBasePath() throws Exception { public void testInitUnderContainer_NoBasePath() throws Exception {
server = new AppServer(); server = new AppServer();
@ -104,6 +111,7 @@ public class GitServletInitTest extends TestCase {
assertTrue("Wanted base-path", why.getMessage().contains("base-path")); assertTrue("Wanted base-path", why.getMessage().contains("base-path"));
} }
@Test
public void testInitUnderContainer_WithBasePath() throws Exception { public void testInitUnderContainer_WithBasePath() throws Exception {
server = new AppServer(); server = new AppServer();

10
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java

@ -43,6 +43,10 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -75,13 +79,16 @@ import org.eclipse.jgit.transport.ReceivePack;
import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class HookMessageTest extends HttpTestCase { public class HookMessageTest extends HttpTestCase {
private FileRepository remoteRepository; private FileRepository remoteRepository;
private URIish remoteURI; private URIish remoteURI;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository<FileRepository> src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
@ -130,6 +137,7 @@ public class HookMessageTest extends HttpTestCase {
cfg.save(); cfg.save();
} }
@Test
public void testPush_CreateBranch() throws Exception { public void testPush_CreateBranch() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
final RevBlob Q_txt = src.blob("new text"); final RevBlob Q_txt = src.blob("new text");

9
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java

@ -43,6 +43,13 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
@ -86,7 +93,7 @@ public class HttpClientTests extends HttpTestCase {
private URIish smartAuthBasicURI; private URIish smartAuthBasicURI;
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
remoteRepository = createTestRepository(); remoteRepository = createTestRepository();

18
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java

@ -46,6 +46,12 @@ package org.eclipse.jgit.http.test;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE; import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -92,6 +98,8 @@ import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class SmartClientSmartServerTest extends HttpTestCase { public class SmartClientSmartServerTest extends HttpTestCase {
private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding"; private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding";
@ -106,7 +114,8 @@ public class SmartClientSmartServerTest extends HttpTestCase {
private RevCommit A, B; private RevCommit A, B;
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository<FileRepository> src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
@ -165,6 +174,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
src.update("refs/garbage/a/very/long/ref/name/to/compress", B); src.update("refs/garbage/a/very/long/ref/name/to/compress", B);
} }
@Test
public void testListRemote() throws IOException { public void testListRemote() throws IOException {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
@ -213,6 +223,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING)); assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
} }
@Test
public void testInitialClone_Small() throws Exception { public void testInitialClone_Small() throws Exception {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
assertFalse(dst.hasObject(A_txt)); assertFalse(dst.hasObject(A_txt));
@ -257,6 +268,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE)); .getResponseHeader(HDR_CONTENT_TYPE));
} }
@Test
public void testFetchUpdateExisting() throws Exception { public void testFetchUpdateExisting() throws Exception {
// Bootstrap by doing the clone. // Bootstrap by doing the clone.
// //
@ -336,6 +348,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE)); .getResponseHeader(HDR_CONTENT_TYPE));
} }
@Test
public void testInitialClone_BrokenServer() throws Exception { public void testInitialClone_BrokenServer() throws Exception {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
assertFalse(dst.hasObject(A_txt)); assertFalse(dst.hasObject(A_txt));
@ -376,6 +389,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE)); .getResponseHeader(HDR_CONTENT_TYPE));
} }
@Test
public void testPush_NotAuthorized() throws Exception { public void testPush_NotAuthorized() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
final RevBlob Q_txt = src.blob("new text"); final RevBlob Q_txt = src.blob("new text");
@ -418,6 +432,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
assertEquals(401, info.getStatus()); assertEquals(401, info.getStatus());
} }
@Test
public void testPush_CreateBranch() throws Exception { public void testPush_CreateBranch() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository src = createTestRepository();
final RevBlob Q_txt = src.blob("new text"); final RevBlob Q_txt = src.blob("new text");
@ -490,6 +505,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE)); .getResponseHeader(HDR_CONTENT_TYPE));
} }
@Test
public void testPush_ChunkedEncoding() throws Exception { public void testPush_ChunkedEncoding() throws Exception {
final TestRepository<FileRepository> src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
final RevBlob Q_bin = src.blob(new TestRng("Q").nextBytes(128 * 1024)); final RevBlob Q_bin = src.blob(new TestRng("Q").nextBytes(128 * 1024));

4
org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF

@ -9,7 +9,6 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: javax.servlet;version="[2.5.0,3.0.0)", Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
javax.servlet.http;version="[2.5.0,3.0.0)", javax.servlet.http;version="[2.5.0,3.0.0)",
junit.framework;version="[3.8.2,4.0.0)",
org.eclipse.jetty.continuation;version="[7.1.0,8.0.0)", org.eclipse.jetty.continuation;version="[7.1.0,8.0.0)",
org.eclipse.jetty.http;version="[7.1.0,8.0.0)", org.eclipse.jetty.http;version="[7.1.0,8.0.0)",
org.eclipse.jetty.http.security;version="[7.1.0,8.0.0)", org.eclipse.jetty.http.security;version="[7.1.0,8.0.0)",
@ -30,5 +29,6 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
org.eclipse.jgit.lib;version="[0.11.0,0.12.0)", org.eclipse.jgit.lib;version="[0.11.0,0.12.0)",
org.eclipse.jgit.revwalk;version="[0.11.0,0.12.0)", org.eclipse.jgit.revwalk;version="[0.11.0,0.12.0)",
org.eclipse.jgit.storage.file;version="[0.11.0,0.12.0)", org.eclipse.jgit.storage.file;version="[0.11.0,0.12.0)",
org.eclipse.jgit.transport;version="[0.11.0,0.12.0)" org.eclipse.jgit.transport;version="[0.11.0,0.12.0)",
org.junit;version="[4.0.0,5.0.0)"
Export-Package: org.eclipse.jgit.junit.http;version="0.11.0" Export-Package: org.eclipse.jgit.junit.http;version="0.11.0"

9
org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java

@ -43,6 +43,9 @@
package org.eclipse.jgit.junit.http; package org.eclipse.jgit.junit.http;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
@ -51,8 +54,6 @@ import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import junit.framework.Assert;
import org.eclipse.jetty.http.security.Constraint; import org.eclipse.jetty.http.security.Constraint;
import org.eclipse.jetty.http.security.Password; import org.eclipse.jetty.http.security.Password;
import org.eclipse.jetty.security.Authenticator; import org.eclipse.jetty.security.Authenticator;
@ -282,10 +283,10 @@ public class AppServer {
} }
private void assertNotYetSetUp() { private void assertNotYetSetUp() {
Assert.assertFalse("server is not running", server.isRunning()); assertFalse("server is not running", server.isRunning());
} }
private void assertAlreadySetUp() { private void assertAlreadySetUp() {
Assert.assertTrue("server is running", server.isRunning()); assertTrue("server is running", server.isRunning());
} }
} }

6
org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.junit.http; package org.eclipse.jgit.junit.http;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -73,12 +75,12 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase {
/** In-memory application server; subclass must start. */ /** In-memory application server; subclass must start. */
protected AppServer server; protected AppServer server;
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
server = new AppServer(); server = new AppServer();
} }
protected void tearDown() throws Exception { public void tearDown() throws Exception {
server.tearDown(); server.tearDown();
super.tearDown(); super.tearDown();
} }

10
org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java

@ -43,11 +43,6 @@
package org.eclipse.jgit.junit.http; package org.eclipse.jgit.junit.http;
import org.eclipse.jetty.server.DispatcherType;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -57,6 +52,11 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.DispatcherType;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.handler.HandlerWrapper;
/** Logs request made through {@link AppServer}. */ /** Logs request made through {@link AppServer}. */
class TestRequestLog extends HandlerWrapper { class TestRequestLog extends HandlerWrapper {
private static final int MAX = 16; private static final int MAX = 16;

6
org.eclipse.jgit.junit/META-INF/MANIFEST.MF

@ -7,8 +7,7 @@ Bundle-Localization: plugin
Bundle-Vendor: %provider_name Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: junit.framework;version="[4.0.0,5.0.0)", Import-Package: org.eclipse.jgit.diff;version="[0.11.0,0.12.0)",
org.eclipse.jgit.diff;version="[0.11.0,0.12.0)",
org.eclipse.jgit.dircache;version="[0.11.0,0.12.0)", org.eclipse.jgit.dircache;version="[0.11.0,0.12.0)",
org.eclipse.jgit.errors;version="[0.11.0,0.12.0)", org.eclipse.jgit.errors;version="[0.11.0,0.12.0)",
org.eclipse.jgit.fnmatch;version="[0.11.0,0.12.0)", org.eclipse.jgit.fnmatch;version="[0.11.0,0.12.0)",
@ -24,6 +23,7 @@ Import-Package: junit.framework;version="[4.0.0,5.0.0)",
org.eclipse.jgit.treewalk;version="[0.11.0,0.12.0)", org.eclipse.jgit.treewalk;version="[0.11.0,0.12.0)",
org.eclipse.jgit.treewalk.filter;version="[0.11.0,0.12.0)", org.eclipse.jgit.treewalk.filter;version="[0.11.0,0.12.0)",
org.eclipse.jgit.util;version="[0.11.0,0.12.0)", org.eclipse.jgit.util;version="[0.11.0,0.12.0)",
org.eclipse.jgit.util.io;version="[0.11.0,0.12.0)" org.eclipse.jgit.util.io;version="[0.11.0,0.12.0)",
org.junit;version="[4.0.0,5.0.0)"
Export-Package: org.eclipse.jgit.junit;version="0.11.0" Export-Package: org.eclipse.jgit.junit;version="0.11.0"
Require-Bundle: com.jcraft.jsch;bundle-version="[0.1.37,0.2.0)" Require-Bundle: com.jcraft.jsch;bundle-version="[0.1.37,0.2.0)"

53
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/JGitTestUtil.java → org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java

@ -43,12 +43,17 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package org.eclipse.jgit.util; package org.eclipse.jgit.junit;
import java.io.File; import java.io.File;
import java.lang.reflect.Method;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import org.eclipse.jgit.util.RawParseUtils;
import org.junit.Assert;
import org.junit.Test;
public abstract class JGitTestUtil { public abstract class JGitTestUtil {
public static final String CLASSPATH_TO_RESOURCES = "org/eclipse/jgit/test/resources/"; public static final String CLASSPATH_TO_RESOURCES = "org/eclipse/jgit/test/resources/";
@ -56,6 +61,52 @@ public abstract class JGitTestUtil {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public static String getName() {
GatherStackTrace stack;
try {
throw new GatherStackTrace();
} catch (GatherStackTrace wanted) {
stack = wanted;
}
try {
for (StackTraceElement stackTrace : stack.getStackTrace()) {
String className = stackTrace.getClassName();
String methodName = stackTrace.getMethodName();
Method method;
try {
method = Class.forName(className) //
.getMethod(methodName, (Class[]) null);
} catch (NoSuchMethodException e) {
// could be private, i.e. not a test method
// could have arguments, not handled
continue;
}
Test annotation = method.getAnnotation(Test.class);
if (annotation != null)
return methodName;
}
} catch (ClassNotFoundException shouldNeverOccur) {
// Fall through and crash.
}
throw new AssertionError("Cannot determine name of current test");
}
@SuppressWarnings("serial")
private static class GatherStackTrace extends Exception {
// Thrown above to collect the stack frame.
}
public static void assertEquals(byte[] exp, byte[] act) {
Assert.assertEquals(s(exp), s(act));
}
private static String s(byte[] raw) {
return RawParseUtils.decode(raw);
}
public static File getTestResourceFile(final String fileName) { public static File getTestResourceFile(final String fileName) {
if (fileName == null || fileName.length() <= 0) { if (fileName == null || fileName.length() <= 0) {
return null; return null;

35
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java

@ -45,6 +45,9 @@
package org.eclipse.jgit.junit; package org.eclipse.jgit.junit;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -57,10 +60,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -72,6 +71,8 @@ import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.Before;
/** /**
* JUnit TestCase with specialized support for temporary local repository. * JUnit TestCase with specialized support for temporary local repository.
@ -90,7 +91,7 @@ import org.eclipse.jgit.util.SystemReader;
* a test, or tests may fail altogether if there is insufficient file * a test, or tests may fail altogether if there is insufficient file
* descriptors or address space for the test process. * descriptors or address space for the test process.
*/ */
public abstract class LocalDiskRepositoryTestCase extends TestCase { public abstract class LocalDiskRepositoryTestCase {
private static Thread shutdownHook; private static Thread shutdownHook;
private static int testCount; private static int testCount;
@ -110,9 +111,8 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
private MockSystemReader mockSystemReader; private MockSystemReader mockSystemReader;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
synchronized(this) { synchronized(this) {
if (shutdownHook == null) { if (shutdownHook == null) {
@ -131,7 +131,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
Runtime.getRuntime().addShutdownHook(shutdownHook); Runtime.getRuntime().addShutdownHook(shutdownHook);
} }
} }
recursiveDelete(testName(), trash, true, false); recursiveDelete(testId(), trash, true, false);
mockSystemReader = new MockSystemReader(); mockSystemReader = new MockSystemReader();
mockSystemReader.userGitConfig = new FileBasedConfig(new File(trash, mockSystemReader.userGitConfig = new FileBasedConfig(new File(trash,
@ -174,8 +174,8 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
return stringBuilder.toString(); return stringBuilder.toString();
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
RepositoryCache.clear(); RepositoryCache.clear();
for (Repository r : toClose) for (Repository r : toClose)
r.close(); r.close();
@ -188,8 +188,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
if (useMMAP) if (useMMAP)
System.gc(); System.gc();
recursiveDelete(testName(), trash, false, true); recursiveDelete(testId(), trash, false, true);
super.tearDown();
} }
/** Increment the {@link #author} and {@link #committer} times. */ /** Increment the {@link #author} and {@link #committer} times. */
@ -210,7 +209,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* the recursively directory to delete, if present. * the recursively directory to delete, if present.
*/ */
protected void recursiveDelete(final File dir) { protected void recursiveDelete(final File dir) {
recursiveDelete(testName(), dir, false, true); recursiveDelete(testId(), dir, false, true);
} }
private static boolean recursiveDelete(final String testName, private static boolean recursiveDelete(final String testName,
@ -414,10 +413,6 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
return new String(body, 0, body.length, "UTF-8"); return new String(body, 0, body.length, "UTF-8");
} }
protected static void assertEquals(AnyObjectId exp, AnyObjectId act) {
Assert.assertEquals(exp, act);
}
private static String[] toEnvArray(final Map<String, String> env) { private static String[] toEnvArray(final Map<String, String> env) {
final String[] envp = new String[env.size()]; final String[] envp = new String[env.size()];
int i = 0; int i = 0;
@ -431,7 +426,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
return new HashMap<String, String>(System.getenv()); return new HashMap<String, String>(System.getenv());
} }
private String testName() { private String testId() {
return getClass().getName() + "." + getName(); return getClass().getName() + "." + testCount;
} }
} }

13
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.junit; package org.eclipse.jgit.junit;
import static org.junit.Assert.*;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -56,9 +58,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
@ -277,12 +276,10 @@ public class TestRepository<R extends Repository> {
* @param path * @param path
* the path to find the entry of. * the path to find the entry of.
* @return the parsed object entry at this path, never null. * @return the parsed object entry at this path, never null.
* @throws AssertionFailedError
* if the path does not exist in the given tree.
* @throws Exception * @throws Exception
*/ */
public RevObject get(final RevTree tree, final String path) public RevObject get(final RevTree tree, final String path)
throws AssertionFailedError, Exception { throws Exception {
final TreeWalk tw = new TreeWalk(pool.getObjectReader()); final TreeWalk tw = new TreeWalk(pool.getObjectReader());
tw.setFilter(PathFilterGroup.createFromStrings(Collections tw.setFilter(PathFilterGroup.createFromStrings(Collections
.singleton(path))); .singleton(path)));
@ -296,7 +293,7 @@ public class TestRepository<R extends Repository> {
final FileMode entmode = tw.getFileMode(0); final FileMode entmode = tw.getFileMode(0);
return pool.lookupAny(entid, entmode.getObjectType()); return pool.lookupAny(entid, entmode.getObjectType());
} }
Assert.fail("Can't find " + path + " in tree " + tree.name()); fail("Can't find " + path + " in tree " + tree.name());
return null; // never reached. return null; // never reached.
} }
@ -598,7 +595,7 @@ public class TestRepository<R extends Repository> {
md.update(Constants.encodeASCII(bin.length)); md.update(Constants.encodeASCII(bin.length));
md.update((byte) 0); md.update((byte) 0);
md.update(bin); md.update(bin);
Assert.assertEquals(id, ObjectId.fromRaw(md.digest())); assertEquals(id, ObjectId.fromRaw(md.digest()));
} }
/** /**

3
org.eclipse.jgit.test/META-INF/MANIFEST.MF

@ -7,8 +7,7 @@ Bundle-Localization: plugin
Bundle-Vendor: %provider_name Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: junit.framework;version="[4.0.0,5.0.0)", Import-Package: org.eclipse.jgit;version="[0.11.0,0.12.0)",
org.eclipse.jgit;version="[0.11.0,0.12.0)",
org.eclipse.jgit.api;version="[0.11.0,0.12.0)", org.eclipse.jgit.api;version="[0.11.0,0.12.0)",
org.eclipse.jgit.api.errors;version="[0.11.0,0.12.0)", org.eclipse.jgit.api.errors;version="[0.11.0,0.12.0)",
org.eclipse.jgit.awtui;version="[0.11.0,0.12.0)", org.eclipse.jgit.awtui;version="[0.11.0,0.12.0)",

21
org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java

@ -44,6 +44,11 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -53,6 +58,8 @@ import java.lang.reflect.Method;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.GitIndex.Entry; import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.junit.Before;
import org.junit.Test;
public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
@ -113,12 +120,14 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
private File trash; private File trash;
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
db = createWorkRepository(); db = createWorkRepository();
trash = db.getWorkTree(); trash = db.getWorkTree();
} }
@Test
public void testCreateEmptyIndex() throws Exception { public void testCreateEmptyIndex() throws Exception {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
index.write(); index.write();
@ -130,12 +139,14 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, indexr.getMembers().length); assertEquals(0, indexr.getMembers().length);
} }
@Test
public void testReadWithNoIndex() throws Exception { public void testReadWithNoIndex() throws Exception {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
index.read(); index.read();
assertEquals(0, index.getMembers().length); assertEquals(0, index.getMembers().length);
} }
@Test
public void testCreateSimpleSortTestIndex() throws Exception { public void testCreateSimpleSortTestIndex() throws Exception {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
writeTrashFile("a/b", "data:a/b"); writeTrashFile("a/b", "data:a/b");
@ -163,6 +174,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, system(trash, "git status")); assertEquals(0, system(trash, "git status"));
} }
@Test
public void testUpdateSimpleSortTestIndex() throws Exception { public void testUpdateSimpleSortTestIndex() throws Exception {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
writeTrashFile("a/b", "data:a/b"); writeTrashFile("a/b", "data:a/b");
@ -178,6 +190,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, system(trash, "git status")); assertEquals(0, system(trash, "git status"));
} }
@Test
public void testWriteTree() throws Exception { public void testWriteTree() throws Exception {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
writeTrashFile("a/b", "data:a/b"); writeTrashFile("a/b", "data:a/b");
@ -198,6 +211,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, system(trash, "git status")); assertEquals(0, system(trash, "git status"));
} }
@Test
public void testReadTree() throws Exception { public void testReadTree() throws Exception {
// Prepare tree // Prepare tree
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
@ -236,6 +250,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, system(trash, "git status")); assertEquals(0, system(trash, "git status"));
} }
@Test
public void testReadTree2() throws Exception { public void testReadTree2() throws Exception {
// Prepare a larger tree to test some odd cases in tree writing // Prepare a larger tree to test some odd cases in tree writing
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
@ -281,6 +296,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals("a:b", membersr[5].getName()); assertEquals("a:b", membersr[5].getName());
} }
@Test
public void testDelete() throws Exception { public void testDelete() throws Exception {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
writeTrashFile("a/b", "data:a/b"); writeTrashFile("a/b", "data:a/b");
@ -305,6 +321,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, system(trash, "git status")); assertEquals(0, system(trash, "git status"));
} }
@Test
public void testCheckout() throws Exception { public void testCheckout() throws Exception {
// Prepare tree, remote it and checkout // Prepare tree, remote it and checkout
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
@ -336,6 +353,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals(0, system(trash, "git status")); assertEquals(0, system(trash, "git status"));
} }
@Test
public void test030_executeBit_coreModeTrue() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { public void test030_executeBit_coreModeTrue() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception {
if (!FS.DETECTED.supportsExecute()) { if (!FS.DETECTED.supportsExecute()) {
System.err.println("Test ignored since platform FS does not support the execute permission"); System.err.println("Test ignored since platform FS does not support the execute permission");
@ -391,6 +409,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void test031_executeBit_coreModeFalse() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { public void test031_executeBit_coreModeFalse() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception {
if (!FS.DETECTED.supportsExecute()) { if (!FS.DETECTED.supportsExecute()) {
System.err.println("Test ignored since platform FS does not support the execute permission"); System.err.println("Test ignored since platform FS does not support the execute permission");

11
org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java

@ -43,6 +43,11 @@
package org.eclipse.jgit.patch; package org.eclipse.jgit.patch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -50,14 +55,14 @@ import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.MutableInteger;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.TemporaryBuffer; import org.eclipse.jgit.util.TemporaryBuffer;
import org.junit.Test;
public class EGitPatchHistoryTest extends TestCase { public class EGitPatchHistoryTest {
@Test
public void testParseHistory() throws Exception { public void testParseHistory() throws Exception {
final NumStatReader numstat = new NumStatReader(); final NumStatReader numstat = new NumStatReader();
numstat.read(); numstat.read();

2
org.eclipse.jgit.test/pom.xml

@ -129,8 +129,6 @@
<argLine>-Xmx256m -Dfile.encoding=UTF-8</argLine> <argLine>-Xmx256m -Dfile.encoding=UTF-8</argLine>
<includes> <includes>
<include>**/*Test.java</include> <include>**/*Test.java</include>
<include>**/*TestCase.java</include>
<include>**/T000*.java</include>
</includes> </includes>
</configuration> </configuration>
</plugin> </plugin>

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

@ -43,6 +43,9 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -58,9 +61,11 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
public class AddCommandTest extends RepositoryTestCase { public class AddCommandTest extends RepositoryTestCase {
@Test
public void testAddNothing() { public void testAddNothing() {
Git git = new Git(db); Git git = new Git(db);
@ -73,6 +78,7 @@ public class AddCommandTest extends RepositoryTestCase {
} }
@Test
public void testAddNonExistingSingleFile() throws NoFilepatternException { public void testAddNonExistingSingleFile() throws NoFilepatternException {
Git git = new Git(db); Git git = new Git(db);
@ -81,6 +87,7 @@ public class AddCommandTest extends RepositoryTestCase {
} }
@Test
public void testAddExistingSingleFile() throws IOException, NoFilepatternException { public void testAddExistingSingleFile() throws IOException, NoFilepatternException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile(); file.createNewFile();
@ -97,6 +104,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException { public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException {
new File(db.getWorkTree(), "sub").mkdir(); new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
@ -114,6 +122,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException { public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile(); file.createNewFile();
@ -137,6 +146,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddExistingSingleFileTwiceWithCommit() throws Exception { public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile(); file.createNewFile();
@ -162,6 +172,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddRemovedFile() throws Exception { public void testAddRemovedFile() throws Exception {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile(); file.createNewFile();
@ -183,6 +194,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddRemovedCommittedFile() throws Exception { public void testAddRemovedCommittedFile() throws Exception {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile(); file.createNewFile();
@ -206,6 +218,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddWithConflicts() throws Exception { public void testAddWithConflicts() throws Exception {
// prepare conflict // prepare conflict
@ -259,6 +272,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddTwoFiles() throws Exception { public void testAddTwoFiles() throws Exception {
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile(); file.createNewFile();
@ -280,6 +294,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddFolder() throws Exception { public void testAddFolder() throws Exception {
new File(db.getWorkTree(), "sub").mkdir(); new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
@ -302,6 +317,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddIgnoredFile() throws Exception { public void testAddIgnoredFile() throws Exception {
new File(db.getWorkTree(), "sub").mkdir(); new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
@ -330,6 +346,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAddWholeRepo() throws Exception { public void testAddWholeRepo() throws Exception {
new File(db.getWorkTree(), "sub").mkdir(); new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
@ -356,6 +373,7 @@ public class AddCommandTest extends RepositoryTestCase {
// file a exists in workdir and in index -> added // file a exists in workdir and in index -> added
// file b exists not in workdir but in index -> unchanged // file b exists not in workdir but in index -> unchanged
// file c exists in workdir but not in index -> added // file c exists in workdir but not in index -> added
@Test
public void testAddWithoutParameterUpdate() throws Exception { public void testAddWithoutParameterUpdate() throws Exception {
new File(db.getWorkTree(), "sub").mkdir(); new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
@ -409,6 +427,7 @@ public class AddCommandTest extends RepositoryTestCase {
// file a exists in workdir and in index -> added // file a exists in workdir and in index -> added
// file b exists not in workdir but in index -> deleted // file b exists not in workdir but in index -> deleted
// file c exists in workdir but not in index -> unchanged // file c exists in workdir but not in index -> unchanged
@Test
public void testAddWithParameterUpdate() throws Exception { public void testAddWithParameterUpdate() throws Exception {
new File(db.getWorkTree(), "sub").mkdir(); new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt"); File file = new File(db.getWorkTree(), "sub/a.txt");
@ -457,6 +476,7 @@ public class AddCommandTest extends RepositoryTestCase {
indexState(CONTENT)); indexState(CONTENT));
} }
@Test
public void testAssumeUnchanged() throws Exception { public void testAssumeUnchanged() throws Exception {
Git git = new Git(db); Git git = new Git(db);
String path = "a.txt"; String path = "a.txt";

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java

@ -42,6 +42,11 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.List; import java.util.List;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
@ -65,6 +70,8 @@ import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class BranchCommandTest extends RepositoryTestCase { public class BranchCommandTest extends RepositoryTestCase {
private Git git; private Git git;
@ -74,7 +81,8 @@ public class BranchCommandTest extends RepositoryTestCase {
RevCommit secondCommit; RevCommit secondCommit;
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
git = new Git(db); git = new Git(db);
// checkout master // checkout master
@ -128,6 +136,7 @@ public class BranchCommandTest extends RepositoryTestCase {
return localGit; return localGit;
} }
@Test
public void testCreateAndList() throws Exception { public void testCreateAndList() throws Exception {
int localBefore; int localBefore;
int remoteBefore; int remoteBefore;
@ -180,6 +189,7 @@ public class BranchCommandTest extends RepositoryTestCase {
- allBefore); - allBefore);
} }
@Test
public void testCreateFromCommit() throws Exception { public void testCreateFromCommit() throws Exception {
Ref branch = git.branchCreate().setName("FromInitial").setStartPoint( Ref branch = git.branchCreate().setName("FromInitial").setStartPoint(
initialCommit).call(); initialCommit).call();
@ -198,6 +208,7 @@ public class BranchCommandTest extends RepositoryTestCase {
assertEquals(secondCommit.getId(), branch.getObjectId()); assertEquals(secondCommit.getId(), branch.getObjectId());
} }
@Test
public void testCreateForce() throws Exception { public void testCreateForce() throws Exception {
// using commits // using commits
Ref newBranch = createBranch(git, "NewForce", false, secondCommit Ref newBranch = createBranch(git, "NewForce", false, secondCommit
@ -230,6 +241,7 @@ public class BranchCommandTest extends RepositoryTestCase {
assertEquals(newBranch.getTarget().getObjectId(), initialCommit.getId()); assertEquals(newBranch.getTarget().getObjectId(), initialCommit.getId());
} }
@Test
public void testDelete() throws Exception { public void testDelete() throws Exception {
createBranch(git, "ForDelete", false, "master", null); createBranch(git, "ForDelete", false, "master", null);
git.branchDelete().setBranchNames("ForDelete").call(); git.branchDelete().setBranchNames("ForDelete").call();
@ -274,6 +286,7 @@ public class BranchCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testPullConfigRemoteBranch() throws Exception { public void testPullConfigRemoteBranch() throws Exception {
Git localGit = setUpRepoWithRemote(); Git localGit = setUpRepoWithRemote();
Ref remote = localGit.branchList().setListMode(ListMode.REMOTE).call() Ref remote = localGit.branchList().setListMode(ListMode.REMOTE).call()
@ -305,6 +318,7 @@ public class BranchCommandTest extends RepositoryTestCase {
localGit.branchDelete().setBranchNames("newFromRemote").call(); localGit.branchDelete().setBranchNames("newFromRemote").call();
} }
@Test
public void testPullConfigLocalBranch() throws Exception { public void testPullConfigLocalBranch() throws Exception {
Git localGit = setUpRepoWithRemote(); Git localGit = setUpRepoWithRemote();
// by default, we should not create pull configuration // by default, we should not create pull configuration
@ -324,6 +338,7 @@ public class BranchCommandTest extends RepositoryTestCase {
"newFromRemote", "remote")); "newFromRemote", "remote"));
} }
@Test
public void testPullConfigRenameLocalBranch() throws Exception { public void testPullConfigRenameLocalBranch() throws Exception {
Git localGit = setUpRepoWithRemote(); Git localGit = setUpRepoWithRemote();
// by default, we should not create pull configuration // by default, we should not create pull configuration
@ -348,6 +363,7 @@ public class BranchCommandTest extends RepositoryTestCase {
"newFromRemote", "remote")); "newFromRemote", "remote"));
} }
@Test
public void testRenameLocalBranch() throws Exception { public void testRenameLocalBranch() throws Exception {
// null newName not allowed // null newName not allowed
try { try {
@ -402,6 +418,7 @@ public class BranchCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testRenameRemoteTrackingBranch() throws Exception { public void testRenameRemoteTrackingBranch() throws Exception {
Git localGit = setUpRepoWithRemote(); Git localGit = setUpRepoWithRemote();
Ref remoteBranch = localGit.branchList().setListMode(ListMode.REMOTE) Ref remoteBranch = localGit.branchList().setListMode(ListMode.REMOTE)
@ -412,6 +429,7 @@ public class BranchCommandTest extends RepositoryTestCase {
assertEquals(Constants.R_REMOTES + "newRemote", renamed.getName()); assertEquals(Constants.R_REMOTES + "newRemote", renamed.getName());
} }
@Test
public void testCreationImplicitStart() throws JGitInternalException, public void testCreationImplicitStart() throws JGitInternalException,
GitAPIException { GitAPIException {
git.branchCreate().setName("topic").call(); git.branchCreate().setName("topic").call();

19
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

@ -42,6 +42,13 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -57,6 +64,8 @@ import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
import org.junit.Test;
public class CheckoutCommandTest extends RepositoryTestCase { public class CheckoutCommandTest extends RepositoryTestCase {
private Git git; private Git git;
@ -66,7 +75,8 @@ public class CheckoutCommandTest extends RepositoryTestCase {
RevCommit secondCommit; RevCommit secondCommit;
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
git = new Git(db); git = new Git(db);
// commit something // commit something
@ -85,6 +95,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
secondCommit = git.commit().setMessage("Second commit").call(); secondCommit = git.commit().setMessage("Second commit").call();
} }
@Test
public void testSimpleCheckout() { public void testSimpleCheckout() {
try { try {
git.checkout().setName("test").call(); git.checkout().setName("test").call();
@ -93,6 +104,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testCheckout() { public void testCheckout() {
try { try {
git.checkout().setName("test").call(); git.checkout().setName("test").call();
@ -109,6 +121,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testCreateBranchOnCheckout() throws IOException { public void testCreateBranchOnCheckout() throws IOException {
try { try {
git.checkout().setCreateBranch(true).setName("test2").call(); git.checkout().setCreateBranch(true).setName("test2").call();
@ -118,6 +131,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
assertNotNull(db.getRef("test2")); assertNotNull(db.getRef("test2"));
} }
@Test
public void testCheckoutToNonExistingBranch() throws JGitInternalException, public void testCheckoutToNonExistingBranch() throws JGitInternalException,
RefAlreadyExistsException, InvalidRefNameException { RefAlreadyExistsException, InvalidRefNameException {
try { try {
@ -128,6 +142,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testCheckoutWithConflict() { public void testCheckoutWithConflict() {
CheckoutCommand co = git.checkout(); CheckoutCommand co = git.checkout();
try { try {
@ -141,6 +156,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testCheckoutWithNonDeletedFiles() throws Exception { public void testCheckoutWithNonDeletedFiles() throws Exception {
File testFile = writeTrashFile("temp", ""); File testFile = writeTrashFile("temp", "");
FileInputStream fis = new FileInputStream(testFile); FileInputStream fis = new FileInputStream(testFile);
@ -176,6 +192,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testCheckoutCommit() { public void testCheckoutCommit() {
try { try {
Ref result = git.checkout().setName(initialCommit.name()).call(); Ref result = git.checkout().setName(initialCommit.name()).call();

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java

@ -42,22 +42,28 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.jgit.api.errors.*; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
/** /**
* Test cherry-pick command * Test cherry-pick command
*/ */
public class CherryPickCommandTest extends RepositoryTestCase { public class CherryPickCommandTest extends RepositoryTestCase {
@Test
public void testCherryPick() throws IOException, JGitInternalException, public void testCherryPick() throws IOException, JGitInternalException,
GitAPIException { GitAPIException {
Git git = new Git(db); Git git = new Git(db);

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java

@ -42,6 +42,10 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java

@ -42,6 +42,8 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -55,9 +57,11 @@ import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Test;
public class FetchCommandTest extends RepositoryTestCase { public class FetchCommandTest extends RepositoryTestCase {
@Test
public void testFetch() throws JGitInternalException, IOException, public void testFetch() throws JGitInternalException, IOException,
GitAPIException, URISyntaxException { GitAPIException, URISyntaxException {

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java

@ -42,19 +42,27 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Before;
import org.junit.Test;
public class InitCommandTest extends RepositoryTestCase { public class InitCommandTest extends RepositoryTestCase {
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
} }
@Test
public void testInitRepository() { public void testInitRepository() {
try { try {
File directory = createTempDirectory("testInitRepository"); File directory = createTempDirectory("testInitRepository");
@ -67,6 +75,7 @@ public class InitCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testInitBareRepository() { public void testInitBareRepository() {
try { try {
File directory = createTempDirectory("testInitBareRepository"); File directory = createTempDirectory("testInitBareRepository");

22
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -43,6 +43,11 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
@ -58,8 +63,10 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class MergeCommandTest extends RepositoryTestCase { public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testMergeInItself() throws Exception { public void testMergeInItself() throws Exception {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
@ -68,6 +75,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
} }
@Test
public void testAlreadyUpToDate() throws Exception { public void testAlreadyUpToDate() throws Exception {
Git git = new Git(db); Git git = new Git(db);
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
@ -80,6 +88,7 @@ public class MergeCommandTest extends RepositoryTestCase {
} }
@Test
public void testFastForward() throws Exception { public void testFastForward() throws Exception {
Git git = new Git(db); Git git = new Git(db);
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
@ -95,6 +104,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
} }
@Test
public void testFastForwardWithFiles() throws Exception { public void testFastForwardWithFiles() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -121,6 +131,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
} }
@Test
public void testMultipleHeads() throws Exception { public void testMultipleHeads() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -153,6 +164,7 @@ public class MergeCommandTest extends RepositoryTestCase {
} }
@Test
public void testContentMerge() throws Exception { public void testContentMerge() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -197,6 +209,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); assertEquals(RepositoryState.MERGING, db.getRepositoryState());
} }
@Test
public void testMergeNonVersionedPaths() throws Exception { public void testMergeNonVersionedPaths() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -247,6 +260,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); assertEquals(RepositoryState.MERGING, db.getRepositoryState());
} }
@Test
public void testMultipleCreations() throws Exception { public void testMultipleCreations() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -272,6 +286,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
} }
@Test
public void testMultipleCreationsSameContent() throws Exception { public void testMultipleCreationsSameContent() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -298,6 +313,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals("1\nb(1)\n3\n", read(new File(db.getWorkTree(), "b"))); assertEquals("1\nb(1)\n3\n", read(new File(db.getWorkTree(), "b")));
} }
@Test
public void testSuccessfulContentMerge() throws Exception { public void testSuccessfulContentMerge() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -355,6 +371,7 @@ public class MergeCommandTest extends RepositoryTestCase {
// test index state // test index state
} }
@Test
public void testSuccessfulContentMergeAndDirtyworkingTree() public void testSuccessfulContentMergeAndDirtyworkingTree()
throws Exception { throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -414,6 +431,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
@Test
public void testSingleDeletion() throws Exception { public void testSingleDeletion() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -466,6 +484,7 @@ public class MergeCommandTest extends RepositoryTestCase {
read(new File(db.getWorkTree(), "c/c/c"))); read(new File(db.getWorkTree(), "c/c/c")));
} }
@Test
public void testMultipleDeletions() throws Exception { public void testMultipleDeletions() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -494,6 +513,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
} }
@Test
public void testDeletionAndConflict() throws Exception { public void testDeletionAndConflict() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -536,6 +556,7 @@ public class MergeCommandTest extends RepositoryTestCase {
read(new File(db.getWorkTree(), "c/c/c"))); read(new File(db.getWorkTree(), "c/c/c")));
} }
@Test
public void testMergeFailingWithDirtyWorkingTree() throws Exception { public void testMergeFailingWithDirtyWorkingTree() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -574,6 +595,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
@Test
public void testMergeConflictFileFolder() throws Exception { public void testMergeConflictFileFolder() throws Exception {
Git git = new Git(db); Git git = new Git(db);

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java

@ -42,6 +42,11 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -59,6 +64,8 @@ import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
public class PullCommandTest extends RepositoryTestCase { public class PullCommandTest extends RepositoryTestCase {
/** Second Test repository */ /** Second Test repository */
@ -72,6 +79,7 @@ public class PullCommandTest extends RepositoryTestCase {
private File targetFile; private File targetFile;
@Test
public void testPullFastForward() throws Exception { public void testPullFastForward() throws Exception {
PullResult res = target.pull().call(); PullResult res = target.pull().call();
// nothing to update since we don't have different data yet // nothing to update since we don't have different data yet
@ -94,6 +102,7 @@ public class PullCommandTest extends RepositoryTestCase {
assertFileContentsEqual(targetFile, "Another change"); assertFileContentsEqual(targetFile, "Another change");
} }
@Test
public void testPullConflict() throws Exception { public void testPullConflict() throws Exception {
PullResult res = target.pull().call(); PullResult res = target.pull().call();
// nothing to update since we don't have different data yet // nothing to update since we don't have different data yet
@ -127,6 +136,7 @@ public class PullCommandTest extends RepositoryTestCase {
assertFileContentsEqual(targetFile, result); assertFileContentsEqual(targetFile, result);
} }
@Test
public void testPullLocalConflict() throws Exception { public void testPullLocalConflict() throws Exception {
target.branchCreate().setName("basedOnMaster").setStartPoint( target.branchCreate().setName("basedOnMaster").setStartPoint(
"refs/heads/master").setUpstreamMode(SetupUpstreamMode.TRACK) "refs/heads/master").setUpstreamMode(SetupUpstreamMode.TRACK)
@ -168,7 +178,8 @@ public class PullCommandTest extends RepositoryTestCase {
} }
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
dbTarget = createWorkRepository(); dbTarget = createWorkRepository();
source = new Git(db); source = new Git(db);

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java

@ -42,6 +42,9 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -56,9 +59,11 @@ import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
import org.junit.Test;
public class PushCommandTest extends RepositoryTestCase { public class PushCommandTest extends RepositoryTestCase {
@Test
public void testPush() throws JGitInternalException, IOException, public void testPush() throws JGitInternalException, IOException,
GitAPIException, URISyntaxException { GitAPIException, URISyntaxException {

29
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java

@ -42,6 +42,12 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -63,6 +69,8 @@ import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Before;
import org.junit.Test;
public class RebaseCommandTest extends RepositoryTestCase { public class RebaseCommandTest extends RepositoryTestCase {
private static final String FILE1 = "file1"; private static final String FILE1 = "file1";
@ -70,7 +78,8 @@ public class RebaseCommandTest extends RepositoryTestCase {
protected Git git; protected Git git;
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
this.git = new Git(db); this.git = new Git(db);
} }
@ -112,6 +121,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
refUpdate.forceUpdate(); refUpdate.forceUpdate();
} }
@Test
public void testFastForwardWithNewFile() throws Exception { public void testFastForwardWithNewFile() throws Exception {
// create file1 on master // create file1 on master
writeTrashFile(FILE1, FILE1); writeTrashFile(FILE1, FILE1);
@ -134,6 +144,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(Status.UP_TO_DATE, res.getStatus()); assertEquals(Status.UP_TO_DATE, res.getStatus());
} }
@Test
public void testUpToDate() throws Exception { public void testUpToDate() throws Exception {
// create file1 on master // create file1 on master
writeTrashFile(FILE1, FILE1); writeTrashFile(FILE1, FILE1);
@ -146,6 +157,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(Status.UP_TO_DATE, res.getStatus()); assertEquals(Status.UP_TO_DATE, res.getStatus());
} }
@Test
public void testUnknownUpstream() throws Exception { public void testUnknownUpstream() throws Exception {
// create file1 on master // create file1 on master
writeTrashFile(FILE1, FILE1); writeTrashFile(FILE1, FILE1);
@ -162,6 +174,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testConflictFreeWithSingleFile() throws Exception { public void testConflictFreeWithSingleFile() throws Exception {
// create file1 on master // create file1 on master
File theFile = writeTrashFile(FILE1, "1\n2\n3\n"); File theFile = writeTrashFile(FILE1, "1\n2\n3\n");
@ -196,6 +209,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
db.resolve(Constants.HEAD)).getParent(0)); db.resolve(Constants.HEAD)).getParent(0));
} }
@Test
public void testDetachedHead() throws Exception { public void testDetachedHead() throws Exception {
// create file1 on master // create file1 on master
File theFile = writeTrashFile(FILE1, "1\n2\n3\n"); File theFile = writeTrashFile(FILE1, "1\n2\n3\n");
@ -233,6 +247,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
} }
@Test
public void testFilesAddedFromTwoBranches() throws Exception { public void testFilesAddedFromTwoBranches() throws Exception {
// create file1 on master // create file1 on master
writeTrashFile(FILE1, FILE1); writeTrashFile(FILE1, FILE1);
@ -277,6 +292,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertFalse(new File(db.getWorkTree(), "file3").exists()); assertFalse(new File(db.getWorkTree(), "file3").exists());
} }
@Test
public void testStopOnConflict() throws Exception { public void testStopOnConflict() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -336,6 +352,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertFalse(new File(db.getDirectory(), "rebase-merge").exists()); assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
} }
@Test
public void testStopOnConflictAndContinue() throws Exception { public void testStopOnConflictAndContinue() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -390,6 +407,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
.getFullMessage()); .getFullMessage());
} }
@Test
public void testStopOnConflictAndFailContinueIfFileIsDirty() public void testStopOnConflictAndFailContinueIfFileIsDirty()
throws Exception { throws Exception {
// create file1 on master // create file1 on master
@ -430,6 +448,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
checkFile(trashFile, "Some local change"); checkFile(trashFile, "Some local change");
} }
@Test
public void testStopOnLastConflictAndContinue() throws Exception { public void testStopOnLastConflictAndContinue() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -465,6 +484,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
@Test
public void testStopOnLastConflictAndSkip() throws Exception { public void testStopOnLastConflictAndSkip() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -500,6 +520,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
@Test
public void testMergeFirstStopOnLastConflictAndSkip() throws Exception { public void testMergeFirstStopOnLastConflictAndSkip() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -538,6 +559,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
checkFile(FILE1, "merged"); checkFile(FILE1, "merged");
} }
@Test
public void testStopOnConflictAndSkipNoConflict() throws Exception { public void testStopOnConflictAndSkipNoConflict() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -574,6 +596,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(Status.OK, res.getStatus()); assertEquals(Status.OK, res.getStatus());
} }
@Test
public void testStopOnConflictAndSkipWithConflict() throws Exception { public void testStopOnConflictAndSkipWithConflict() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -612,6 +635,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(Status.STOPPED, res.getStatus()); assertEquals(Status.STOPPED, res.getStatus());
} }
@Test
public void testStopOnConflictCommitAndContinue() throws Exception { public void testStopOnConflictCommitAndContinue() throws Exception {
// create file1 on master // create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@ -699,6 +723,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
checkFile(file, sb.toString()); checkFile(file, sb.toString());
} }
@Test
public void testStopOnConflictFileCreationAndDeletion() throws Exception { public void testStopOnConflictFileCreationAndDeletion() throws Exception {
// create file1 on master // create file1 on master
writeTrashFile(FILE1, "Hello World"); writeTrashFile(FILE1, "Hello World");
@ -786,6 +811,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
} }
@Test
public void testAuthorScriptConverter() throws Exception { public void testAuthorScriptConverter() throws Exception {
// -1 h timezone offset // -1 h timezone offset
PersonIdent ident = new PersonIdent("Author name", "a.mail@some.com", PersonIdent ident = new PersonIdent("Author name", "a.mail@some.com",
@ -821,6 +847,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(ident.getTimeZoneOffset(), parsedIdent.getTimeZoneOffset()); assertEquals(ident.getTimeZoneOffset(), parsedIdent.getTimeZoneOffset());
} }
@Test
public void testRepositoryStateChecks() throws Exception { public void testRepositoryStateChecks() throws Exception {
try { try {
git.rebase().setOperation(Operation.ABORT).call(); git.rebase().setOperation(Operation.ABORT).call();

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java

@ -42,11 +42,15 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Before;
import org.junit.Test;
public class RmCommandTest extends RepositoryTestCase { public class RmCommandTest extends RepositoryTestCase {
@ -55,7 +59,8 @@ public class RmCommandTest extends RepositoryTestCase {
private static final String FILE = "test.txt"; private static final String FILE = "test.txt";
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
git = new Git(db); git = new Git(db);
// commit something // commit something
@ -64,6 +69,7 @@ public class RmCommandTest extends RepositoryTestCase {
git.commit().setMessage("Initial commit").call(); git.commit().setMessage("Initial commit").call();
} }
@Test
public void testRemove() throws JGitInternalException, public void testRemove() throws JGitInternalException,
NoFilepatternException, IllegalStateException, IOException { NoFilepatternException, IllegalStateException, IOException {
assertEquals("[test.txt, mode:100644, content:Hello world]", assertEquals("[test.txt, mode:100644, content:Hello world]",

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java

@ -42,6 +42,9 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.InvalidTagNameException; import org.eclipse.jgit.api.errors.InvalidTagNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
@ -52,9 +55,11 @@ import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevTag;
import org.junit.Test;
public class TagCommandTest extends RepositoryTestCase { public class TagCommandTest extends RepositoryTestCase {
@Test
public void testTaggingOnHead() throws NoHeadException, NoMessageException, public void testTaggingOnHead() throws NoHeadException, NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException, UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException, JGitInternalException, WrongRepositoryStateException,
@ -65,6 +70,7 @@ public class TagCommandTest extends RepositoryTestCase {
assertEquals(commit.getId(), tag.getObject().getId()); assertEquals(commit.getId(), tag.getObject().getId());
} }
@Test
public void testTagging() throws NoHeadException, NoMessageException, public void testTagging() throws NoHeadException, NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException, UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException, JGitInternalException, WrongRepositoryStateException,
@ -77,6 +83,7 @@ public class TagCommandTest extends RepositoryTestCase {
assertEquals(commit.getId(), tag.getObject().getId()); assertEquals(commit.getId(), tag.getObject().getId());
} }
@Test
public void testEmptyTagName() throws NoHeadException, NoMessageException, public void testEmptyTagName() throws NoHeadException, NoMessageException,
UnmergedPathException, ConcurrentRefUpdateException, UnmergedPathException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException { JGitInternalException, WrongRepositoryStateException {
@ -91,6 +98,7 @@ public class TagCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testInvalidTagName() throws NoHeadException, public void testInvalidTagName() throws NoHeadException,
NoMessageException, UnmergedPathException, NoMessageException, UnmergedPathException,
ConcurrentRefUpdateException, JGitInternalException, ConcurrentRefUpdateException, JGitInternalException,
@ -105,6 +113,7 @@ public class TagCommandTest extends RepositoryTestCase {
} }
} }
@Test
public void testFailureOnSignedTags() throws NoHeadException, public void testFailureOnSignedTags() throws NoHeadException,
NoMessageException, UnmergedPathException, NoMessageException, UnmergedPathException,
ConcurrentRefUpdateException, JGitInternalException, ConcurrentRefUpdateException, JGitInternalException,

26
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java

@ -43,76 +43,91 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import junit.framework.TestCase; import org.junit.Test;
public abstract class AbstractDiffTestCase extends TestCase { public abstract class AbstractDiffTestCase {
@Test
public void testEmptyInputs() { public void testEmptyInputs() {
EditList r = diff(t(""), t("")); EditList r = diff(t(""), t(""));
assertTrue("is empty", r.isEmpty()); assertTrue("is empty", r.isEmpty());
} }
@Test
public void testCreateFile() { public void testCreateFile() {
EditList r = diff(t(""), t("AB")); EditList r = diff(t(""), t("AB"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(0, 0, 0, 2), r.get(0)); assertEquals(new Edit(0, 0, 0, 2), r.get(0));
} }
@Test
public void testDeleteFile() { public void testDeleteFile() {
EditList r = diff(t("AB"), t("")); EditList r = diff(t("AB"), t(""));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(0, 2, 0, 0), r.get(0)); assertEquals(new Edit(0, 2, 0, 0), r.get(0));
} }
@Test
public void testDegenerate_InsertMiddle() { public void testDegenerate_InsertMiddle() {
EditList r = diff(t("ac"), t("aBc")); EditList r = diff(t("ac"), t("aBc"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(1, 1, 1, 2), r.get(0)); assertEquals(new Edit(1, 1, 1, 2), r.get(0));
} }
@Test
public void testDegenerate_DeleteMiddle() { public void testDegenerate_DeleteMiddle() {
EditList r = diff(t("aBc"), t("ac")); EditList r = diff(t("aBc"), t("ac"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(1, 2, 1, 1), r.get(0)); assertEquals(new Edit(1, 2, 1, 1), r.get(0));
} }
@Test
public void testDegenerate_ReplaceMiddle() { public void testDegenerate_ReplaceMiddle() {
EditList r = diff(t("bCd"), t("bEd")); EditList r = diff(t("bCd"), t("bEd"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(1, 2, 1, 2), r.get(0)); assertEquals(new Edit(1, 2, 1, 2), r.get(0));
} }
@Test
public void testDegenerate_InsertsIntoMidPosition() { public void testDegenerate_InsertsIntoMidPosition() {
EditList r = diff(t("aaaa"), t("aaXaa")); EditList r = diff(t("aaaa"), t("aaXaa"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(2, 2, 2, 3), r.get(0)); assertEquals(new Edit(2, 2, 2, 3), r.get(0));
} }
@Test
public void testDegenerate_InsertStart() { public void testDegenerate_InsertStart() {
EditList r = diff(t("bc"), t("Abc")); EditList r = diff(t("bc"), t("Abc"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(0, 0, 0, 1), r.get(0)); assertEquals(new Edit(0, 0, 0, 1), r.get(0));
} }
@Test
public void testDegenerate_DeleteStart() { public void testDegenerate_DeleteStart() {
EditList r = diff(t("Abc"), t("bc")); EditList r = diff(t("Abc"), t("bc"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(0, 1, 0, 0), r.get(0)); assertEquals(new Edit(0, 1, 0, 0), r.get(0));
} }
@Test
public void testDegenerate_InsertEnd() { public void testDegenerate_InsertEnd() {
EditList r = diff(t("bc"), t("bcD")); EditList r = diff(t("bc"), t("bcD"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(2, 2, 2, 3), r.get(0)); assertEquals(new Edit(2, 2, 2, 3), r.get(0));
} }
@Test
public void testDegenerate_DeleteEnd() { public void testDegenerate_DeleteEnd() {
EditList r = diff(t("bcD"), t("bc")); EditList r = diff(t("bcD"), t("bc"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(2, 3, 2, 2), r.get(0)); assertEquals(new Edit(2, 3, 2, 2), r.get(0));
} }
@Test
public void testEdit_ReplaceCommonDelete() { public void testEdit_ReplaceCommonDelete() {
EditList r = diff(t("RbC"), t("Sb")); EditList r = diff(t("RbC"), t("Sb"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -120,6 +135,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(2, 3, 2, 2), r.get(1)); assertEquals(new Edit(2, 3, 2, 2), r.get(1));
} }
@Test
public void testEdit_CommonReplaceCommonDeleteCommon() { public void testEdit_CommonReplaceCommonDeleteCommon() {
EditList r = diff(t("aRbCd"), t("aSbd")); EditList r = diff(t("aRbCd"), t("aSbd"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -127,6 +143,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(3, 4, 3, 3), r.get(1)); assertEquals(new Edit(3, 4, 3, 3), r.get(1));
} }
@Test
public void testEdit_MoveBlock() { public void testEdit_MoveBlock() {
EditList r = diff(t("aYYbcdz"), t("abcdYYz")); EditList r = diff(t("aYYbcdz"), t("abcdYYz"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -134,6 +151,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(6, 6, 4, 6), r.get(1)); assertEquals(new Edit(6, 6, 4, 6), r.get(1));
} }
@Test
public void testEdit_InvertBlocks() { public void testEdit_InvertBlocks() {
EditList r = diff(t("aYYbcdXXz"), t("aXXbcdYYz")); EditList r = diff(t("aYYbcdXXz"), t("aXXbcdYYz"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -141,6 +159,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(6, 8, 6, 8), r.get(1)); assertEquals(new Edit(6, 8, 6, 8), r.get(1));
} }
@Test
public void testEdit_UniqueCommonLargerThanMatchPoint() { public void testEdit_UniqueCommonLargerThanMatchPoint() {
// We are testing 3 unique common matches, but two of // We are testing 3 unique common matches, but two of
// them are consumed as part of the 1st's LCS region. // them are consumed as part of the 1st's LCS region.
@ -150,6 +169,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(4, 5, 4, 6), r.get(1)); assertEquals(new Edit(4, 5, 4, 6), r.get(1));
} }
@Test
public void testEdit_CommonGrowsPrefixAndSuffix() { public void testEdit_CommonGrowsPrefixAndSuffix() {
// Here there is only one common unique point, but we can grow it // Here there is only one common unique point, but we can grow it
// in both directions to find the LCS in the middle. // in both directions to find the LCS in the middle.
@ -159,6 +179,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(6, 7, 6, 7), r.get(1)); assertEquals(new Edit(6, 7, 6, 7), r.get(1));
} }
@Test
public void testEdit_DuplicateAButCommonUniqueInB() { public void testEdit_DuplicateAButCommonUniqueInB() {
EditList r = diff(t("AbbcR"), t("CbcS")); EditList r = diff(t("AbbcR"), t("CbcS"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -166,6 +187,7 @@ public abstract class AbstractDiffTestCase extends TestCase {
assertEquals(new Edit(4, 5, 3, 4), r.get(1)); assertEquals(new Edit(4, 5, 3, 4), r.get(1));
} }
@Test
public void testEdit_InsertNearCommonTail() { public void testEdit_InsertNearCommonTail() {
EditList r = diff(t("aq}nb"), t("aCq}nD}nb")); EditList r = diff(t("aq}nb"), t("aCq}nD}nb"));
assertEquals(new Edit(1, 1, 1, 2), r.get(0)); assertEquals(new Edit(1, 1, 1, 2), r.get(0));

26
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java

@ -44,17 +44,21 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import junit.framework.TestCase; import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.patch.FileHeader; import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.Patch; import org.eclipse.jgit.patch.Patch;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
import org.junit.Before;
import org.junit.Test;
public class DiffFormatterReflowTest extends TestCase { public class DiffFormatterReflowTest {
private RawText a; private RawText a;
private RawText b; private RawText b;
@ -65,12 +69,13 @@ public class DiffFormatterReflowTest extends TestCase {
private DiffFormatter fmt; private DiffFormatter fmt;
protected void setUp() throws Exception { @Before
super.setUp(); public void setUp() throws Exception {
out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream();
fmt = new DiffFormatter(out); fmt = new DiffFormatter(out);
} }
@Test
public void testNegativeContextFails() throws IOException { public void testNegativeContextFails() throws IOException {
init("X"); init("X");
try { try {
@ -81,52 +86,61 @@ public class DiffFormatterReflowTest extends TestCase {
} }
} }
@Test
public void testContext0() throws IOException { public void testContext0() throws IOException {
init("X"); init("X");
fmt.setContext(0); fmt.setContext(0);
assertFormatted(); assertFormatted();
} }
@Test
public void testContext1() throws IOException { public void testContext1() throws IOException {
init("X"); init("X");
fmt.setContext(1); fmt.setContext(1);
assertFormatted(); assertFormatted();
} }
@Test
public void testContext3() throws IOException { public void testContext3() throws IOException {
init("X"); init("X");
fmt.setContext(3); fmt.setContext(3);
assertFormatted(); assertFormatted();
} }
@Test
public void testContext5() throws IOException { public void testContext5() throws IOException {
init("X"); init("X");
fmt.setContext(5); fmt.setContext(5);
assertFormatted(); assertFormatted();
} }
@Test
public void testContext10() throws IOException { public void testContext10() throws IOException {
init("X"); init("X");
fmt.setContext(10); fmt.setContext(10);
assertFormatted(); assertFormatted();
} }
@Test
public void testContext100() throws IOException { public void testContext100() throws IOException {
init("X"); init("X");
fmt.setContext(100); fmt.setContext(100);
assertFormatted(); assertFormatted();
} }
@Test
public void testEmpty1() throws IOException { public void testEmpty1() throws IOException {
init("E"); init("E");
assertFormatted("E.patch"); assertFormatted("E.patch");
} }
@Test
public void testNoNewLine1() throws IOException { public void testNoNewLine1() throws IOException {
init("Y"); init("Y");
assertFormatted("Y.patch"); assertFormatted("Y.patch");
} }
@Test
public void testNoNewLine2() throws IOException { public void testNoNewLine2() throws IOException {
init("Z"); init("Z");
assertFormatted("Z.patch"); assertFormatted("Z.patch");
@ -139,7 +153,7 @@ public class DiffFormatterReflowTest extends TestCase {
} }
private void assertFormatted() throws IOException { private void assertFormatted() throws IOException {
assertFormatted(getName() + ".out"); assertFormatted(JGitTestUtil.getName() + ".out");
} }
private void assertFormatted(final String name) throws IOException { private void assertFormatted(final String name) throws IOException {

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
@ -52,6 +54,9 @@ import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.HunkHeader; import org.eclipse.jgit.patch.HunkHeader;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.io.DisabledOutputStream; import org.eclipse.jgit.util.io.DisabledOutputStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class DiffFormatterTest extends RepositoryTestCase { public class DiffFormatterTest extends RepositoryTestCase {
private static final String DIFF = "diff --git "; private static final String DIFF = "diff --git ";
@ -69,6 +74,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
private TestRepository testDb; private TestRepository testDb;
@Override @Override
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
testDb = new TestRepository(db); testDb = new TestRepository(db);
@ -78,12 +84,14 @@ public class DiffFormatterTest extends RepositoryTestCase {
} }
@Override @Override
@After
public void tearDown() throws Exception { public void tearDown() throws Exception {
if (df != null) if (df != null)
df.release(); df.release();
super.tearDown(); super.tearDown();
} }
@Test
public void testCreateFileHeader_Add() throws Exception { public void testCreateFileHeader_Add() throws Exception {
ObjectId adId = blob("a\nd\n"); ObjectId adId = blob("a\nd\n");
DiffEntry ent = DiffEntry.add("FOO", adId); DiffEntry ent = DiffEntry.add("FOO", adId);
@ -119,6 +127,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
assertEquals(Edit.Type.INSERT, e.getType()); assertEquals(Edit.Type.INSERT, e.getType());
} }
@Test
public void testCreateFileHeader_Delete() throws Exception { public void testCreateFileHeader_Delete() throws Exception {
ObjectId adId = blob("a\nd\n"); ObjectId adId = blob("a\nd\n");
DiffEntry ent = DiffEntry.delete("FOO", adId); DiffEntry ent = DiffEntry.delete("FOO", adId);
@ -154,6 +163,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
assertEquals(Edit.Type.DELETE, e.getType()); assertEquals(Edit.Type.DELETE, e.getType());
} }
@Test
public void testCreateFileHeader_Modify() throws Exception { public void testCreateFileHeader_Modify() throws Exception {
ObjectId adId = blob("a\nd\n"); ObjectId adId = blob("a\nd\n");
ObjectId abcdId = blob("a\nb\nc\nd\n"); ObjectId abcdId = blob("a\nb\nc\nd\n");
@ -188,6 +198,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
assertEquals(Edit.Type.INSERT, e.getType()); assertEquals(Edit.Type.INSERT, e.getType());
} }
@Test
public void testCreateFileHeader_Binary() throws Exception { public void testCreateFileHeader_Binary() throws Exception {
ObjectId adId = blob("a\nd\n"); ObjectId adId = blob("a\nd\n");
ObjectId binId = blob("a\nb\nc\n\0\0\0\0d\n"); ObjectId binId = blob("a\nb\nc\n\0\0\0\0d\n");
@ -211,6 +222,7 @@ public class DiffFormatterTest extends RepositoryTestCase {
assertEquals(0, hh.toEditList().size()); assertEquals(0, hh.toEditList().size());
} }
@Test
public void testCreateFileHeader_GitLink() throws Exception { public void testCreateFileHeader_GitLink() throws Exception {
ObjectId aId = blob("a\n"); ObjectId aId = blob("a\n");
ObjectId bId = blob("b\n"); ObjectId bId = blob("b\n");

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java

@ -43,11 +43,17 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.TestCase; import org.junit.Test;
public class EditListTest extends TestCase { public class EditListTest {
@Test
public void testEmpty() { public void testEmpty() {
final EditList l = new EditList(); final EditList l = new EditList();
assertEquals(0, l.size()); assertEquals(0, l.size());
@ -60,6 +66,7 @@ public class EditListTest extends TestCase {
assertEquals(l.hashCode(), new EditList().hashCode()); assertEquals(l.hashCode(), new EditList().hashCode());
} }
@Test
public void testAddOne() { public void testAddOne() {
final Edit e = new Edit(1, 2, 1, 1); final Edit e = new Edit(1, 2, 1, 1);
final EditList l = new EditList(); final EditList l = new EditList();
@ -79,6 +86,7 @@ public class EditListTest extends TestCase {
assertEquals(l.hashCode(), l2.hashCode()); assertEquals(l.hashCode(), l2.hashCode());
} }
@Test
public void testAddTwo() { public void testAddTwo() {
final Edit e1 = new Edit(1, 2, 1, 1); final Edit e1 = new Edit(1, 2, 1, 1);
final Edit e2 = new Edit(8, 8, 8, 12); final Edit e2 = new Edit(8, 8, 8, 12);
@ -104,6 +112,7 @@ public class EditListTest extends TestCase {
assertEquals(l.hashCode(), l2.hashCode()); assertEquals(l.hashCode(), l2.hashCode());
} }
@Test
public void testSet() { public void testSet() {
final Edit e1 = new Edit(1, 2, 1, 1); final Edit e1 = new Edit(1, 2, 1, 1);
final Edit e2 = new Edit(3, 4, 3, 3); final Edit e2 = new Edit(3, 4, 3, 3);
@ -114,6 +123,7 @@ public class EditListTest extends TestCase {
assertSame(e2, l.get(0)); assertSame(e2, l.get(0));
} }
@Test
public void testRemove() { public void testRemove() {
final Edit e1 = new Edit(1, 2, 1, 1); final Edit e1 = new Edit(1, 2, 1, 1);
final Edit e2 = new Edit(8, 8, 8, 12); final Edit e2 = new Edit(8, 8, 8, 12);

25
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java

@ -44,9 +44,15 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class EditTest extends TestCase { import org.junit.Test;
public class EditTest {
@Test
public void testCreate() { public void testCreate() {
final Edit e = new Edit(1, 2, 3, 4); final Edit e = new Edit(1, 2, 3, 4);
assertEquals(1, e.getBeginA()); assertEquals(1, e.getBeginA());
@ -55,6 +61,7 @@ public class EditTest extends TestCase {
assertEquals(4, e.getEndB()); assertEquals(4, e.getEndB());
} }
@Test
public void testCreateEmpty() { public void testCreateEmpty() {
final Edit e = new Edit(1, 3); final Edit e = new Edit(1, 3);
assertEquals(1, e.getBeginA()); assertEquals(1, e.getBeginA());
@ -65,6 +72,7 @@ public class EditTest extends TestCase {
assertSame(Edit.Type.EMPTY, e.getType()); assertSame(Edit.Type.EMPTY, e.getType());
} }
@Test
public void testSwap() { public void testSwap() {
final Edit e = new Edit(1, 2, 3, 4); final Edit e = new Edit(1, 2, 3, 4);
e.swap(); e.swap();
@ -74,6 +82,7 @@ public class EditTest extends TestCase {
assertEquals(2, e.getEndB()); assertEquals(2, e.getEndB());
} }
@Test
public void testType_Insert() { public void testType_Insert() {
final Edit e = new Edit(1, 1, 1, 2); final Edit e = new Edit(1, 1, 1, 2);
assertSame(Edit.Type.INSERT, e.getType()); assertSame(Edit.Type.INSERT, e.getType());
@ -82,6 +91,7 @@ public class EditTest extends TestCase {
assertEquals(1, e.getLengthB()); assertEquals(1, e.getLengthB());
} }
@Test
public void testType_Delete() { public void testType_Delete() {
final Edit e = new Edit(1, 2, 1, 1); final Edit e = new Edit(1, 2, 1, 1);
assertSame(Edit.Type.DELETE, e.getType()); assertSame(Edit.Type.DELETE, e.getType());
@ -90,6 +100,7 @@ public class EditTest extends TestCase {
assertEquals(0, e.getLengthB()); assertEquals(0, e.getLengthB());
} }
@Test
public void testType_Replace() { public void testType_Replace() {
final Edit e = new Edit(1, 2, 1, 4); final Edit e = new Edit(1, 2, 1, 4);
assertSame(Edit.Type.REPLACE, e.getType()); assertSame(Edit.Type.REPLACE, e.getType());
@ -98,6 +109,7 @@ public class EditTest extends TestCase {
assertEquals(3, e.getLengthB()); assertEquals(3, e.getLengthB());
} }
@Test
public void testType_Empty() { public void testType_Empty() {
final Edit e = new Edit(1, 1, 2, 2); final Edit e = new Edit(1, 1, 2, 2);
assertSame(Edit.Type.EMPTY, e.getType()); assertSame(Edit.Type.EMPTY, e.getType());
@ -107,11 +119,13 @@ public class EditTest extends TestCase {
assertEquals(0, e.getLengthB()); assertEquals(0, e.getLengthB());
} }
@Test
public void testToString() { public void testToString() {
final Edit e = new Edit(1, 2, 1, 4); final Edit e = new Edit(1, 2, 1, 4);
assertEquals("REPLACE(1-2,1-4)", e.toString()); assertEquals("REPLACE(1-2,1-4)", e.toString());
} }
@Test
public void testEquals1() { public void testEquals1() {
final Edit e1 = new Edit(1, 2, 3, 4); final Edit e1 = new Edit(1, 2, 3, 4);
final Edit e2 = new Edit(1, 2, 3, 4); final Edit e2 = new Edit(1, 2, 3, 4);
@ -123,22 +137,27 @@ public class EditTest extends TestCase {
assertFalse(e1.equals("")); assertFalse(e1.equals(""));
} }
@Test
public void testNotEquals1() { public void testNotEquals1() {
assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(0, 2, 3, 4))); assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(0, 2, 3, 4)));
} }
@Test
public void testNotEquals2() { public void testNotEquals2() {
assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 0, 3, 4))); assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 0, 3, 4)));
} }
@Test
public void testNotEquals3() { public void testNotEquals3() {
assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 0, 4))); assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 0, 4)));
} }
@Test
public void testNotEquals4() { public void testNotEquals4() {
assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 3, 0))); assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 3, 0)));
} }
@Test
public void testExtendA() { public void testExtendA() {
final Edit e = new Edit(1, 2, 1, 1); final Edit e = new Edit(1, 2, 1, 1);
@ -149,6 +168,7 @@ public class EditTest extends TestCase {
assertEquals(new Edit(1, 4, 1, 1), e); assertEquals(new Edit(1, 4, 1, 1), e);
} }
@Test
public void testExtendB() { public void testExtendB() {
final Edit e = new Edit(1, 2, 1, 1); final Edit e = new Edit(1, 2, 1, 1);
@ -159,6 +179,7 @@ public class EditTest extends TestCase {
assertEquals(new Edit(1, 2, 1, 3), e); assertEquals(new Edit(1, 2, 1, 3), e);
} }
@Test
public void testBeforeAfterCuts() { public void testBeforeAfterCuts() {
final Edit whole = new Edit(1, 8, 2, 9); final Edit whole = new Edit(1, 8, 2, 9);
final Edit mid = new Edit(4, 5, 3, 6); final Edit mid = new Edit(4, 5, 3, 6);

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java

@ -43,6 +43,10 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class HistogramDiffTest extends AbstractDiffTestCase { public class HistogramDiffTest extends AbstractDiffTestCase {
@Override @Override
@ -52,6 +56,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase {
return hd; return hd;
} }
@Test
public void testEdit_NoUniqueMiddleSide_FlipBlocks() { public void testEdit_NoUniqueMiddleSide_FlipBlocks() {
EditList r = diff(t("aRRSSz"), t("aSSRRz")); EditList r = diff(t("aRRSSz"), t("aSSRRz"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -59,12 +64,14 @@ public class HistogramDiffTest extends AbstractDiffTestCase {
assertEquals(new Edit(5, 5, 3, 5), r.get(1)); // INSERT "RR assertEquals(new Edit(5, 5, 3, 5), r.get(1)); // INSERT "RR
} }
@Test
public void testEdit_NoUniqueMiddleSide_Insert2() { public void testEdit_NoUniqueMiddleSide_Insert2() {
EditList r = diff(t("aRSz"), t("aRRSSz")); EditList r = diff(t("aRSz"), t("aRRSSz"));
assertEquals(1, r.size()); assertEquals(1, r.size());
assertEquals(new Edit(2, 2, 2, 4), r.get(0)); assertEquals(new Edit(2, 2, 2, 4), r.get(0));
} }
@Test
public void testEdit_NoUniqueMiddleSide_FlipAndExpand() { public void testEdit_NoUniqueMiddleSide_FlipAndExpand() {
EditList r = diff(t("aRSz"), t("aSSRRz")); EditList r = diff(t("aRSz"), t("aSSRRz"));
assertEquals(2, r.size()); assertEquals(2, r.size());
@ -72,6 +79,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase {
assertEquals(new Edit(3, 3, 2, 5), r.get(1)); // INSERT "SRR" assertEquals(new Edit(3, 3, 2, 5), r.get(1)); // INSERT "SRR"
} }
@Test
public void testEdit_LcsContainsUnique() { public void testEdit_LcsContainsUnique() {
EditList r = diff(t("nqnjrnjsnm"), t("AnqnjrnjsnjTnmZ")); EditList r = diff(t("nqnjrnjsnm"), t("AnqnjrnjsnjTnmZ"));
assertEquals(new Edit(0, 0, 0, 1), r.get(0)); // INSERT "A"; assertEquals(new Edit(0, 0, 0, 1), r.get(0)); // INSERT "A";
@ -80,6 +88,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase {
assertEquals(3, r.size()); assertEquals(3, r.size());
} }
@Test
public void testExceedsChainLength_DuringScanOfA() { public void testExceedsChainLength_DuringScanOfA() {
HistogramDiff hd = new HistogramDiff(); HistogramDiff hd = new HistogramDiff();
hd.setFallbackAlgorithm(null); hd.setFallbackAlgorithm(null);
@ -102,6 +111,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase {
assertEquals(new Edit(0, 4, 0, 4), r.get(0)); assertEquals(new Edit(0, 4, 0, 4), r.get(0));
} }
@Test
public void testExceedsChainLength_DuringScanOfB() { public void testExceedsChainLength_DuringScanOfB() {
HistogramDiff hd = new HistogramDiff(); HistogramDiff hd = new HistogramDiff();
hd.setFallbackAlgorithm(null); hd.setFallbackAlgorithm(null);
@ -112,6 +122,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase {
assertEquals(new Edit(0, 4, 0, 4), r.get(0)); assertEquals(new Edit(0, 4, 0, 4), r.get(0));
} }
@Test
public void testFallbackToMyersDiff() { public void testFallbackToMyersDiff() {
HistogramDiff hd = new HistogramDiff(); HistogramDiff hd = new HistogramDiff();
hd.setMaxChainLength(4); hd.setMaxChainLength(4);

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespaceTest.java

@ -44,13 +44,17 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import org.eclipse.jgit.lib.Constants; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class RawTextIgnoreAllWhitespaceTest extends TestCase { public class RawTextIgnoreAllWhitespaceTest {
private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_ALL; private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_ALL;
@Test
public void testEqualsWithoutWhitespace() { public void testEqualsWithoutWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\nfoo-b\nfoo\n")); .encodeASCII("foo-a\nfoo-b\nfoo\n"));
@ -73,6 +77,7 @@ public class RawTextIgnoreAllWhitespaceTest extends TestCase {
assertFalse(cmp.equals(b, 2, a, 2)); assertFalse(cmp.equals(b, 2, a, 2));
} }
@Test
public void testEqualsWithWhitespace() { public void testEqualsWithWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\n \n a b c\na \n")); .encodeASCII("foo-a\n \n a b c\na \n"));

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespaceTest.java

@ -44,13 +44,17 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import org.eclipse.jgit.lib.Constants; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class RawTextIgnoreLeadingWhitespaceTest extends TestCase { public class RawTextIgnoreLeadingWhitespaceTest {
private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_LEADING; private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_LEADING;
@Test
public void testEqualsWithoutWhitespace() { public void testEqualsWithoutWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\nfoo-b\nfoo\n")); .encodeASCII("foo-a\nfoo-b\nfoo\n"));
@ -73,6 +77,7 @@ public class RawTextIgnoreLeadingWhitespaceTest extends TestCase {
assertFalse(cmp.equals(b, 2, a, 2)); assertFalse(cmp.equals(b, 2, a, 2));
} }
@Test
public void testEqualsWithWhitespace() { public void testEqualsWithWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\n \n a b c\n a\nb \n")); .encodeASCII("foo-a\n \n a b c\n a\nb \n"));

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespaceTest.java

@ -44,13 +44,17 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import org.eclipse.jgit.lib.Constants; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class RawTextIgnoreTrailingWhitespaceTest extends TestCase { public class RawTextIgnoreTrailingWhitespaceTest {
private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_TRAILING; private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_TRAILING;
@Test
public void testEqualsWithoutWhitespace() { public void testEqualsWithoutWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\nfoo-b\nfoo\n")); .encodeASCII("foo-a\nfoo-b\nfoo\n"));
@ -73,6 +77,7 @@ public class RawTextIgnoreTrailingWhitespaceTest extends TestCase {
assertFalse(cmp.equals(b, 2, a, 2)); assertFalse(cmp.equals(b, 2, a, 2));
} }
@Test
public void testEqualsWithWhitespace() { public void testEqualsWithWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\n \n a b c\na \n b\n")); .encodeASCII("foo-a\n \n a b c\na \n b\n"));

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java

@ -44,13 +44,17 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import org.eclipse.jgit.lib.Constants; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class RawTextIgnoreWhitespaceChangeTest extends TestCase { public class RawTextIgnoreWhitespaceChangeTest {
private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_CHANGE; private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_CHANGE;
@Test
public void testEqualsWithoutWhitespace() { public void testEqualsWithoutWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\nfoo-b\nfoo\n")); .encodeASCII("foo-a\nfoo-b\nfoo\n"));
@ -73,6 +77,7 @@ public class RawTextIgnoreWhitespaceChangeTest extends TestCase {
assertFalse(cmp.equals(b, 2, a, 2)); assertFalse(cmp.equals(b, 2, a, 2));
} }
@Test
public void testEqualsWithWhitespace() { public void testEqualsWithWhitespace() {
final RawText a = new RawText(Constants final RawText a = new RawText(Constants
.encodeASCII("foo-a\n \n a b c\na \n foo\na b c\n")); .encodeASCII("foo-a\n \n a b c\na \n foo\na b c\n"));

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java

@ -44,21 +44,26 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
import org.junit.Test;
public class RawTextTest extends TestCase { public class RawTextTest {
@Test
public void testEmpty() { public void testEmpty() {
final RawText r = new RawText(new byte[0]); final RawText r = new RawText(new byte[0]);
assertEquals(0, r.size()); assertEquals(0, r.size());
} }
@Test
public void testEquals() { public void testEquals() {
final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\n")); final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\n"));
final RawText b = new RawText(Constants.encodeASCII("foo-b\nfoo-c\n")); final RawText b = new RawText(Constants.encodeASCII("foo-b\nfoo-c\n"));
@ -76,6 +81,7 @@ public class RawTextTest extends TestCase {
assertTrue(cmp.equals(b, 0, a, 1)); assertTrue(cmp.equals(b, 0, a, 1));
} }
@Test
public void testWriteLine1() throws IOException { public void testWriteLine1() throws IOException {
final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\n")); final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\n"));
final ByteArrayOutputStream o = new ByteArrayOutputStream(); final ByteArrayOutputStream o = new ByteArrayOutputStream();
@ -84,6 +90,7 @@ public class RawTextTest extends TestCase {
assertEquals("foo-a", RawParseUtils.decode(r)); assertEquals("foo-a", RawParseUtils.decode(r));
} }
@Test
public void testWriteLine2() throws IOException { public void testWriteLine2() throws IOException {
final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b")); final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b"));
final ByteArrayOutputStream o = new ByteArrayOutputStream(); final ByteArrayOutputStream o = new ByteArrayOutputStream();
@ -92,6 +99,7 @@ public class RawTextTest extends TestCase {
assertEquals("foo-b", RawParseUtils.decode(r)); assertEquals("foo-b", RawParseUtils.decode(r));
} }
@Test
public void testWriteLine3() throws IOException { public void testWriteLine3() throws IOException {
final RawText a = new RawText(Constants.encodeASCII("a\n\nb\n")); final RawText a = new RawText(Constants.encodeASCII("a\n\nb\n"));
final ByteArrayOutputStream o = new ByteArrayOutputStream(); final ByteArrayOutputStream o = new ByteArrayOutputStream();
@ -100,6 +108,7 @@ public class RawTextTest extends TestCase {
assertEquals("", RawParseUtils.decode(r)); assertEquals("", RawParseUtils.decode(r));
} }
@Test
public void testComparatorReduceCommonStartEnd() public void testComparatorReduceCommonStartEnd()
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
final RawTextComparator c = RawTextComparator.DEFAULT; final RawTextComparator c = RawTextComparator.DEFAULT;
@ -134,6 +143,7 @@ public class RawTextTest extends TestCase {
assertEquals(new Edit(2, 3, 2, 3), e); assertEquals(new Edit(2, 3, 2, 3), e);
} }
@Test
public void testComparatorReduceCommonStartEnd_EmptyLine() public void testComparatorReduceCommonStartEnd_EmptyLine()
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
RawText a; RawText a;

34
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java

@ -43,6 +43,11 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List; import java.util.List;
import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffEntry.ChangeType;
@ -51,6 +56,8 @@ import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Before;
import org.junit.Test;
public class RenameDetectorTest extends RepositoryTestCase { public class RenameDetectorTest extends RepositoryTestCase {
private static final String PATH_A = "src/A"; private static final String PATH_A = "src/A";
@ -63,12 +70,14 @@ public class RenameDetectorTest extends RepositoryTestCase {
private TestRepository testDb; private TestRepository testDb;
@Override @Override
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
testDb = new TestRepository(db); testDb = new TestRepository(db);
rd = new RenameDetector(db); rd = new RenameDetector(db);
} }
@Test
public void testExactRename_OneRename() throws Exception { public void testExactRename_OneRename() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
@ -83,6 +92,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 100, entries.get(0)); assertRename(b, a, 100, entries.get(0));
} }
@Test
public void testExactRename_DifferentObjects() throws Exception { public void testExactRename_DifferentObjects() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
ObjectId bar = blob("bar"); ObjectId bar = blob("bar");
@ -102,6 +112,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(q, entries.get(2)); assertSame(q, entries.get(2));
} }
@Test
public void testExactRename_OneRenameOneModify() throws Exception { public void testExactRename_OneRenameOneModify() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
ObjectId bar = blob("bar"); ObjectId bar = blob("bar");
@ -122,6 +133,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(c, entries.get(1)); assertSame(c, entries.get(1));
} }
@Test
public void testExactRename_ManyRenames() throws Exception { public void testExactRename_ManyRenames() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
ObjectId bar = blob("bar"); ObjectId bar = blob("bar");
@ -143,6 +155,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(d, c, 100, entries.get(1)); assertRename(d, c, 100, entries.get(1));
} }
@Test
public void testExactRename_MultipleIdenticalDeletes() throws Exception { public void testExactRename_MultipleIdenticalDeletes() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
@ -165,6 +178,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(a, d, 100, entries.get(2)); assertRename(a, d, 100, entries.get(2));
} }
@Test
public void testExactRename_PathBreaksTie() throws Exception { public void testExactRename_PathBreaksTie() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
@ -189,6 +203,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertCopy(d, e, 100, entries.get(2)); assertCopy(d, e, 100, entries.get(2));
} }
@Test
public void testExactRename_OneDeleteManyAdds() throws Exception { public void testExactRename_OneDeleteManyAdds() throws Exception {
ObjectId foo = blob("foo"); ObjectId foo = blob("foo");
@ -210,6 +225,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertCopy(d, b, 100, entries.get(2)); assertCopy(d, b, 100, entries.get(2));
} }
@Test
public void testInexactRename_OnePair() throws Exception { public void testInexactRename_OnePair() throws Exception {
ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); ObjectId aId = blob("foo\nbar\nbaz\nblarg\n");
ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); ObjectId bId = blob("foo\nbar\nbaz\nblah\n");
@ -225,6 +241,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 66, entries.get(0)); assertRename(b, a, 66, entries.get(0));
} }
@Test
public void testInexactRename_OneRenameTwoUnrelatedFiles() throws Exception { public void testInexactRename_OneRenameTwoUnrelatedFiles() throws Exception {
ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); ObjectId aId = blob("foo\nbar\nbaz\nblarg\n");
ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); ObjectId bId = blob("foo\nbar\nbaz\nblah\n");
@ -248,6 +265,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(d, entries.get(2)); assertSame(d, entries.get(2));
} }
@Test
public void testInexactRename_LastByteDifferent() throws Exception { public void testInexactRename_LastByteDifferent() throws Exception {
ObjectId aId = blob("foo\nbar\na"); ObjectId aId = blob("foo\nbar\na");
ObjectId bId = blob("foo\nbar\nb"); ObjectId bId = blob("foo\nbar\nb");
@ -263,6 +281,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 88, entries.get(0)); assertRename(b, a, 88, entries.get(0));
} }
@Test
public void testInexactRename_NewlinesOnly() throws Exception { public void testInexactRename_NewlinesOnly() throws Exception {
ObjectId aId = blob("\n\n\n"); ObjectId aId = blob("\n\n\n");
ObjectId bId = blob("\n\n\n\n"); ObjectId bId = blob("\n\n\n\n");
@ -278,6 +297,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 74, entries.get(0)); assertRename(b, a, 74, entries.get(0));
} }
@Test
public void testInexactRename_SameContentMultipleTimes() throws Exception { public void testInexactRename_SameContentMultipleTimes() throws Exception {
ObjectId aId = blob("a\na\na\na\n"); ObjectId aId = blob("a\na\na\na\n");
ObjectId bId = blob("a\na\na\n"); ObjectId bId = blob("a\na\na\n");
@ -293,6 +313,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 74, entries.get(0)); assertRename(b, a, 74, entries.get(0));
} }
@Test
public void testInexactRenames_OnePair2() throws Exception { public void testInexactRenames_OnePair2() throws Exception {
ObjectId aId = blob("ab\nab\nab\nac\nad\nae\n"); ObjectId aId = blob("ab\nab\nab\nac\nad\nae\n");
ObjectId bId = blob("ac\nab\nab\nab\naa\na0\na1\n"); ObjectId bId = blob("ac\nab\nab\nab\naa\na0\na1\n");
@ -309,6 +330,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(b, a, 57, entries.get(0)); assertRename(b, a, 57, entries.get(0));
} }
@Test
public void testNoRenames_SingleByteFiles() throws Exception { public void testNoRenames_SingleByteFiles() throws Exception {
ObjectId aId = blob("a"); ObjectId aId = blob("a");
ObjectId bId = blob("b"); ObjectId bId = blob("b");
@ -325,6 +347,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(b, entries.get(1)); assertSame(b, entries.get(1));
} }
@Test
public void testNoRenames_EmptyFile1() throws Exception { public void testNoRenames_EmptyFile1() throws Exception {
ObjectId aId = blob(""); ObjectId aId = blob("");
DiffEntry a = DiffEntry.add(PATH_A, aId); DiffEntry a = DiffEntry.add(PATH_A, aId);
@ -336,6 +359,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(a, entries.get(0)); assertSame(a, entries.get(0));
} }
@Test
public void testNoRenames_EmptyFile2() throws Exception { public void testNoRenames_EmptyFile2() throws Exception {
ObjectId aId = blob(""); ObjectId aId = blob("");
ObjectId bId = blob("blah"); ObjectId bId = blob("blah");
@ -352,6 +376,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(b, entries.get(1)); assertSame(b, entries.get(1));
} }
@Test
public void testNoRenames_SymlinkAndFile() throws Exception { public void testNoRenames_SymlinkAndFile() throws Exception {
ObjectId aId = blob("src/dest"); ObjectId aId = blob("src/dest");
@ -368,6 +393,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(b, entries.get(1)); assertSame(b, entries.get(1));
} }
@Test
public void testNoRenames_GitlinkAndFile() throws Exception { public void testNoRenames_GitlinkAndFile() throws Exception {
ObjectId aId = blob("src/dest"); ObjectId aId = blob("src/dest");
@ -384,6 +410,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(b, entries.get(1)); assertSame(b, entries.get(1));
} }
@Test
public void testNoRenames_SymlinkAndFileSamePath() throws Exception { public void testNoRenames_SymlinkAndFileSamePath() throws Exception {
ObjectId aId = blob("src/dest"); ObjectId aId = blob("src/dest");
@ -401,6 +428,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(b, entries.get(1)); assertSame(b, entries.get(1));
} }
@Test
public void testBreakModify_BreakAll() throws Exception { public void testBreakModify_BreakAll() throws Exception {
ObjectId aId = blob("foo"); ObjectId aId = blob("foo");
ObjectId bId = blob("bar"); ObjectId bId = blob("bar");
@ -422,6 +450,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(DiffEntry.breakModify(m).get(0), a, 100, entries.get(1)); assertRename(DiffEntry.breakModify(m).get(0), a, 100, entries.get(1));
} }
@Test
public void testBreakModify_BreakNone() throws Exception { public void testBreakModify_BreakNone() throws Exception {
ObjectId aId = blob("foo"); ObjectId aId = blob("foo");
ObjectId bId = blob("bar"); ObjectId bId = blob("bar");
@ -443,6 +472,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(a, entries.get(1)); assertSame(a, entries.get(1));
} }
@Test
public void testBreakModify_BreakBelowScore() throws Exception { public void testBreakModify_BreakBelowScore() throws Exception {
ObjectId aId = blob("foo"); ObjectId aId = blob("foo");
ObjectId bId = blob("bar"); ObjectId bId = blob("bar");
@ -464,6 +494,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertRename(DiffEntry.breakModify(m).get(0), a, 100, entries.get(1)); assertRename(DiffEntry.breakModify(m).get(0), a, 100, entries.get(1));
} }
@Test
public void testBreakModify_DontBreakAboveScore() throws Exception { public void testBreakModify_DontBreakAboveScore() throws Exception {
ObjectId aId = blob("blah\nblah\nfoo"); ObjectId aId = blob("blah\nblah\nfoo");
ObjectId bId = blob("blah\nblah\nbar"); ObjectId bId = blob("blah\nblah\nbar");
@ -485,6 +516,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertSame(a, entries.get(1)); assertSame(a, entries.get(1));
} }
@Test
public void testBreakModify_RejoinIfUnpaired() throws Exception { public void testBreakModify_RejoinIfUnpaired() throws Exception {
ObjectId aId = blob("foo"); ObjectId aId = blob("foo");
ObjectId bId = blob("bar"); ObjectId bId = blob("bar");
@ -511,6 +543,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertEquals(0, modify.score); assertEquals(0, modify.score);
} }
@Test
public void testSetRenameScore_IllegalArgs() throws Exception { public void testSetRenameScore_IllegalArgs() throws Exception {
try { try {
rd.setRenameScore(-1); rd.setRenameScore(-1);
@ -527,6 +560,7 @@ public class RenameDetectorTest extends RepositoryTestCase {
} }
} }
@Test
public void testRenameLimit() throws Exception { public void testRenameLimit() throws Exception {
ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); ObjectId aId = blob("foo\nbar\nbaz\nblarg\n");
ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); ObjectId bId = blob("foo\nbar\nbaz\nblah\n");

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java

@ -43,15 +43,18 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jgit.diff.SimilarityIndex.TableFullException; import org.eclipse.jgit.diff.SimilarityIndex.TableFullException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class SimilarityIndexTest extends TestCase { public class SimilarityIndexTest {
@Test
public void testIndexingSmallObject() throws TableFullException { public void testIndexingSmallObject() throws TableFullException {
SimilarityIndex si = hash("" // SimilarityIndex si = hash("" //
+ "A\n" // + "A\n" //
@ -71,6 +74,7 @@ public class SimilarityIndexTest extends TestCase {
assertEquals(2, si.count(si.findIndex(key_D))); assertEquals(2, si.count(si.findIndex(key_D)));
} }
@Test
public void testIndexingLargeObject() throws IOException, public void testIndexingLargeObject() throws IOException,
TableFullException { TableFullException {
byte[] in = ("" // byte[] in = ("" //
@ -83,6 +87,7 @@ public class SimilarityIndexTest extends TestCase {
assertEquals(2, si.size()); assertEquals(2, si.size());
} }
@Test
public void testCommonScore_SameFiles() throws TableFullException { public void testCommonScore_SameFiles() throws TableFullException {
String text = "" // String text = "" //
+ "A\n" // + "A\n" //
@ -98,6 +103,7 @@ public class SimilarityIndexTest extends TestCase {
assertEquals(100, dst.score(src, 100)); assertEquals(100, dst.score(src, 100));
} }
@Test
public void testCommonScore_EmptyFiles() throws TableFullException { public void testCommonScore_EmptyFiles() throws TableFullException {
SimilarityIndex src = hash(""); SimilarityIndex src = hash("");
SimilarityIndex dst = hash(""); SimilarityIndex dst = hash("");
@ -105,6 +111,7 @@ public class SimilarityIndexTest extends TestCase {
assertEquals(0, dst.common(src)); assertEquals(0, dst.common(src));
} }
@Test
public void testCommonScore_TotallyDifferentFiles() public void testCommonScore_TotallyDifferentFiles()
throws TableFullException { throws TableFullException {
SimilarityIndex src = hash("A\n"); SimilarityIndex src = hash("A\n");
@ -113,6 +120,7 @@ public class SimilarityIndexTest extends TestCase {
assertEquals(0, dst.common(src)); assertEquals(0, dst.common(src));
} }
@Test
public void testCommonScore_SimiliarBy75() throws TableFullException { public void testCommonScore_SimiliarBy75() throws TableFullException {
SimilarityIndex src = hash("A\nB\nC\nD\n"); SimilarityIndex src = hash("A\nB\nC\nD\n");
SimilarityIndex dst = hash("A\nB\nC\nQ\n"); SimilarityIndex dst = hash("A\nB\nC\nQ\n");

17
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java vendored

@ -43,13 +43,20 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Test;
public class DirCacheBasicTest extends RepositoryTestCase { public class DirCacheBasicTest extends RepositoryTestCase {
@Test
public void testReadMissing_RealIndex() throws Exception { public void testReadMissing_RealIndex() throws Exception {
final File idx = new File(db.getDirectory(), "index"); final File idx = new File(db.getDirectory(), "index");
assertFalse(idx.exists()); assertFalse(idx.exists());
@ -59,6 +66,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertEquals(0, dc.getEntryCount()); assertEquals(0, dc.getEntryCount());
} }
@Test
public void testReadMissing_TempIndex() throws Exception { public void testReadMissing_TempIndex() throws Exception {
final File idx = new File(db.getDirectory(), "tmp_index"); final File idx = new File(db.getDirectory(), "tmp_index");
assertFalse(idx.exists()); assertFalse(idx.exists());
@ -68,6 +76,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertEquals(0, dc.getEntryCount()); assertEquals(0, dc.getEntryCount());
} }
@Test
public void testLockMissing_RealIndex() throws Exception { public void testLockMissing_RealIndex() throws Exception {
final File idx = new File(db.getDirectory(), "index"); final File idx = new File(db.getDirectory(), "index");
final File lck = new File(db.getDirectory(), "index.lock"); final File lck = new File(db.getDirectory(), "index.lock");
@ -85,6 +94,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(lck.exists()); assertFalse(lck.exists());
} }
@Test
public void testLockMissing_TempIndex() throws Exception { public void testLockMissing_TempIndex() throws Exception {
final File idx = new File(db.getDirectory(), "tmp_index"); final File idx = new File(db.getDirectory(), "tmp_index");
final File lck = new File(db.getDirectory(), "tmp_index.lock"); final File lck = new File(db.getDirectory(), "tmp_index.lock");
@ -102,6 +112,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(lck.exists()); assertFalse(lck.exists());
} }
@Test
public void testWriteEmptyUnlock_RealIndex() throws Exception { public void testWriteEmptyUnlock_RealIndex() throws Exception {
final File idx = new File(db.getDirectory(), "index"); final File idx = new File(db.getDirectory(), "index");
final File lck = new File(db.getDirectory(), "index.lock"); final File lck = new File(db.getDirectory(), "index.lock");
@ -118,6 +129,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(lck.exists()); assertFalse(lck.exists());
} }
@Test
public void testWriteEmptyCommit_RealIndex() throws Exception { public void testWriteEmptyCommit_RealIndex() throws Exception {
final File idx = new File(db.getDirectory(), "index"); final File idx = new File(db.getDirectory(), "index");
final File lck = new File(db.getDirectory(), "index.lock"); final File lck = new File(db.getDirectory(), "index.lock");
@ -135,6 +147,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertEquals(12 + 20, idx.length()); assertEquals(12 + 20, idx.length());
} }
@Test
public void testWriteEmptyReadEmpty_RealIndex() throws Exception { public void testWriteEmptyReadEmpty_RealIndex() throws Exception {
final File idx = new File(db.getDirectory(), "index"); final File idx = new File(db.getDirectory(), "index");
final File lck = new File(db.getDirectory(), "index.lock"); final File lck = new File(db.getDirectory(), "index.lock");
@ -152,6 +165,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
} }
} }
@Test
public void testWriteEmptyLockEmpty_RealIndex() throws Exception { public void testWriteEmptyLockEmpty_RealIndex() throws Exception {
final File idx = new File(db.getDirectory(), "index"); final File idx = new File(db.getDirectory(), "index");
final File lck = new File(db.getDirectory(), "index.lock"); final File lck = new File(db.getDirectory(), "index.lock");
@ -172,6 +186,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
} }
} }
@Test
public void testBuildThenClear() throws Exception { public void testBuildThenClear() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
@ -194,6 +209,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(dc.hasUnmergedPaths()); assertFalse(dc.hasUnmergedPaths());
} }
@Test
public void testDetectUnmergedPaths() throws Exception { public void testDetectUnmergedPaths() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
final DirCacheEntry[] ents = new DirCacheEntry[3]; final DirCacheEntry[] ents = new DirCacheEntry[3];
@ -212,6 +228,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertTrue(dc.hasUnmergedPaths()); assertTrue(dc.hasUnmergedPaths());
} }
@Test
public void testFindOnEmpty() throws Exception { public void testFindOnEmpty() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
final byte[] path = Constants.encode("a"); final byte[] path = Constants.encode("a");

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java vendored

@ -43,14 +43,22 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Collections; import java.util.Collections;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.junit.Test;
public class DirCacheBuilderIteratorTest extends RepositoryTestCase { public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
@Test
public void testPathFilterGroup_DoesNotSkipTail() throws Exception { public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java vendored

@ -43,13 +43,22 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Test;
public class DirCacheBuilderTest extends RepositoryTestCase { public class DirCacheBuilderTest extends RepositoryTestCase {
@Test
public void testBuildEmpty() throws Exception { public void testBuildEmpty() throws Exception {
{ {
final DirCache dc = db.lockDirCache(); final DirCache dc = db.lockDirCache();
@ -65,6 +74,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
} }
} }
@Test
public void testBuildRejectsUnsetFileMode() throws Exception { public void testBuildRejectsUnsetFileMode() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
final DirCacheBuilder b = dc.builder(); final DirCacheBuilder b = dc.builder();
@ -79,6 +89,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
} }
} }
@Test
public void testBuildOneFile_FinishWriteCommit() throws Exception { public void testBuildOneFile_FinishWriteCommit() throws Exception {
final String path = "a-file-path"; final String path = "a-file-path";
final FileMode mode = FileMode.REGULAR_FILE; final FileMode mode = FileMode.REGULAR_FILE;
@ -128,6 +139,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
} }
} }
@Test
public void testBuildOneFile_Commit() throws Exception { public void testBuildOneFile_Commit() throws Exception {
final String path = "a-file-path"; final String path = "a-file-path";
final FileMode mode = FileMode.REGULAR_FILE; final FileMode mode = FileMode.REGULAR_FILE;
@ -175,6 +187,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
} }
} }
@Test
public void testFindSingleFile() throws Exception { public void testFindSingleFile() throws Exception {
final String path = "a-file-path"; final String path = "a-file-path";
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
@ -201,6 +214,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
assertSame(entOrig, dc.getEntry(path)); assertSame(entOrig, dc.getEntry(path));
} }
@Test
public void testAdd_InGitSortOrder() throws Exception { public void testAdd_InGitSortOrder() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
@ -225,6 +239,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
} }
} }
@Test
public void testAdd_ReverseGitSortOrder() throws Exception { public void testAdd_ReverseGitSortOrder() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
@ -249,6 +264,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
} }
} }
@Test
public void testBuilderClear() throws Exception { public void testBuilderClear() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java vendored

@ -43,6 +43,11 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -55,6 +60,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@ -62,11 +68,12 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.JGitTestUtil; import org.junit.Test;
public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
private final File index = pathOf("gitgit.index"); private final File index = pathOf("gitgit.index");
@Test
public void testReadIndex_LsFiles() throws Exception { public void testReadIndex_LsFiles() throws Exception {
final Map<String, CGitIndexRecord> ls = readLsFiles(); final Map<String, CGitIndexRecord> ls = readLsFiles();
final DirCache dc = new DirCache(index, FS.DETECTED); final DirCache dc = new DirCache(index, FS.DETECTED);
@ -80,6 +87,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testTreeWalk_LsFiles() throws Exception { public void testTreeWalk_LsFiles() throws Exception {
final Repository db = createBareRepository(); final Repository db = createBareRepository();
final Map<String, CGitIndexRecord> ls = readLsFiles(); final Map<String, CGitIndexRecord> ls = readLsFiles();
@ -104,6 +112,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testUnsupportedOptionalExtension() throws Exception { public void testUnsupportedOptionalExtension() throws Exception {
final DirCache dc = new DirCache(pathOf("gitgit.index.ZZZZ"), final DirCache dc = new DirCache(pathOf("gitgit.index.ZZZZ"),
FS.DETECTED); FS.DETECTED);
@ -112,6 +121,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals("A", dc.getEntry(0).getPathString()); assertEquals("A", dc.getEntry(0).getPathString());
} }
@Test
public void testUnsupportedRequiredExtension() throws Exception { public void testUnsupportedRequiredExtension() throws Exception {
final DirCache dc = new DirCache(pathOf("gitgit.index.aaaa"), final DirCache dc = new DirCache(pathOf("gitgit.index.aaaa"),
FS.DETECTED); FS.DETECTED);
@ -124,6 +134,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testCorruptChecksumAtFooter() throws Exception { public void testCorruptChecksumAtFooter() throws Exception {
final DirCache dc = new DirCache(pathOf("gitgit.index.badchecksum"), final DirCache dc = new DirCache(pathOf("gitgit.index.badchecksum"),
FS.DETECTED); FS.DETECTED);
@ -146,6 +157,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals(c.stage, j.getStage()); assertEquals(c.stage, j.getStage());
} }
@Test
public void testReadIndex_DirCacheTree() throws Exception { public void testReadIndex_DirCacheTree() throws Exception {
final Map<String, CGitIndexRecord> cList = readLsFiles(); final Map<String, CGitIndexRecord> cList = readLsFiles();
final Map<String, CGitLsTreeRecord> cTree = readLsTree(); final Map<String, CGitLsTreeRecord> cTree = readLsTree();
@ -181,6 +193,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
} }
} }
@Test
public void testReadWriteV3() throws Exception { public void testReadWriteV3() throws Exception {
final File file = pathOf("gitgit.index.v3"); final File file = pathOf("gitgit.index.v3");
final DirCache dc = new DirCache(file, FS.DETECTED); final DirCache dc = new DirCache(file, FS.DETECTED);

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java vendored

@ -43,12 +43,18 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.junit.Test;
public class DirCacheEntryTest extends TestCase { public class DirCacheEntryTest {
@Test
public void testIsValidPath() { public void testIsValidPath() {
assertTrue(isValidPath("a")); assertTrue(isValidPath("a"));
assertTrue(isValidPath("a/b")); assertTrue(isValidPath("a/b"));
@ -67,6 +73,7 @@ public class DirCacheEntryTest extends TestCase {
return DirCacheEntry.isValidPath(Constants.encode(path)); return DirCacheEntry.isValidPath(Constants.encode(path));
} }
@Test
public void testCreate_ByStringPath() { public void testCreate_ByStringPath() {
assertEquals("a", new DirCacheEntry("a").getPathString()); assertEquals("a", new DirCacheEntry("a").getPathString());
assertEquals("a/b", new DirCacheEntry("a/b").getPathString()); assertEquals("a/b", new DirCacheEntry("a/b").getPathString());
@ -79,6 +86,7 @@ public class DirCacheEntryTest extends TestCase {
} }
} }
@Test
public void testCreate_ByStringPathAndStage() { public void testCreate_ByStringPathAndStage() {
DirCacheEntry e; DirCacheEntry e;
@ -120,6 +128,7 @@ public class DirCacheEntryTest extends TestCase {
} }
} }
@Test
public void testSetFileMode() { public void testSetFileMode() {
final DirCacheEntry e = new DirCacheEntry("a"); final DirCacheEntry e = new DirCacheEntry("a");

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java vendored

@ -43,10 +43,16 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Test;
public class DirCacheFindTest extends RepositoryTestCase { public class DirCacheFindTest extends RepositoryTestCase {
@Test
public void testEntriesWithin() throws Exception { public void testEntriesWithin() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java vendored

@ -43,17 +43,25 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.util.Collections; import java.util.Collections;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.JGitTestUtil; import org.junit.Test;
public class DirCacheIteratorTest extends RepositoryTestCase { public class DirCacheIteratorTest extends RepositoryTestCase {
@Test
public void testEmptyTree_NoTreeWalk() throws Exception { public void testEmptyTree_NoTreeWalk() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
assertEquals(0, dc.getEntryCount()); assertEquals(0, dc.getEntryCount());
@ -62,6 +70,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertTrue(i.eof()); assertTrue(i.eof());
} }
@Test
public void testEmptyTree_WithTreeWalk() throws Exception { public void testEmptyTree_WithTreeWalk() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
assertEquals(0, dc.getEntryCount()); assertEquals(0, dc.getEntryCount());
@ -71,6 +80,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertFalse(tw.next()); assertFalse(tw.next());
} }
@Test
public void testNoSubtree_NoTreeWalk() throws Exception { public void testNoSubtree_NoTreeWalk() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
@ -96,6 +106,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
@Test
public void testNoSubtree_WithTreeWalk() throws Exception { public void testNoSubtree_WithTreeWalk() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
@ -128,6 +139,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
@Test
public void testSingleSubtree_NoRecursion() throws Exception { public void testSingleSubtree_NoRecursion() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
@ -171,6 +183,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertEquals(expPaths.length, pathIdx); assertEquals(expPaths.length, pathIdx);
} }
@Test
public void testSingleSubtree_Recursive() throws Exception { public void testSingleSubtree_Recursive() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
@ -205,6 +218,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
@Test
public void testTwoLevelSubtree_Recursive() throws Exception { public void testTwoLevelSubtree_Recursive() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
@ -238,6 +252,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
@Test
public void testTwoLevelSubtree_FilterPath() throws Exception { public void testTwoLevelSubtree_FilterPath() throws Exception {
final DirCache dc = DirCache.newInCore(); final DirCache dc = DirCache.newInCore();
@ -273,6 +288,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
} }
} }
@Test
public void testRemovedSubtree() throws Exception { public void testRemovedSubtree() throws Exception {
final File path = JGitTestUtil final File path = JGitTestUtil
.getTestResourceFile("dircache.testRemovedSubtree"); .getTestResourceFile("dircache.testRemovedSubtree");

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java vendored

@ -43,29 +43,40 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Test;
public class DirCacheLargePathTest extends RepositoryTestCase { public class DirCacheLargePathTest extends RepositoryTestCase {
@Test
public void testPath_4090() throws Exception { public void testPath_4090() throws Exception {
testLongPath(4090); testLongPath(4090);
} }
@Test
public void testPath_4094() throws Exception { public void testPath_4094() throws Exception {
testLongPath(4094); testLongPath(4094);
} }
@Test
public void testPath_4095() throws Exception { public void testPath_4095() throws Exception {
testLongPath(4095); testLongPath(4095);
} }
@Test
public void testPath_4096() throws Exception { public void testPath_4096() throws Exception {
testLongPath(4096); testLongPath(4096);
} }
@Test
public void testPath_16384() throws Exception { public void testPath_16384() throws Exception {
testLongPath(16384); testLongPath(16384);
} }

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java vendored

@ -43,18 +43,28 @@
package org.eclipse.jgit.dircache; package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.junit.Test;
public class DirCacheTreeTest extends RepositoryTestCase { public class DirCacheTreeTest extends RepositoryTestCase {
@Test
public void testEmptyCache_NoCacheTree() throws Exception { public void testEmptyCache_NoCacheTree() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
assertNull(dc.getCacheTree(false)); assertNull(dc.getCacheTree(false));
} }
@Test
public void testEmptyCache_CreateEmptyCacheTree() throws Exception { public void testEmptyCache_CreateEmptyCacheTree() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
final DirCacheTree tree = dc.getCacheTree(true); final DirCacheTree tree = dc.getCacheTree(true);
@ -68,6 +78,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
assertFalse(tree.isValid()); assertFalse(tree.isValid());
} }
@Test
public void testEmptyCache_Clear_NoCacheTree() throws Exception { public void testEmptyCache_Clear_NoCacheTree() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
final DirCacheTree tree = dc.getCacheTree(true); final DirCacheTree tree = dc.getCacheTree(true);
@ -77,6 +88,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
assertNotSame(tree, dc.getCacheTree(true)); assertNotSame(tree, dc.getCacheTree(true));
} }
@Test
public void testSingleSubtree() throws Exception { public void testSingleSubtree() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
@ -114,6 +126,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
assertFalse(aTree.isValid()); assertFalse(aTree.isValid());
} }
@Test
public void testTwoLevelSubtree() throws Exception { public void testTwoLevelSubtree() throws Exception {
final DirCache dc = db.readDirCache(); final DirCache dc = db.readDirCache();
@ -171,6 +184,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
* @throws CorruptObjectException * @throws CorruptObjectException
* @throws IOException * @throws IOException
*/ */
@Test
public void testWriteReadTree() throws CorruptObjectException, IOException { public void testWriteReadTree() throws CorruptObjectException, IOException {
final DirCache dc = db.lockDirCache(); final DirCache dc = db.lockDirCache();

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java

@ -42,10 +42,16 @@
*/ */
package org.eclipse.jgit.events; package org.eclipse.jgit.events;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.junit.Test;
public class ConfigChangeEventTest extends RepositoryTestCase { public class ConfigChangeEventTest extends RepositoryTestCase {
@Test
public void testFileRepository_ChangeEventsOnlyOnSave() throws Exception { public void testFileRepository_ChangeEventsOnlyOnSave() throws Exception {
final ConfigChangedEvent[] events = new ConfigChangedEvent[1]; final ConfigChangedEvent[] events = new ConfigChangedEvent[1];
db.getListenerList().addConfigChangedListener( db.getListenerList().addConfigChangedListener(

157
org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java

@ -44,12 +44,14 @@
package org.eclipse.jgit.fnmatch; package org.eclipse.jgit.fnmatch;
import org.eclipse.jgit.errors.InvalidPatternException; import static org.junit.Assert.assertEquals;
import org.eclipse.jgit.fnmatch.FileNameMatcher; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.TestCase; import org.eclipse.jgit.errors.InvalidPatternException;
import org.junit.Test;
public class FileNameMatcherTest extends TestCase { public class FileNameMatcherTest {
private void assertMatch(final String pattern, final String input, private void assertMatch(final String pattern, final String input,
final boolean matchExpected, final boolean appendCanMatchExpected) final boolean matchExpected, final boolean appendCanMatchExpected)
@ -71,178 +73,222 @@ public class FileNameMatcherTest extends TestCase {
assertEquals(appendCanMatchExpected, matcher.canAppendMatch()); assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
} }
@Test
public void testVerySimplePatternCase0() throws Exception { public void testVerySimplePatternCase0() throws Exception {
assertMatch("", "", true, false); assertMatch("", "", true, false);
} }
@Test
public void testVerySimplePatternCase1() throws Exception { public void testVerySimplePatternCase1() throws Exception {
assertMatch("ab", "a", false, true); assertMatch("ab", "a", false, true);
} }
@Test
public void testVerySimplePatternCase2() throws Exception { public void testVerySimplePatternCase2() throws Exception {
assertMatch("ab", "ab", true, false); assertMatch("ab", "ab", true, false);
} }
@Test
public void testVerySimplePatternCase3() throws Exception { public void testVerySimplePatternCase3() throws Exception {
assertMatch("ab", "ac", false, false); assertMatch("ab", "ac", false, false);
} }
@Test
public void testVerySimplePatternCase4() throws Exception { public void testVerySimplePatternCase4() throws Exception {
assertMatch("ab", "abc", false, false); assertMatch("ab", "abc", false, false);
} }
@Test
public void testVerySimpleWirdcardCase0() throws Exception { public void testVerySimpleWirdcardCase0() throws Exception {
assertMatch("?", "a", true, false); assertMatch("?", "a", true, false);
} }
@Test
public void testVerySimpleWildCardCase1() throws Exception { public void testVerySimpleWildCardCase1() throws Exception {
assertMatch("??", "a", false, true); assertMatch("??", "a", false, true);
} }
@Test
public void testVerySimpleWildCardCase2() throws Exception { public void testVerySimpleWildCardCase2() throws Exception {
assertMatch("??", "ab", true, false); assertMatch("??", "ab", true, false);
} }
@Test
public void testVerySimpleWildCardCase3() throws Exception { public void testVerySimpleWildCardCase3() throws Exception {
assertMatch("??", "abc", false, false); assertMatch("??", "abc", false, false);
} }
@Test
public void testVerySimpleStarCase0() throws Exception { public void testVerySimpleStarCase0() throws Exception {
assertMatch("*", "", true, true); assertMatch("*", "", true, true);
} }
@Test
public void testVerySimpleStarCase1() throws Exception { public void testVerySimpleStarCase1() throws Exception {
assertMatch("*", "a", true, true); assertMatch("*", "a", true, true);
} }
@Test
public void testVerySimpleStarCase2() throws Exception { public void testVerySimpleStarCase2() throws Exception {
assertMatch("*", "ab", true, true); assertMatch("*", "ab", true, true);
} }
@Test
public void testSimpleStarCase0() throws Exception { public void testSimpleStarCase0() throws Exception {
assertMatch("a*b", "a", false, true); assertMatch("a*b", "a", false, true);
} }
@Test
public void testSimpleStarCase1() throws Exception { public void testSimpleStarCase1() throws Exception {
assertMatch("a*c", "ac", true, true); assertMatch("a*c", "ac", true, true);
} }
@Test
public void testSimpleStarCase2() throws Exception { public void testSimpleStarCase2() throws Exception {
assertMatch("a*c", "ab", false, true); assertMatch("a*c", "ab", false, true);
} }
@Test
public void testSimpleStarCase3() throws Exception { public void testSimpleStarCase3() throws Exception {
assertMatch("a*c", "abc", true, true); assertMatch("a*c", "abc", true, true);
} }
@Test
public void testManySolutionsCase0() throws Exception { public void testManySolutionsCase0() throws Exception {
assertMatch("a*a*a", "aaa", true, true); assertMatch("a*a*a", "aaa", true, true);
} }
@Test
public void testManySolutionsCase1() throws Exception { public void testManySolutionsCase1() throws Exception {
assertMatch("a*a*a", "aaaa", true, true); assertMatch("a*a*a", "aaaa", true, true);
} }
@Test
public void testManySolutionsCase2() throws Exception { public void testManySolutionsCase2() throws Exception {
assertMatch("a*a*a", "ababa", true, true); assertMatch("a*a*a", "ababa", true, true);
} }
@Test
public void testManySolutionsCase3() throws Exception { public void testManySolutionsCase3() throws Exception {
assertMatch("a*a*a", "aaaaaaaa", true, true); assertMatch("a*a*a", "aaaaaaaa", true, true);
} }
@Test
public void testManySolutionsCase4() throws Exception { public void testManySolutionsCase4() throws Exception {
assertMatch("a*a*a", "aaaaaaab", false, true); assertMatch("a*a*a", "aaaaaaab", false, true);
} }
@Test
public void testVerySimpleGroupCase0() throws Exception { public void testVerySimpleGroupCase0() throws Exception {
assertMatch("[ab]", "a", true, false); assertMatch("[ab]", "a", true, false);
} }
@Test
public void testVerySimpleGroupCase1() throws Exception { public void testVerySimpleGroupCase1() throws Exception {
assertMatch("[ab]", "b", true, false); assertMatch("[ab]", "b", true, false);
} }
@Test
public void testVerySimpleGroupCase2() throws Exception { public void testVerySimpleGroupCase2() throws Exception {
assertMatch("[ab]", "ab", false, false); assertMatch("[ab]", "ab", false, false);
} }
@Test
public void testVerySimpleGroupRangeCase0() throws Exception { public void testVerySimpleGroupRangeCase0() throws Exception {
assertMatch("[b-d]", "a", false, false); assertMatch("[b-d]", "a", false, false);
} }
@Test
public void testVerySimpleGroupRangeCase1() throws Exception { public void testVerySimpleGroupRangeCase1() throws Exception {
assertMatch("[b-d]", "b", true, false); assertMatch("[b-d]", "b", true, false);
} }
@Test
public void testVerySimpleGroupRangeCase2() throws Exception { public void testVerySimpleGroupRangeCase2() throws Exception {
assertMatch("[b-d]", "c", true, false); assertMatch("[b-d]", "c", true, false);
} }
@Test
public void testVerySimpleGroupRangeCase3() throws Exception { public void testVerySimpleGroupRangeCase3() throws Exception {
assertMatch("[b-d]", "d", true, false); assertMatch("[b-d]", "d", true, false);
} }
@Test
public void testVerySimpleGroupRangeCase4() throws Exception { public void testVerySimpleGroupRangeCase4() throws Exception {
assertMatch("[b-d]", "e", false, false); assertMatch("[b-d]", "e", false, false);
} }
@Test
public void testVerySimpleGroupRangeCase5() throws Exception { public void testVerySimpleGroupRangeCase5() throws Exception {
assertMatch("[b-d]", "-", false, false); assertMatch("[b-d]", "-", false, false);
} }
@Test
public void testTwoGroupsCase0() throws Exception { public void testTwoGroupsCase0() throws Exception {
assertMatch("[b-d][ab]", "bb", true, false); assertMatch("[b-d][ab]", "bb", true, false);
} }
@Test
public void testTwoGroupsCase1() throws Exception { public void testTwoGroupsCase1() throws Exception {
assertMatch("[b-d][ab]", "ca", true, false); assertMatch("[b-d][ab]", "ca", true, false);
} }
@Test
public void testTwoGroupsCase2() throws Exception { public void testTwoGroupsCase2() throws Exception {
assertMatch("[b-d][ab]", "fa", false, false); assertMatch("[b-d][ab]", "fa", false, false);
} }
@Test
public void testTwoGroupsCase3() throws Exception { public void testTwoGroupsCase3() throws Exception {
assertMatch("[b-d][ab]", "bc", false, false); assertMatch("[b-d][ab]", "bc", false, false);
} }
@Test
public void testTwoRangesInOneGroupCase0() throws Exception { public void testTwoRangesInOneGroupCase0() throws Exception {
assertMatch("[b-ce-e]", "a", false, false); assertMatch("[b-ce-e]", "a", false, false);
} }
@Test
public void testTwoRangesInOneGroupCase1() throws Exception { public void testTwoRangesInOneGroupCase1() throws Exception {
assertMatch("[b-ce-e]", "b", true, false); assertMatch("[b-ce-e]", "b", true, false);
} }
@Test
public void testTwoRangesInOneGroupCase2() throws Exception { public void testTwoRangesInOneGroupCase2() throws Exception {
assertMatch("[b-ce-e]", "c", true, false); assertMatch("[b-ce-e]", "c", true, false);
} }
@Test
public void testTwoRangesInOneGroupCase3() throws Exception { public void testTwoRangesInOneGroupCase3() throws Exception {
assertMatch("[b-ce-e]", "d", false, false); assertMatch("[b-ce-e]", "d", false, false);
} }
@Test
public void testTwoRangesInOneGroupCase4() throws Exception { public void testTwoRangesInOneGroupCase4() throws Exception {
assertMatch("[b-ce-e]", "e", true, false); assertMatch("[b-ce-e]", "e", true, false);
} }
@Test
public void testTwoRangesInOneGroupCase5() throws Exception { public void testTwoRangesInOneGroupCase5() throws Exception {
assertMatch("[b-ce-e]", "f", false, false); assertMatch("[b-ce-e]", "f", false, false);
} }
@Test
public void testIncompleteRangesInOneGroupCase0() throws Exception { public void testIncompleteRangesInOneGroupCase0() throws Exception {
assertMatch("a[b-]", "ab", true, false); assertMatch("a[b-]", "ab", true, false);
} }
@Test
public void testIncompleteRangesInOneGroupCase1() throws Exception { public void testIncompleteRangesInOneGroupCase1() throws Exception {
assertMatch("a[b-]", "ac", false, false); assertMatch("a[b-]", "ac", false, false);
} }
@Test
public void testIncompleteRangesInOneGroupCase2() throws Exception { public void testIncompleteRangesInOneGroupCase2() throws Exception {
assertMatch("a[b-]", "a-", true, false); assertMatch("a[b-]", "a-", true, false);
} }
@Test
public void testCombinedRangesInOneGroupCase0() throws Exception { public void testCombinedRangesInOneGroupCase0() throws Exception {
assertMatch("[a-c-e]", "b", true, false); assertMatch("[a-c-e]", "b", true, false);
} }
@ -254,383 +300,476 @@ public class FileNameMatcherTest extends TestCase {
* @throws Exception * @throws Exception
* for some reasons * for some reasons
*/ */
@Test
public void testCombinedRangesInOneGroupCase1() throws Exception { public void testCombinedRangesInOneGroupCase1() throws Exception {
assertMatch("[a-c-e]", "d", false, false); assertMatch("[a-c-e]", "d", false, false);
} }
@Test
public void testCombinedRangesInOneGroupCase2() throws Exception { public void testCombinedRangesInOneGroupCase2() throws Exception {
assertMatch("[a-c-e]", "e", true, false); assertMatch("[a-c-e]", "e", true, false);
} }
@Test
public void testInversedGroupCase0() throws Exception { public void testInversedGroupCase0() throws Exception {
assertMatch("[!b-c]", "a", true, false); assertMatch("[!b-c]", "a", true, false);
} }
@Test
public void testInversedGroupCase1() throws Exception { public void testInversedGroupCase1() throws Exception {
assertMatch("[!b-c]", "b", false, false); assertMatch("[!b-c]", "b", false, false);
} }
@Test
public void testInversedGroupCase2() throws Exception { public void testInversedGroupCase2() throws Exception {
assertMatch("[!b-c]", "c", false, false); assertMatch("[!b-c]", "c", false, false);
} }
@Test
public void testInversedGroupCase3() throws Exception { public void testInversedGroupCase3() throws Exception {
assertMatch("[!b-c]", "d", true, false); assertMatch("[!b-c]", "d", true, false);
} }
@Test
public void testAlphaGroupCase0() throws Exception { public void testAlphaGroupCase0() throws Exception {
assertMatch("[[:alpha:]]", "d", true, false); assertMatch("[[:alpha:]]", "d", true, false);
} }
@Test
public void testAlphaGroupCase1() throws Exception { public void testAlphaGroupCase1() throws Exception {
assertMatch("[[:alpha:]]", ":", false, false); assertMatch("[[:alpha:]]", ":", false, false);
} }
@Test
public void testAlphaGroupCase2() throws Exception { public void testAlphaGroupCase2() throws Exception {
// \u00f6 = 'o' with dots on it // \u00f6 = 'o' with dots on it
assertMatch("[[:alpha:]]", "\u00f6", true, false); assertMatch("[[:alpha:]]", "\u00f6", true, false);
} }
@Test
public void test2AlphaGroupsCase0() throws Exception { public void test2AlphaGroupsCase0() throws Exception {
// \u00f6 = 'o' with dots on it // \u00f6 = 'o' with dots on it
assertMatch("[[:alpha:]][[:alpha:]]", "a\u00f6", true, false); assertMatch("[[:alpha:]][[:alpha:]]", "a\u00f6", true, false);
assertMatch("[[:alpha:]][[:alpha:]]", "a1", false, false); assertMatch("[[:alpha:]][[:alpha:]]", "a1", false, false);
} }
@Test
public void testAlnumGroupCase0() throws Exception { public void testAlnumGroupCase0() throws Exception {
assertMatch("[[:alnum:]]", "a", true, false); assertMatch("[[:alnum:]]", "a", true, false);
} }
@Test
public void testAlnumGroupCase1() throws Exception { public void testAlnumGroupCase1() throws Exception {
assertMatch("[[:alnum:]]", "1", true, false); assertMatch("[[:alnum:]]", "1", true, false);
} }
@Test
public void testAlnumGroupCase2() throws Exception { public void testAlnumGroupCase2() throws Exception {
assertMatch("[[:alnum:]]", ":", false, false); assertMatch("[[:alnum:]]", ":", false, false);
} }
@Test
public void testBlankGroupCase0() throws Exception { public void testBlankGroupCase0() throws Exception {
assertMatch("[[:blank:]]", " ", true, false); assertMatch("[[:blank:]]", " ", true, false);
} }
@Test
public void testBlankGroupCase1() throws Exception { public void testBlankGroupCase1() throws Exception {
assertMatch("[[:blank:]]", "\t", true, false); assertMatch("[[:blank:]]", "\t", true, false);
} }
@Test
public void testBlankGroupCase2() throws Exception { public void testBlankGroupCase2() throws Exception {
assertMatch("[[:blank:]]", "\r", false, false); assertMatch("[[:blank:]]", "\r", false, false);
} }
@Test
public void testBlankGroupCase3() throws Exception { public void testBlankGroupCase3() throws Exception {
assertMatch("[[:blank:]]", "\n", false, false); assertMatch("[[:blank:]]", "\n", false, false);
} }
@Test
public void testBlankGroupCase4() throws Exception { public void testBlankGroupCase4() throws Exception {
assertMatch("[[:blank:]]", "a", false, false); assertMatch("[[:blank:]]", "a", false, false);
} }
@Test
public void testCntrlGroupCase0() throws Exception { public void testCntrlGroupCase0() throws Exception {
assertMatch("[[:cntrl:]]", "a", false, false); assertMatch("[[:cntrl:]]", "a", false, false);
} }
@Test
public void testCntrlGroupCase1() throws Exception { public void testCntrlGroupCase1() throws Exception {
assertMatch("[[:cntrl:]]", String.valueOf((char) 7), true, false); assertMatch("[[:cntrl:]]", String.valueOf((char) 7), true, false);
} }
@Test
public void testDigitGroupCase0() throws Exception { public void testDigitGroupCase0() throws Exception {
assertMatch("[[:digit:]]", "0", true, false); assertMatch("[[:digit:]]", "0", true, false);
} }
@Test
public void testDigitGroupCase1() throws Exception { public void testDigitGroupCase1() throws Exception {
assertMatch("[[:digit:]]", "5", true, false); assertMatch("[[:digit:]]", "5", true, false);
} }
@Test
public void testDigitGroupCase2() throws Exception { public void testDigitGroupCase2() throws Exception {
assertMatch("[[:digit:]]", "9", true, false); assertMatch("[[:digit:]]", "9", true, false);
} }
@Test
public void testDigitGroupCase3() throws Exception { public void testDigitGroupCase3() throws Exception {
// \u06f9 = EXTENDED ARABIC-INDIC DIGIT NINE // \u06f9 = EXTENDED ARABIC-INDIC DIGIT NINE
assertMatch("[[:digit:]]", "\u06f9", true, false); assertMatch("[[:digit:]]", "\u06f9", true, false);
} }
@Test
public void testDigitGroupCase4() throws Exception { public void testDigitGroupCase4() throws Exception {
assertMatch("[[:digit:]]", "a", false, false); assertMatch("[[:digit:]]", "a", false, false);
} }
@Test
public void testDigitGroupCase5() throws Exception { public void testDigitGroupCase5() throws Exception {
assertMatch("[[:digit:]]", "]", false, false); assertMatch("[[:digit:]]", "]", false, false);
} }
@Test
public void testGraphGroupCase0() throws Exception { public void testGraphGroupCase0() throws Exception {
assertMatch("[[:graph:]]", "]", true, false); assertMatch("[[:graph:]]", "]", true, false);
} }
@Test
public void testGraphGroupCase1() throws Exception { public void testGraphGroupCase1() throws Exception {
assertMatch("[[:graph:]]", "a", true, false); assertMatch("[[:graph:]]", "a", true, false);
} }
@Test
public void testGraphGroupCase2() throws Exception { public void testGraphGroupCase2() throws Exception {
assertMatch("[[:graph:]]", ".", true, false); assertMatch("[[:graph:]]", ".", true, false);
} }
@Test
public void testGraphGroupCase3() throws Exception { public void testGraphGroupCase3() throws Exception {
assertMatch("[[:graph:]]", "0", true, false); assertMatch("[[:graph:]]", "0", true, false);
} }
@Test
public void testGraphGroupCase4() throws Exception { public void testGraphGroupCase4() throws Exception {
assertMatch("[[:graph:]]", " ", false, false); assertMatch("[[:graph:]]", " ", false, false);
} }
@Test
public void testGraphGroupCase5() throws Exception { public void testGraphGroupCase5() throws Exception {
// \u00f6 = 'o' with dots on it // \u00f6 = 'o' with dots on it
assertMatch("[[:graph:]]", "\u00f6", true, false); assertMatch("[[:graph:]]", "\u00f6", true, false);
} }
@Test
public void testLowerGroupCase0() throws Exception { public void testLowerGroupCase0() throws Exception {
assertMatch("[[:lower:]]", "a", true, false); assertMatch("[[:lower:]]", "a", true, false);
} }
@Test
public void testLowerGroupCase1() throws Exception { public void testLowerGroupCase1() throws Exception {
assertMatch("[[:lower:]]", "h", true, false); assertMatch("[[:lower:]]", "h", true, false);
} }
@Test
public void testLowerGroupCase2() throws Exception { public void testLowerGroupCase2() throws Exception {
assertMatch("[[:lower:]]", "A", false, false); assertMatch("[[:lower:]]", "A", false, false);
} }
@Test
public void testLowerGroupCase3() throws Exception { public void testLowerGroupCase3() throws Exception {
assertMatch("[[:lower:]]", "H", false, false); assertMatch("[[:lower:]]", "H", false, false);
} }
@Test
public void testLowerGroupCase4() throws Exception { public void testLowerGroupCase4() throws Exception {
// \u00e4 = small 'a' with dots on it // \u00e4 = small 'a' with dots on it
assertMatch("[[:lower:]]", "\u00e4", true, false); assertMatch("[[:lower:]]", "\u00e4", true, false);
} }
@Test
public void testLowerGroupCase5() throws Exception { public void testLowerGroupCase5() throws Exception {
assertMatch("[[:lower:]]", ".", false, false); assertMatch("[[:lower:]]", ".", false, false);
} }
@Test
public void testPrintGroupCase0() throws Exception { public void testPrintGroupCase0() throws Exception {
assertMatch("[[:print:]]", "]", true, false); assertMatch("[[:print:]]", "]", true, false);
} }
@Test
public void testPrintGroupCase1() throws Exception { public void testPrintGroupCase1() throws Exception {
assertMatch("[[:print:]]", "a", true, false); assertMatch("[[:print:]]", "a", true, false);
} }
@Test
public void testPrintGroupCase2() throws Exception { public void testPrintGroupCase2() throws Exception {
assertMatch("[[:print:]]", ".", true, false); assertMatch("[[:print:]]", ".", true, false);
} }
@Test
public void testPrintGroupCase3() throws Exception { public void testPrintGroupCase3() throws Exception {
assertMatch("[[:print:]]", "0", true, false); assertMatch("[[:print:]]", "0", true, false);
} }
@Test
public void testPrintGroupCase4() throws Exception { public void testPrintGroupCase4() throws Exception {
assertMatch("[[:print:]]", " ", true, false); assertMatch("[[:print:]]", " ", true, false);
} }
@Test
public void testPrintGroupCase5() throws Exception { public void testPrintGroupCase5() throws Exception {
// \u00f6 = 'o' with dots on it // \u00f6 = 'o' with dots on it
assertMatch("[[:print:]]", "\u00f6", true, false); assertMatch("[[:print:]]", "\u00f6", true, false);
} }
@Test
public void testPunctGroupCase0() throws Exception { public void testPunctGroupCase0() throws Exception {
assertMatch("[[:punct:]]", ".", true, false); assertMatch("[[:punct:]]", ".", true, false);
} }
@Test
public void testPunctGroupCase1() throws Exception { public void testPunctGroupCase1() throws Exception {
assertMatch("[[:punct:]]", "@", true, false); assertMatch("[[:punct:]]", "@", true, false);
} }
@Test
public void testPunctGroupCase2() throws Exception { public void testPunctGroupCase2() throws Exception {
assertMatch("[[:punct:]]", " ", false, false); assertMatch("[[:punct:]]", " ", false, false);
} }
@Test
public void testPunctGroupCase3() throws Exception { public void testPunctGroupCase3() throws Exception {
assertMatch("[[:punct:]]", "a", false, false); assertMatch("[[:punct:]]", "a", false, false);
} }
@Test
public void testSpaceGroupCase0() throws Exception { public void testSpaceGroupCase0() throws Exception {
assertMatch("[[:space:]]", " ", true, false); assertMatch("[[:space:]]", " ", true, false);
} }
@Test
public void testSpaceGroupCase1() throws Exception { public void testSpaceGroupCase1() throws Exception {
assertMatch("[[:space:]]", "\t", true, false); assertMatch("[[:space:]]", "\t", true, false);
} }
@Test
public void testSpaceGroupCase2() throws Exception { public void testSpaceGroupCase2() throws Exception {
assertMatch("[[:space:]]", "\r", true, false); assertMatch("[[:space:]]", "\r", true, false);
} }
@Test
public void testSpaceGroupCase3() throws Exception { public void testSpaceGroupCase3() throws Exception {
assertMatch("[[:space:]]", "\n", true, false); assertMatch("[[:space:]]", "\n", true, false);
} }
@Test
public void testSpaceGroupCase4() throws Exception { public void testSpaceGroupCase4() throws Exception {
assertMatch("[[:space:]]", "a", false, false); assertMatch("[[:space:]]", "a", false, false);
} }
@Test
public void testUpperGroupCase0() throws Exception { public void testUpperGroupCase0() throws Exception {
assertMatch("[[:upper:]]", "a", false, false); assertMatch("[[:upper:]]", "a", false, false);
} }
@Test
public void testUpperGroupCase1() throws Exception { public void testUpperGroupCase1() throws Exception {
assertMatch("[[:upper:]]", "h", false, false); assertMatch("[[:upper:]]", "h", false, false);
} }
@Test
public void testUpperGroupCase2() throws Exception { public void testUpperGroupCase2() throws Exception {
assertMatch("[[:upper:]]", "A", true, false); assertMatch("[[:upper:]]", "A", true, false);
} }
@Test
public void testUpperGroupCase3() throws Exception { public void testUpperGroupCase3() throws Exception {
assertMatch("[[:upper:]]", "H", true, false); assertMatch("[[:upper:]]", "H", true, false);
} }
@Test
public void testUpperGroupCase4() throws Exception { public void testUpperGroupCase4() throws Exception {
// \u00c4 = 'A' with dots on it // \u00c4 = 'A' with dots on it
assertMatch("[[:upper:]]", "\u00c4", true, false); assertMatch("[[:upper:]]", "\u00c4", true, false);
} }
@Test
public void testUpperGroupCase5() throws Exception { public void testUpperGroupCase5() throws Exception {
assertMatch("[[:upper:]]", ".", false, false); assertMatch("[[:upper:]]", ".", false, false);
} }
@Test
public void testXDigitGroupCase0() throws Exception { public void testXDigitGroupCase0() throws Exception {
assertMatch("[[:xdigit:]]", "a", true, false); assertMatch("[[:xdigit:]]", "a", true, false);
} }
@Test
public void testXDigitGroupCase1() throws Exception { public void testXDigitGroupCase1() throws Exception {
assertMatch("[[:xdigit:]]", "d", true, false); assertMatch("[[:xdigit:]]", "d", true, false);
} }
@Test
public void testXDigitGroupCase2() throws Exception { public void testXDigitGroupCase2() throws Exception {
assertMatch("[[:xdigit:]]", "f", true, false); assertMatch("[[:xdigit:]]", "f", true, false);
} }
@Test
public void testXDigitGroupCase3() throws Exception { public void testXDigitGroupCase3() throws Exception {
assertMatch("[[:xdigit:]]", "0", true, false); assertMatch("[[:xdigit:]]", "0", true, false);
} }
@Test
public void testXDigitGroupCase4() throws Exception { public void testXDigitGroupCase4() throws Exception {
assertMatch("[[:xdigit:]]", "5", true, false); assertMatch("[[:xdigit:]]", "5", true, false);
} }
@Test
public void testXDigitGroupCase5() throws Exception { public void testXDigitGroupCase5() throws Exception {
assertMatch("[[:xdigit:]]", "9", true, false); assertMatch("[[:xdigit:]]", "9", true, false);
} }
@Test
public void testXDigitGroupCase6() throws Exception { public void testXDigitGroupCase6() throws Exception {
assertMatch("[[:xdigit:]]", "۹", false, false); assertMatch("[[:xdigit:]]", "۹", false, false);
} }
@Test
public void testXDigitGroupCase7() throws Exception { public void testXDigitGroupCase7() throws Exception {
assertMatch("[[:xdigit:]]", ".", false, false); assertMatch("[[:xdigit:]]", ".", false, false);
} }
@Test
public void testWordroupCase0() throws Exception { public void testWordroupCase0() throws Exception {
assertMatch("[[:word:]]", "g", true, false); assertMatch("[[:word:]]", "g", true, false);
} }
@Test
public void testWordroupCase1() throws Exception { public void testWordroupCase1() throws Exception {
// \u00f6 = 'o' with dots on it // \u00f6 = 'o' with dots on it
assertMatch("[[:word:]]", "\u00f6", true, false); assertMatch("[[:word:]]", "\u00f6", true, false);
} }
@Test
public void testWordroupCase2() throws Exception { public void testWordroupCase2() throws Exception {
assertMatch("[[:word:]]", "5", true, false); assertMatch("[[:word:]]", "5", true, false);
} }
@Test
public void testWordroupCase3() throws Exception { public void testWordroupCase3() throws Exception {
assertMatch("[[:word:]]", "_", true, false); assertMatch("[[:word:]]", "_", true, false);
} }
@Test
public void testWordroupCase4() throws Exception { public void testWordroupCase4() throws Exception {
assertMatch("[[:word:]]", " ", false, false); assertMatch("[[:word:]]", " ", false, false);
} }
@Test
public void testWordroupCase5() throws Exception { public void testWordroupCase5() throws Exception {
assertMatch("[[:word:]]", ".", false, false); assertMatch("[[:word:]]", ".", false, false);
} }
@Test
public void testMixedGroupCase0() throws Exception { public void testMixedGroupCase0() throws Exception {
assertMatch("[A[:lower:]C3-5]", "A", true, false); assertMatch("[A[:lower:]C3-5]", "A", true, false);
} }
@Test
public void testMixedGroupCase1() throws Exception { public void testMixedGroupCase1() throws Exception {
assertMatch("[A[:lower:]C3-5]", "C", true, false); assertMatch("[A[:lower:]C3-5]", "C", true, false);
} }
@Test
public void testMixedGroupCase2() throws Exception { public void testMixedGroupCase2() throws Exception {
assertMatch("[A[:lower:]C3-5]", "e", true, false); assertMatch("[A[:lower:]C3-5]", "e", true, false);
} }
@Test
public void testMixedGroupCase3() throws Exception { public void testMixedGroupCase3() throws Exception {
assertMatch("[A[:lower:]C3-5]", "3", true, false); assertMatch("[A[:lower:]C3-5]", "3", true, false);
} }
@Test
public void testMixedGroupCase4() throws Exception { public void testMixedGroupCase4() throws Exception {
assertMatch("[A[:lower:]C3-5]", "4", true, false); assertMatch("[A[:lower:]C3-5]", "4", true, false);
} }
@Test
public void testMixedGroupCase5() throws Exception { public void testMixedGroupCase5() throws Exception {
assertMatch("[A[:lower:]C3-5]", "5", true, false); assertMatch("[A[:lower:]C3-5]", "5", true, false);
} }
@Test
public void testMixedGroupCase6() throws Exception { public void testMixedGroupCase6() throws Exception {
assertMatch("[A[:lower:]C3-5]", "B", false, false); assertMatch("[A[:lower:]C3-5]", "B", false, false);
} }
@Test
public void testMixedGroupCase7() throws Exception { public void testMixedGroupCase7() throws Exception {
assertMatch("[A[:lower:]C3-5]", "2", false, false); assertMatch("[A[:lower:]C3-5]", "2", false, false);
} }
@Test
public void testMixedGroupCase8() throws Exception { public void testMixedGroupCase8() throws Exception {
assertMatch("[A[:lower:]C3-5]", "6", false, false); assertMatch("[A[:lower:]C3-5]", "6", false, false);
} }
@Test
public void testMixedGroupCase9() throws Exception { public void testMixedGroupCase9() throws Exception {
assertMatch("[A[:lower:]C3-5]", ".", false, false); assertMatch("[A[:lower:]C3-5]", ".", false, false);
} }
@Test
public void testSpecialGroupCase0() throws Exception { public void testSpecialGroupCase0() throws Exception {
assertMatch("[[]", "[", true, false); assertMatch("[[]", "[", true, false);
} }
@Test
public void testSpecialGroupCase1() throws Exception { public void testSpecialGroupCase1() throws Exception {
assertMatch("[]]", "]", true, false); assertMatch("[]]", "]", true, false);
} }
@Test
public void testSpecialGroupCase2() throws Exception { public void testSpecialGroupCase2() throws Exception {
assertMatch("[]a]", "]", true, false); assertMatch("[]a]", "]", true, false);
} }
@Test
public void testSpecialGroupCase3() throws Exception { public void testSpecialGroupCase3() throws Exception {
assertMatch("[a[]", "[", true, false); assertMatch("[a[]", "[", true, false);
} }
@Test
public void testSpecialGroupCase4() throws Exception { public void testSpecialGroupCase4() throws Exception {
assertMatch("[a[]", "a", true, false); assertMatch("[a[]", "a", true, false);
} }
@Test
public void testSpecialGroupCase5() throws Exception { public void testSpecialGroupCase5() throws Exception {
assertMatch("[!]]", "]", false, false); assertMatch("[!]]", "]", false, false);
} }
@Test
public void testSpecialGroupCase6() throws Exception { public void testSpecialGroupCase6() throws Exception {
assertMatch("[!]]", "x", true, false); assertMatch("[!]]", "x", true, false);
} }
@Test
public void testSpecialGroupCase7() throws Exception { public void testSpecialGroupCase7() throws Exception {
assertMatch("[:]]", ":]", true, false); assertMatch("[:]]", ":]", true, false);
} }
@Test
public void testSpecialGroupCase8() throws Exception { public void testSpecialGroupCase8() throws Exception {
assertMatch("[:]]", ":", false, true); assertMatch("[:]]", ":", false, true);
} }
@Test
public void testSpecialGroupCase9() throws Exception { public void testSpecialGroupCase9() throws Exception {
try { try {
assertMatch("[[:]", ":", true, true); assertMatch("[[:]", ":", true, true);
@ -640,6 +779,7 @@ public class FileNameMatcherTest extends TestCase {
} }
} }
@Test
public void testUnsupportedGroupCase0() throws Exception { public void testUnsupportedGroupCase0() throws Exception {
try { try {
assertMatch("[[=a=]]", "b", false, false); assertMatch("[[=a=]]", "b", false, false);
@ -649,6 +789,7 @@ public class FileNameMatcherTest extends TestCase {
} }
} }
@Test
public void testUnsupportedGroupCase1() throws Exception { public void testUnsupportedGroupCase1() throws Exception {
try { try {
assertMatch("[[.a.]]", "b", false, false); assertMatch("[[.a.]]", "b", false, false);
@ -658,26 +799,32 @@ public class FileNameMatcherTest extends TestCase {
} }
} }
@Test
public void testFilePathSimpleCase() throws Exception { public void testFilePathSimpleCase() throws Exception {
assertFileNameMatch("a/b", "a/b", '/', true, false); assertFileNameMatch("a/b", "a/b", '/', true, false);
} }
@Test
public void testFilePathCase0() throws Exception { public void testFilePathCase0() throws Exception {
assertFileNameMatch("a*b", "a/b", '/', false, false); assertFileNameMatch("a*b", "a/b", '/', false, false);
} }
@Test
public void testFilePathCase1() throws Exception { public void testFilePathCase1() throws Exception {
assertFileNameMatch("a?b", "a/b", '/', false, false); assertFileNameMatch("a?b", "a/b", '/', false, false);
} }
@Test
public void testFilePathCase2() throws Exception { public void testFilePathCase2() throws Exception {
assertFileNameMatch("a*b", "a\\b", '\\', false, false); assertFileNameMatch("a*b", "a\\b", '\\', false, false);
} }
@Test
public void testFilePathCase3() throws Exception { public void testFilePathCase3() throws Exception {
assertFileNameMatch("a?b", "a\\b", '\\', false, false); assertFileNameMatch("a?b", "a\\b", '\\', false, false);
} }
@Test
public void testReset() throws Exception { public void testReset() throws Exception {
final String pattern = "helloworld"; final String pattern = "helloworld";
final FileNameMatcher matcher = new FileNameMatcher(pattern, null); final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
@ -700,6 +847,7 @@ public class FileNameMatcherTest extends TestCase {
assertEquals(false, matcher.canAppendMatch()); assertEquals(false, matcher.canAppendMatch());
} }
@Test
public void testCreateMatcherForSuffix() throws Exception { public void testCreateMatcherForSuffix() throws Exception {
final String pattern = "helloworld"; final String pattern = "helloworld";
final FileNameMatcher matcher = new FileNameMatcher(pattern, null); final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
@ -731,6 +879,7 @@ public class FileNameMatcherTest extends TestCase {
assertEquals(false, childMatcher.canAppendMatch()); assertEquals(false, childMatcher.canAppendMatch());
} }
@Test
public void testCopyConstructor() throws Exception { public void testCopyConstructor() throws Exception {
final String pattern = "helloworld"; final String pattern = "helloworld";
final FileNameMatcher matcher = new FileNameMatcher(pattern, null); final FileNameMatcher matcher = new FileNameMatcher(pattern, null);

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java

@ -42,15 +42,19 @@
*/ */
package org.eclipse.jgit.ignore; package org.eclipse.jgit.ignore;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import junit.framework.TestCase; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/** /**
* Tests ignore pattern matches * Tests ignore pattern matches
*/ */
public class IgnoreMatcherTest extends TestCase{ public class IgnoreMatcherTest {
@Test
public void testBasic() { public void testBasic() {
String pattern = "/test.stp"; String pattern = "/test.stp";
assertMatched(pattern, "/test.stp"); assertMatched(pattern, "/test.stp");
@ -59,6 +63,7 @@ public class IgnoreMatcherTest extends TestCase{
assertNotMatched(pattern, "/test.stp"); assertNotMatched(pattern, "/test.stp");
} }
@Test
public void testFileNameWildcards() { public void testFileNameWildcards() {
//Test basic * and ? for any pattern + any character //Test basic * and ? for any pattern + any character
String pattern = "*.st?"; String pattern = "*.st?";
@ -118,6 +123,7 @@ public class IgnoreMatcherTest extends TestCase{
assertNotMatched(pattern, "/src/new.c"); assertNotMatched(pattern, "/src/new.c");
} }
@Test
public void testTargetWithoutLeadingSlash() { public void testTargetWithoutLeadingSlash() {
//Test basic * and ? for any pattern + any character //Test basic * and ? for any pattern + any character
String pattern = "/*.st?"; String pattern = "/*.st?";
@ -177,6 +183,7 @@ public class IgnoreMatcherTest extends TestCase{
assertNotMatched(pattern, "src/new.c"); assertNotMatched(pattern, "src/new.c");
} }
@Test
public void testParentDirectoryGitIgnores() { public void testParentDirectoryGitIgnores() {
//Contains git ignore patterns such as might be seen in a parent directory //Contains git ignore patterns such as might be seen in a parent directory
@ -210,6 +217,7 @@ public class IgnoreMatcherTest extends TestCase{
assertNotMatched(pattern, "/src/new/a/file.c"); assertNotMatched(pattern, "/src/new/a/file.c");
} }
@Test
public void testTrailingSlash() { public void testTrailingSlash() {
String pattern = "/src/"; String pattern = "/src/";
assertMatched(pattern, "/src/"); assertMatched(pattern, "/src/");
@ -220,6 +228,7 @@ public class IgnoreMatcherTest extends TestCase{
assertNotMatched(pattern, "/srcA/"); assertNotMatched(pattern, "/srcA/");
} }
@Test
public void testNameOnlyMatches() { public void testNameOnlyMatches() {
/* /*
* Name-only matches do not contain any path separators * Name-only matches do not contain any path separators
@ -270,11 +279,13 @@ public class IgnoreMatcherTest extends TestCase{
assertNotMatched(pattern, "/cr3"); assertNotMatched(pattern, "/cr3");
} }
@Test
public void testNegation() { public void testNegation() {
String pattern = "!/test.stp"; String pattern = "!/test.stp";
assertMatched(pattern, "/test.stp"); assertMatched(pattern, "/test.stp");
} }
@Test
public void testGetters() { public void testGetters() {
IgnoreRule r = new IgnoreRule("/pattern/"); IgnoreRule r = new IgnoreRule("/pattern/");
assertFalse(r.getNameOnly()); assertFalse(r.getNameOnly());
@ -329,7 +340,8 @@ public class IgnoreMatcherTest extends TestCase{
*/ */
public void assertMatched(String pattern, String target) { public void assertMatched(String pattern, String target) {
boolean value = match(pattern, target); boolean value = match(pattern, target);
Assert.assertTrue("Expected a match for: " + pattern + " with: " + target, value); assertTrue("Expected a match for: " + pattern + " with: " + target,
value);
} }
/** /**
@ -342,7 +354,8 @@ public class IgnoreMatcherTest extends TestCase{
*/ */
public void assertNotMatched(String pattern, String target) { public void assertNotMatched(String pattern, String target) {
boolean value = match(pattern, target); boolean value = match(pattern, target);
Assert.assertFalse("Expected no match for: " + pattern + " with: " + target, value); assertFalse("Expected no match for: " + pattern + " with: " + target,
value);
} }
/** /**

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java

@ -42,6 +42,10 @@
*/ */
package org.eclipse.jgit.ignore; package org.eclipse.jgit.ignore;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -52,6 +56,7 @@ import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
/** /**
* Tests ignore node behavior on the local filesystem. * Tests ignore node behavior on the local filesystem.
@ -67,6 +72,7 @@ public class IgnoreNodeTest extends RepositoryTestCase {
private TreeWalk walk; private TreeWalk walk;
@Test
public void testRules() throws IOException { public void testRules() throws IOException {
writeIgnoreFile(".git/info/exclude", "*~", "/out"); writeIgnoreFile(".git/info/exclude", "*~", "/out");
@ -105,6 +111,7 @@ public class IgnoreNodeTest extends RepositoryTestCase {
assertEntry(F, ignored, "src/config/old/lex.out"); assertEntry(F, ignored, "src/config/old/lex.out");
} }
@Test
public void testNegation() throws IOException { public void testNegation() throws IOException {
writeIgnoreFile(".gitignore", "*.o"); writeIgnoreFile(".gitignore", "*.o");
writeIgnoreFile("src/a/b/.gitignore", "!keep.o"); writeIgnoreFile("src/a/b/.gitignore", "!keep.o");
@ -121,6 +128,7 @@ public class IgnoreNodeTest extends RepositoryTestCase {
assertEntry(F, ignored, "src/a/b/nothere.o"); assertEntry(F, ignored, "src/a/b/nothere.o");
} }
@Test
public void testSlashOnlyMatchesDirectory() throws IOException { public void testSlashOnlyMatchesDirectory() throws IOException {
writeIgnoreFile(".gitignore", "out/"); writeIgnoreFile(".gitignore", "out/");
writeTrashFile("out", ""); writeTrashFile("out", "");
@ -138,6 +146,7 @@ public class IgnoreNodeTest extends RepositoryTestCase {
assertEntry(F, ignored, "out/foo"); assertEntry(F, ignored, "out/foo");
} }
@Test
public void testWithSlashDoesNotMatchInSubDirectory() throws IOException { public void testWithSlashDoesNotMatchInSubDirectory() throws IOException {
writeIgnoreFile(".gitignore", "a/b"); writeIgnoreFile(".gitignore", "a/b");
writeTrashFile("a/a", ""); writeTrashFile("a/a", "");

36
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbreviatedObjectIdTest.java

@ -43,9 +43,17 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class AbbreviatedObjectIdTest extends TestCase { import org.junit.Test;
public class AbbreviatedObjectIdTest {
@Test
public void testEmpty_FromByteArray() { public void testEmpty_FromByteArray() {
final AbbreviatedObjectId i; final AbbreviatedObjectId i;
i = AbbreviatedObjectId.fromString(new byte[] {}, 0, 0); i = AbbreviatedObjectId.fromString(new byte[] {}, 0, 0);
@ -55,6 +63,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertEquals("", i.name()); assertEquals("", i.name());
} }
@Test
public void testEmpty_FromString() { public void testEmpty_FromString() {
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(""); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString("");
assertNotNull(i); assertNotNull(i);
@ -63,6 +72,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertEquals("", i.name()); assertEquals("", i.name());
} }
@Test
public void testFull_FromByteArray() { public void testFull_FromByteArray() {
final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
final byte[] b = Constants.encodeASCII(s); final byte[] b = Constants.encodeASCII(s);
@ -79,6 +89,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertEquals(f.hashCode(), i.hashCode()); assertEquals(f.hashCode(), i.hashCode());
} }
@Test
public void testFull_FromString() { public void testFull_FromString() {
final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -93,6 +104,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertEquals(f.hashCode(), i.hashCode()); assertEquals(f.hashCode(), i.hashCode());
} }
@Test
public void test1_FromString() { public void test1_FromString() {
final String s = "7"; final String s = "7";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -103,6 +115,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test2_FromString() { public void test2_FromString() {
final String s = "7b"; final String s = "7b";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -113,6 +126,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test3_FromString() { public void test3_FromString() {
final String s = "7b6"; final String s = "7b6";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -123,6 +137,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test4_FromString() { public void test4_FromString() {
final String s = "7b6e"; final String s = "7b6e";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -133,6 +148,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test5_FromString() { public void test5_FromString() {
final String s = "7b6e8"; final String s = "7b6e8";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -143,6 +159,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test6_FromString() { public void test6_FromString() {
final String s = "7b6e80"; final String s = "7b6e80";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -153,6 +170,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test7_FromString() { public void test7_FromString() {
final String s = "7b6e806"; final String s = "7b6e806";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -163,6 +181,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test8_FromString() { public void test8_FromString() {
final String s = "7b6e8067"; final String s = "7b6e8067";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -173,6 +192,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test9_FromString() { public void test9_FromString() {
final String s = "7b6e8067e"; final String s = "7b6e8067e";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -183,6 +203,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void test17_FromString() { public void test17_FromString() {
final String s = "7b6e8067ec96acef9"; final String s = "7b6e8067ec96acef9";
final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s);
@ -193,6 +214,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertNull(i.toObjectId()); assertNull(i.toObjectId());
} }
@Test
public void testEquals_Short() { public void testEquals_Short() {
final String s = "7b6e8067"; final String s = "7b6e8067";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s);
@ -203,6 +225,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertTrue(b.equals(a)); assertTrue(b.equals(a));
} }
@Test
public void testEquals_Full() { public void testEquals_Full() {
final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s);
@ -213,6 +236,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertTrue(b.equals(a)); assertTrue(b.equals(a));
} }
@Test
public void testNotEquals_SameLength() { public void testNotEquals_SameLength() {
final String sa = "7b6e8067"; final String sa = "7b6e8067";
final String sb = "7b6e806e"; final String sb = "7b6e806e";
@ -222,6 +246,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(b.equals(a)); assertFalse(b.equals(a));
} }
@Test
public void testNotEquals_DiffLength() { public void testNotEquals_DiffLength() {
final String sa = "7b6e8067abcd"; final String sa = "7b6e8067abcd";
final String sb = "7b6e8067"; final String sb = "7b6e8067";
@ -231,6 +256,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(b.equals(a)); assertFalse(b.equals(a));
} }
@Test
public void testPrefixCompare_Full() { public void testPrefixCompare_Full() {
final String s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final String s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s1); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s1);
@ -249,6 +275,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(i3.startsWith(a)); assertFalse(i3.startsWith(a));
} }
@Test
public void testPrefixCompare_1() { public void testPrefixCompare_1() {
final String sa = "7"; final String sa = "7";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
@ -269,6 +296,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(i3.startsWith(a)); assertFalse(i3.startsWith(a));
} }
@Test
public void testPrefixCompare_7() { public void testPrefixCompare_7() {
final String sa = "7b6e806"; final String sa = "7b6e806";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
@ -289,6 +317,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(i3.startsWith(a)); assertFalse(i3.startsWith(a));
} }
@Test
public void testPrefixCompare_8() { public void testPrefixCompare_8() {
final String sa = "7b6e8067"; final String sa = "7b6e8067";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
@ -309,6 +338,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(i3.startsWith(a)); assertFalse(i3.startsWith(a));
} }
@Test
public void testPrefixCompare_9() { public void testPrefixCompare_9() {
final String sa = "7b6e8067e"; final String sa = "7b6e8067e";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
@ -329,6 +359,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(i3.startsWith(a)); assertFalse(i3.startsWith(a));
} }
@Test
public void testPrefixCompare_17() { public void testPrefixCompare_17() {
final String sa = "7b6e8067ec96acef9"; final String sa = "7b6e8067ec96acef9";
final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa);
@ -349,6 +380,7 @@ public class AbbreviatedObjectIdTest extends TestCase {
assertFalse(i3.startsWith(a)); assertFalse(i3.startsWith(a));
} }
@Test
public void testIsId() { public void testIsId() {
// These are all too short. // These are all too short.
assertFalse(AbbreviatedObjectId.isId("")); assertFalse(AbbreviatedObjectId.isId(""));

37
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java

@ -48,28 +48,37 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Set; import java.util.Set;
import junit.framework.TestCase;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.SystemReader;
import org.junit.Test;
/** /**
* Test reading of git config * Test reading of git config
*/ */
public class ConfigTest extends TestCase { public class ConfigTest {
@Test
public void test001_ReadBareKey() throws ConfigInvalidException { public void test001_ReadBareKey() throws ConfigInvalidException {
final Config c = parse("[foo]\nbar\n"); final Config c = parse("[foo]\nbar\n");
assertEquals(true, c.getBoolean("foo", null, "bar", false)); assertEquals(true, c.getBoolean("foo", null, "bar", false));
assertEquals("", c.getString("foo", null, "bar")); assertEquals("", c.getString("foo", null, "bar"));
} }
@Test
public void test002_ReadWithSubsection() throws ConfigInvalidException { public void test002_ReadWithSubsection() throws ConfigInvalidException {
final Config c = parse("[foo \"zip\"]\nbar\n[foo \"zap\"]\nbar=false\nn=3\n"); final Config c = parse("[foo \"zip\"]\nbar\n[foo \"zap\"]\nbar=false\nn=3\n");
assertEquals(true, c.getBoolean("foo", "zip", "bar", false)); assertEquals(true, c.getBoolean("foo", "zip", "bar", false));
@ -80,6 +89,7 @@ public class ConfigTest extends TestCase {
assertEquals(4, c.getInt("foo", "zap","m", 4)); assertEquals(4, c.getInt("foo", "zap","m", 4));
} }
@Test
public void test003_PutRemote() { public void test003_PutRemote() {
final Config c = new Config(); final Config c = new Config();
c.setString("sec", "ext", "name", "value"); c.setString("sec", "ext", "name", "value");
@ -88,6 +98,7 @@ public class ConfigTest extends TestCase {
assertEquals(expText, c.toText()); assertEquals(expText, c.toText());
} }
@Test
public void test004_PutGetSimple() { public void test004_PutGetSimple() {
Config c = new Config(); Config c = new Config();
c.setString("my", null, "somename", "false"); c.setString("my", null, "somename", "false");
@ -95,6 +106,7 @@ public class ConfigTest extends TestCase {
assertEquals("[my]\n\tsomename = false\n", c.toText()); assertEquals("[my]\n\tsomename = false\n", c.toText());
} }
@Test
public void test005_PutGetStringList() { public void test005_PutGetStringList() {
Config c = new Config(); Config c = new Config();
final LinkedList<String> values = new LinkedList<String>(); final LinkedList<String> values = new LinkedList<String>();
@ -110,12 +122,14 @@ public class ConfigTest extends TestCase {
assertEquals(expText, c.toText()); assertEquals(expText, c.toText());
} }
@Test
public void test006_readCaseInsensitive() throws ConfigInvalidException { public void test006_readCaseInsensitive() throws ConfigInvalidException {
final Config c = parse("[Foo]\nBar\n"); final Config c = parse("[Foo]\nBar\n");
assertEquals(true, c.getBoolean("foo", null, "bar", false)); assertEquals(true, c.getBoolean("foo", null, "bar", false));
assertEquals("", c.getString("foo", null, "bar")); assertEquals("", c.getString("foo", null, "bar"));
} }
@Test
public void test007_readUserConfig() { public void test007_readUserConfig() {
final MockSystemReader mockSystemReader = new MockSystemReader(); final MockSystemReader mockSystemReader = new MockSystemReader();
SystemReader.setInstance(mockSystemReader); SystemReader.setInstance(mockSystemReader);
@ -176,6 +190,7 @@ public class ConfigTest extends TestCase {
assertEquals("author@localemail", authorEmail); assertEquals("author@localemail", authorEmail);
} }
@Test
public void testReadBoolean_TrueFalse1() throws ConfigInvalidException { public void testReadBoolean_TrueFalse1() throws ConfigInvalidException {
final Config c = parse("[s]\na = true\nb = false\n"); final Config c = parse("[s]\na = true\nb = false\n");
assertEquals("true", c.getString("s", null, "a")); assertEquals("true", c.getString("s", null, "a"));
@ -185,6 +200,7 @@ public class ConfigTest extends TestCase {
assertFalse(c.getBoolean("s", "b", true)); assertFalse(c.getBoolean("s", "b", true));
} }
@Test
public void testReadBoolean_TrueFalse2() throws ConfigInvalidException { public void testReadBoolean_TrueFalse2() throws ConfigInvalidException {
final Config c = parse("[s]\na = TrUe\nb = fAlSe\n"); final Config c = parse("[s]\na = TrUe\nb = fAlSe\n");
assertEquals("TrUe", c.getString("s", null, "a")); assertEquals("TrUe", c.getString("s", null, "a"));
@ -194,6 +210,7 @@ public class ConfigTest extends TestCase {
assertFalse(c.getBoolean("s", "b", true)); assertFalse(c.getBoolean("s", "b", true));
} }
@Test
public void testReadBoolean_YesNo1() throws ConfigInvalidException { public void testReadBoolean_YesNo1() throws ConfigInvalidException {
final Config c = parse("[s]\na = yes\nb = no\n"); final Config c = parse("[s]\na = yes\nb = no\n");
assertEquals("yes", c.getString("s", null, "a")); assertEquals("yes", c.getString("s", null, "a"));
@ -203,6 +220,7 @@ public class ConfigTest extends TestCase {
assertFalse(c.getBoolean("s", "b", true)); assertFalse(c.getBoolean("s", "b", true));
} }
@Test
public void testReadBoolean_YesNo2() throws ConfigInvalidException { public void testReadBoolean_YesNo2() throws ConfigInvalidException {
final Config c = parse("[s]\na = yEs\nb = NO\n"); final Config c = parse("[s]\na = yEs\nb = NO\n");
assertEquals("yEs", c.getString("s", null, "a")); assertEquals("yEs", c.getString("s", null, "a"));
@ -212,6 +230,7 @@ public class ConfigTest extends TestCase {
assertFalse(c.getBoolean("s", "b", true)); assertFalse(c.getBoolean("s", "b", true));
} }
@Test
public void testReadBoolean_OnOff1() throws ConfigInvalidException { public void testReadBoolean_OnOff1() throws ConfigInvalidException {
final Config c = parse("[s]\na = on\nb = off\n"); final Config c = parse("[s]\na = on\nb = off\n");
assertEquals("on", c.getString("s", null, "a")); assertEquals("on", c.getString("s", null, "a"));
@ -221,6 +240,7 @@ public class ConfigTest extends TestCase {
assertFalse(c.getBoolean("s", "b", true)); assertFalse(c.getBoolean("s", "b", true));
} }
@Test
public void testReadBoolean_OnOff2() throws ConfigInvalidException { public void testReadBoolean_OnOff2() throws ConfigInvalidException {
final Config c = parse("[s]\na = ON\nb = OFF\n"); final Config c = parse("[s]\na = ON\nb = OFF\n");
assertEquals("ON", c.getString("s", null, "a")); assertEquals("ON", c.getString("s", null, "a"));
@ -234,6 +254,7 @@ public class ConfigTest extends TestCase {
ONE_TWO; ONE_TWO;
} }
@Test
public void testGetEnum() throws ConfigInvalidException { public void testGetEnum() throws ConfigInvalidException {
Config c = parse("[s]\na = ON\nb = input\nc = true\nd = off\n"); Config c = parse("[s]\na = ON\nb = input\nc = true\nd = off\n");
assertSame(CoreConfig.AutoCRLF.TRUE, c.getEnum("s", null, "a", assertSame(CoreConfig.AutoCRLF.TRUE, c.getEnum("s", null, "a",
@ -256,12 +277,14 @@ public class ConfigTest extends TestCase {
assertSame(TestEnum.ONE_TWO, c.getEnum("s", "b", "c", TestEnum.ONE_TWO)); assertSame(TestEnum.ONE_TWO, c.getEnum("s", "b", "c", TestEnum.ONE_TWO));
} }
@Test
public void testSetEnum() { public void testSetEnum() {
final Config c = new Config(); final Config c = new Config();
c.setEnum("s", "b", "c", TestEnum.ONE_TWO); c.setEnum("s", "b", "c", TestEnum.ONE_TWO);
assertEquals("[s \"b\"]\n\tc = one two\n", c.toText()); assertEquals("[s \"b\"]\n\tc = one two\n", c.toText());
} }
@Test
public void testReadLong() throws ConfigInvalidException { public void testReadLong() throws ConfigInvalidException {
assertReadLong(1L); assertReadLong(1L);
assertReadLong(-1L); assertReadLong(-1L);
@ -279,6 +302,7 @@ public class ConfigTest extends TestCase {
} }
} }
@Test
public void testBooleanWithNoValue() throws ConfigInvalidException { public void testBooleanWithNoValue() throws ConfigInvalidException {
Config c = parse("[my]\n\tempty\n"); Config c = parse("[my]\n\tempty\n");
assertEquals("", c.getString("my", null, "empty")); assertEquals("", c.getString("my", null, "empty"));
@ -288,6 +312,7 @@ public class ConfigTest extends TestCase {
assertEquals("[my]\n\tempty\n", c.toText()); assertEquals("[my]\n\tempty\n", c.toText());
} }
@Test
public void testEmptyString() throws ConfigInvalidException { public void testEmptyString() throws ConfigInvalidException {
Config c = parse("[my]\n\tempty =\n"); Config c = parse("[my]\n\tempty =\n");
assertNull(c.getString("my", null, "empty")); assertNull(c.getString("my", null, "empty"));
@ -308,6 +333,7 @@ public class ConfigTest extends TestCase {
assertEquals("[my]\n\tempty =\n", c.toText()); assertEquals("[my]\n\tempty =\n", c.toText());
} }
@Test
public void testUnsetBranchSection() throws ConfigInvalidException { public void testUnsetBranchSection() throws ConfigInvalidException {
Config c = parse("" // Config c = parse("" //
+ "[branch \"keep\"]\n" + "[branch \"keep\"]\n"
@ -329,6 +355,7 @@ public class ConfigTest extends TestCase {
+ " packedGitLimit = 14\n", c.toText()); + " packedGitLimit = 14\n", c.toText());
} }
@Test
public void testUnsetSingleSection() throws ConfigInvalidException { public void testUnsetSingleSection() throws ConfigInvalidException {
Config c = parse("" // Config c = parse("" //
+ "[branch \"keep\"]\n" + "[branch \"keep\"]\n"
@ -349,6 +376,7 @@ public class ConfigTest extends TestCase {
+ " packedGitLimit = 14\n", c.toText()); + " packedGitLimit = 14\n", c.toText());
} }
@Test
public void test008_readSectionNames() throws ConfigInvalidException { public void test008_readSectionNames() throws ConfigInvalidException {
final Config c = parse("[a]\n [B]\n"); final Config c = parse("[a]\n [B]\n");
Set<String> sections = c.getSections(); Set<String> sections = c.getSections();
@ -356,6 +384,7 @@ public class ConfigTest extends TestCase {
assertTrue("Sections should contain \"b\"", sections.contains("b")); assertTrue("Sections should contain \"b\"", sections.contains("b"));
} }
@Test
public void test009_readNamesInSection() throws ConfigInvalidException { public void test009_readNamesInSection() throws ConfigInvalidException {
String configString = "[core]\n" + "repositoryformatversion = 0\n" String configString = "[core]\n" + "repositoryformatversion = 0\n"
+ "filemode = false\n" + "logallrefupdates = true\n"; + "filemode = false\n" + "logallrefupdates = true\n";
@ -366,6 +395,7 @@ public class ConfigTest extends TestCase {
.contains("filemode")); .contains("filemode"));
} }
@Test
public void test010_readNamesInSubSection() throws ConfigInvalidException { public void test010_readNamesInSubSection() throws ConfigInvalidException {
String configString = "[a \"sub1\"]\n"// String configString = "[a \"sub1\"]\n"//
+ "x = 0\n" // + "x = 0\n" //
@ -386,6 +416,7 @@ public class ConfigTest extends TestCase {
assertTrue("Subsection should contain \"b\"", names.contains("b")); assertTrue("Subsection should contain \"b\"", names.contains("b"));
} }
@Test
public void testQuotingForSubSectionNames() { public void testQuotingForSubSectionNames() {
String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n"; String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
String result; String result;

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConstantsEncodingTest.java

@ -43,12 +43,17 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase; import org.junit.Test;
public class ConstantsEncodingTest extends TestCase { public class ConstantsEncodingTest {
@Test
public void testEncodeASCII_SimpleASCII() public void testEncodeASCII_SimpleASCII()
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
final String src = "abc"; final String src = "abc";
@ -58,6 +63,7 @@ public class ConstantsEncodingTest extends TestCase {
assertEquals(src, new String(res, 0, res.length, "UTF-8")); assertEquals(src, new String(res, 0, res.length, "UTF-8"));
} }
@Test
public void testEncodeASCII_FailOnNonASCII() { public void testEncodeASCII_FailOnNonASCII() {
final String src = "Ūnĭcōde̽"; final String src = "Ūnĭcōde̽";
try { try {
@ -68,6 +74,7 @@ public class ConstantsEncodingTest extends TestCase {
} }
} }
@Test
public void testEncodeASCII_Number13() { public void testEncodeASCII_Number13() {
final long src = 13; final long src = 13;
final byte[] exp = { '1', '3' }; final byte[] exp = { '1', '3' };
@ -75,6 +82,7 @@ public class ConstantsEncodingTest extends TestCase {
assertTrue(Arrays.equals(exp, res)); assertTrue(Arrays.equals(exp, res));
} }
@Test
public void testEncode_SimpleASCII() throws UnsupportedEncodingException { public void testEncode_SimpleASCII() throws UnsupportedEncodingException {
final String src = "abc"; final String src = "abc";
final byte[] exp = { 'a', 'b', 'c' }; final byte[] exp = { 'a', 'b', 'c' };
@ -83,6 +91,7 @@ public class ConstantsEncodingTest extends TestCase {
assertEquals(src, new String(res, 0, res.length, "UTF-8")); assertEquals(src, new String(res, 0, res.length, "UTF-8"));
} }
@Test
public void testEncode_Unicode() throws UnsupportedEncodingException { public void testEncode_Unicode() throws UnsupportedEncodingException {
final String src = "Ūnĭcōde̽"; final String src = "Ūnĭcōde̽";
final byte[] exp = { (byte) 0xC5, (byte) 0xAA, 0x6E, (byte) 0xC4, final byte[] exp = { (byte) 0xC5, (byte) 0xAA, 0x6E, (byte) 0xC4,

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

@ -37,6 +37,9 @@
*/ */
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -53,6 +56,7 @@ import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class DirCacheCheckoutTest extends ReadTreeTest { public class DirCacheCheckoutTest extends ReadTreeTest {
private DirCacheCheckout dco; private DirCacheCheckout dco;
@ -94,6 +98,7 @@ public class DirCacheCheckoutTest extends ReadTreeTest {
return dco.getConflicts(); return dco.getConflicts();
} }
@Test
public void testResetHard() throws IOException, NoFilepatternException, public void testResetHard() throws IOException, NoFilepatternException,
GitAPIException { GitAPIException {
Git git = new Git(db); Git git = new Git(db);

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

@ -45,6 +45,9 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -53,8 +56,10 @@ import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.junit.Test;
public class IndexDiffTest extends RepositoryTestCase { public class IndexDiffTest extends RepositoryTestCase {
@Test
public void testAdded() throws IOException { public void testAdded() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
writeTrashFile("file1", "file1"); writeTrashFile("file1", "file1");
@ -76,6 +81,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertEquals(0, diff.getRemoved().size()); assertEquals(0, diff.getRemoved().size());
} }
@Test
public void testRemoved() throws IOException { public void testRemoved() throws IOException {
writeTrashFile("file2", "file2"); writeTrashFile("file2", "file2");
writeTrashFile("dir/file3", "dir/file3"); writeTrashFile("dir/file3", "dir/file3");
@ -101,6 +107,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertEquals(0, diff.getAdded().size()); assertEquals(0, diff.getAdded().size());
} }
@Test
public void testModified() throws IOException { public void testModified() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
@ -132,6 +139,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertEquals(0, diff.getMissing().size()); assertEquals(0, diff.getMissing().size());
} }
@Test
public void testUnchangedSimple() throws IOException { public void testUnchangedSimple() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
@ -166,6 +174,7 @@ public class IndexDiffTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testUnchangedComplex() throws IOException { public void testUnchangedComplex() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
@ -221,6 +230,7 @@ public class IndexDiffTest extends RepositoryTestCase {
* *
* @throws Exception * @throws Exception
*/ */
@Test
public void testRemovedUntracked() throws Exception{ public void testRemovedUntracked() throws Exception{
Git git = new Git(db); Git git = new Git(db);
String path = "file"; String path = "file";
@ -235,6 +245,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertTrue(diff.getUntracked().contains(path)); assertTrue(diff.getUntracked().contains(path));
} }
@Test
public void testAssumeUnchanged() throws Exception { public void testAssumeUnchanged() throws Exception {
Git git = new Git(db); Git git = new Git(db);
String path = "file"; String path = "file";

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexTreeWalkerTest.java

@ -44,11 +44,16 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.jgit.lib.GitIndex.Entry; import org.eclipse.jgit.lib.GitIndex.Entry;
import org.junit.Test;
public class IndexTreeWalkerTest extends RepositoryTestCase { public class IndexTreeWalkerTest extends RepositoryTestCase {
private ArrayList<String> treeOnlyEntriesVisited = new ArrayList<String>(); private ArrayList<String> treeOnlyEntriesVisited = new ArrayList<String>();
@ -74,6 +79,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase {
* because I already * because I already
*/ */
@Test
public void testTreeOnlyOneLevel() throws IOException { public void testTreeOnlyOneLevel() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
Tree tree = new Tree(db); Tree tree = new Tree(db);
@ -86,6 +92,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase {
assertTrue(treeOnlyEntriesVisited.get(1).equals("foo")); assertTrue(treeOnlyEntriesVisited.get(1).equals("foo"));
} }
@Test
public void testIndexOnlyOneLevel() throws IOException { public void testIndexOnlyOneLevel() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
Tree tree = new Tree(db); Tree tree = new Tree(db);
@ -98,6 +105,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase {
assertTrue(indexOnlyEntriesVisited.get(1).equals("foo")); assertTrue(indexOnlyEntriesVisited.get(1).equals("foo"));
} }
@Test
public void testBoth() throws IOException { public void testBoth() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
Tree tree = new Tree(db); Tree tree = new Tree(db);
@ -114,6 +122,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase {
} }
@Test
public void testIndexOnlySubDirs() throws IOException { public void testIndexOnlySubDirs() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
Tree tree = new Tree(db); Tree tree = new Tree(db);
@ -126,6 +135,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase {
assertEquals("foo/bar/baz", indexOnlyEntriesVisited.get(1)); assertEquals("foo/bar/baz", indexOnlyEntriesVisited.get(1));
} }
@Test
public void testLeavingTree() throws IOException { public void testLeavingTree() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
index.add(trash, writeTrashFile("foo/bar", "foo/bar")); index.add(trash, writeTrashFile("foo/bar", "foo/bar"));

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java

@ -42,17 +42,23 @@
*/ */
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import org.junit.Test;
public class MergeHeadMsgTest extends RepositoryTestCase { public class MergeHeadMsgTest extends RepositoryTestCase {
private static final String mergeMsg = "merge a and b"; private static final String mergeMsg = "merge a and b";
private static final String sampleId = "1c6db447abdbb291b25f07be38ea0b1bf94947c5"; private static final String sampleId = "1c6db447abdbb291b25f07be38ea0b1bf94947c5";
@Test
public void testReadWriteMergeHeads() throws IOException { public void testReadWriteMergeHeads() throws IOException {
assertEquals(db.readMergeHeads(), null); assertEquals(db.readMergeHeads(), null);
db.writeMergeHeads(Arrays.asList(ObjectId.zeroId(), db.writeMergeHeads(Arrays.asList(ObjectId.zeroId(),
@ -86,6 +92,7 @@ public class MergeHeadMsgTest extends RepositoryTestCase {
assertEquals(db.readMergeHeads().get(0), ObjectId.fromString(sampleId)); assertEquals(db.readMergeHeads().get(0), ObjectId.fromString(sampleId));
} }
@Test
public void testReadWriteMergeMsg() throws IOException { public void testReadWriteMergeMsg() throws IOException {
assertEquals(db.readMergeCommitMsg(), null); assertEquals(db.readMergeCommitMsg(), null);
assertFalse(new File(db.getDirectory(), "MERGE_MSG").exists()); assertFalse(new File(db.getDirectory(), "MERGE_MSG").exists());

98
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java

@ -44,21 +44,25 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import java.text.MessageFormat; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import junit.framework.TestCase; import java.text.MessageFormat;
import org.eclipse.jgit.JGitText; import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.junit.Before;
import org.junit.Test;
public class ObjectCheckerTest extends TestCase { public class ObjectCheckerTest {
private ObjectChecker checker; private ObjectChecker checker;
protected void setUp() throws Exception { @Before
super.setUp(); public void setUp() throws Exception {
checker = new ObjectChecker(); checker = new ObjectChecker();
} }
@Test
public void testInvalidType() { public void testInvalidType() {
try { try {
checker.check(Constants.OBJ_BAD, new byte[0]); checker.check(Constants.OBJ_BAD, new byte[0]);
@ -69,6 +73,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testCheckBlob() throws CorruptObjectException { public void testCheckBlob() throws CorruptObjectException {
// Any blob should pass... // Any blob should pass...
checker.checkBlob(new byte[0]); checker.checkBlob(new byte[0]);
@ -78,6 +83,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_BLOB, new byte[1]); checker.check(Constants.OBJ_BLOB, new byte[1]);
} }
@Test
public void testValidCommitNoParent() throws CorruptObjectException { public void testValidCommitNoParent() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -93,6 +99,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_COMMIT, data); checker.check(Constants.OBJ_COMMIT, data);
} }
@Test
public void testValidCommitBlankAuthor() throws CorruptObjectException { public void testValidCommitBlankAuthor() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -108,6 +115,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_COMMIT, data); checker.check(Constants.OBJ_COMMIT, data);
} }
@Test
public void testValidCommit1Parent() throws CorruptObjectException { public void testValidCommit1Parent() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -127,6 +135,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_COMMIT, data); checker.check(Constants.OBJ_COMMIT, data);
} }
@Test
public void testValidCommit2Parent() throws CorruptObjectException { public void testValidCommit2Parent() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -150,6 +159,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_COMMIT, data); checker.check(Constants.OBJ_COMMIT, data);
} }
@Test
public void testValidCommit128Parent() throws CorruptObjectException { public void testValidCommit128Parent() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -171,6 +181,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_COMMIT, data); checker.check(Constants.OBJ_COMMIT, data);
} }
@Test
public void testValidCommitNormalTime() throws CorruptObjectException { public void testValidCommitNormalTime() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
final String when = "1222757360 -0730"; final String when = "1222757360 -0730";
@ -187,6 +198,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_COMMIT, data); checker.check(Constants.OBJ_COMMIT, data);
} }
@Test
public void testInvalidCommitNoTree1() { public void testInvalidCommitNoTree1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -203,6 +215,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitNoTree2() { public void testInvalidCommitNoTree2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -219,6 +232,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitNoTree3() { public void testInvalidCommitNoTree3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -235,6 +249,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitNoTree4() { public void testInvalidCommitNoTree4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -251,6 +266,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidTree1() { public void testInvalidCommitInvalidTree1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -267,6 +283,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidTree2() { public void testInvalidCommitInvalidTree2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -283,6 +300,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidTree3() { public void testInvalidCommitInvalidTree3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -299,6 +317,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidTree4() { public void testInvalidCommitInvalidTree4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -315,6 +334,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidParent1() { public void testInvalidCommitInvalidParent1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -334,6 +354,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidParent2() { public void testInvalidCommitInvalidParent2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -354,6 +375,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidParent3() { public void testInvalidCommitInvalidParent3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -374,6 +396,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidParent4() { public void testInvalidCommitInvalidParent4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -394,6 +417,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidParent5() { public void testInvalidCommitInvalidParent5() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -416,6 +440,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitNoAuthor() { public void testInvalidCommitNoAuthor() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -436,6 +461,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitNoCommitter1() { public void testInvalidCommitNoCommitter1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -456,6 +482,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitNoCommitter2() { public void testInvalidCommitNoCommitter2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -477,6 +504,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor1() { public void testInvalidCommitInvalidAuthor1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -497,6 +525,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor2() { public void testInvalidCommitInvalidAuthor2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -517,6 +546,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor3() { public void testInvalidCommitInvalidAuthor3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -537,6 +567,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor4() { public void testInvalidCommitInvalidAuthor4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -557,6 +588,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor5() { public void testInvalidCommitInvalidAuthor5() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -577,6 +609,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor6() { public void testInvalidCommitInvalidAuthor6() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -597,6 +630,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidAuthor7() { public void testInvalidCommitInvalidAuthor7() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -617,6 +651,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidCommitInvalidCommitter() { public void testInvalidCommitInvalidCommitter() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -638,6 +673,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testValidTag() throws CorruptObjectException { public void testValidTag() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -654,6 +690,7 @@ public class ObjectCheckerTest extends TestCase {
checker.check(Constants.OBJ_TAG, data); checker.check(Constants.OBJ_TAG, data);
} }
@Test
public void testInvalidTagNoObject1() { public void testInvalidTagNoObject1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -666,6 +703,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoObject2() { public void testInvalidTagNoObject2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -682,6 +720,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoObject3() { public void testInvalidTagNoObject3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -698,6 +737,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoObject4() { public void testInvalidTagNoObject4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -714,6 +754,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoObject5() { public void testInvalidTagNoObject5() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -730,6 +771,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoObject6() { public void testInvalidTagNoObject6() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -745,6 +787,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoType1() { public void testInvalidTagNoType1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -761,6 +804,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoType2() { public void testInvalidTagNoType2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -779,6 +823,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoType3() { public void testInvalidTagNoType3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -797,6 +842,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoType4() { public void testInvalidTagNoType4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -815,6 +861,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoTagHeader1() { public void testInvalidTagNoTagHeader1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -833,6 +880,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoTagHeader2() { public void testInvalidTagNoTagHeader2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -852,6 +900,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagNoTagHeader3() { public void testInvalidTagNoTagHeader3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -871,6 +920,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testValidTagHasNoTaggerHeader() throws CorruptObjectException { public void testValidTagHasNoTaggerHeader() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -884,6 +934,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTag(Constants.encodeASCII(b.toString())); checker.checkTag(Constants.encodeASCII(b.toString()));
} }
@Test
public void testInvalidTagInvalidTaggerHeader1() { public void testInvalidTagInvalidTaggerHeader1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -904,6 +955,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTagInvalidTaggerHeader3() { public void testInvalidTagInvalidTaggerHeader3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
@ -924,11 +976,13 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testValidEmptyTree() throws CorruptObjectException { public void testValidEmptyTree() throws CorruptObjectException {
checker.checkTree(new byte[0]); checker.checkTree(new byte[0]);
checker.check(Constants.OBJ_TREE, new byte[0]); checker.check(Constants.OBJ_TREE, new byte[0]);
} }
@Test
public void testValidTree1() throws CorruptObjectException { public void testValidTree1() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 regular-file"); entry(b, "100644 regular-file");
@ -936,6 +990,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTree2() throws CorruptObjectException { public void testValidTree2() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100755 executable"); entry(b, "100755 executable");
@ -943,6 +998,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTree3() throws CorruptObjectException { public void testValidTree3() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "40000 tree"); entry(b, "40000 tree");
@ -950,6 +1006,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTree4() throws CorruptObjectException { public void testValidTree4() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "120000 symlink"); entry(b, "120000 symlink");
@ -957,6 +1014,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTree5() throws CorruptObjectException { public void testValidTree5() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "160000 git link"); entry(b, "160000 git link");
@ -964,6 +1022,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTree6() throws CorruptObjectException { public void testValidTree6() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 .a"); entry(b, "100644 .a");
@ -971,6 +1030,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting1() throws CorruptObjectException { public void testValidTreeSorting1() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 fooaaa"); entry(b, "100644 fooaaa");
@ -979,6 +1039,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting2() throws CorruptObjectException { public void testValidTreeSorting2() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100755 fooaaa"); entry(b, "100755 fooaaa");
@ -987,6 +1048,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting3() throws CorruptObjectException { public void testValidTreeSorting3() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "40000 a"); entry(b, "40000 a");
@ -995,6 +1057,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting4() throws CorruptObjectException { public void testValidTreeSorting4() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a"); entry(b, "100644 a");
@ -1003,6 +1066,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting5() throws CorruptObjectException { public void testValidTreeSorting5() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a.c"); entry(b, "100644 a.c");
@ -1012,6 +1076,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting6() throws CorruptObjectException { public void testValidTreeSorting6() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "40000 a"); entry(b, "40000 a");
@ -1020,6 +1085,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting7() throws CorruptObjectException { public void testValidTreeSorting7() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "40000 an orang"); entry(b, "40000 an orang");
@ -1028,6 +1094,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testValidTreeSorting8() throws CorruptObjectException { public void testValidTreeSorting8() throws CorruptObjectException {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a"); entry(b, "100644 a");
@ -1037,6 +1104,7 @@ public class ObjectCheckerTest extends TestCase {
checker.checkTree(data); checker.checkTree(data);
} }
@Test
public void testInvalidTreeModeStartsWithZero1() { public void testInvalidTreeModeStartsWithZero1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "0 a"); entry(b, "0 a");
@ -1049,6 +1117,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeStartsWithZero2() { public void testInvalidTreeModeStartsWithZero2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "0100644 a"); entry(b, "0100644 a");
@ -1061,6 +1130,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeStartsWithZero3() { public void testInvalidTreeModeStartsWithZero3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "040000 a"); entry(b, "040000 a");
@ -1073,6 +1143,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeNotOctal1() { public void testInvalidTreeModeNotOctal1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "8 a"); entry(b, "8 a");
@ -1085,6 +1156,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeNotOctal2() { public void testInvalidTreeModeNotOctal2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "Z a"); entry(b, "Z a");
@ -1097,6 +1169,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeNotSupportedMode1() { public void testInvalidTreeModeNotSupportedMode1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "1 a"); entry(b, "1 a");
@ -1109,6 +1182,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeNotSupportedMode2() { public void testInvalidTreeModeNotSupportedMode2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "170000 a"); entry(b, "170000 a");
@ -1121,6 +1195,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeModeMissingName() { public void testInvalidTreeModeMissingName() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append("100644"); b.append("100644");
@ -1133,6 +1208,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeNameContainsSlash() { public void testInvalidTreeNameContainsSlash() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a/b"); entry(b, "100644 a/b");
@ -1145,6 +1221,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeNameIsEmpty() { public void testInvalidTreeNameIsEmpty() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 "); entry(b, "100644 ");
@ -1157,6 +1234,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeNameIsDot() { public void testInvalidTreeNameIsDot() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 ."); entry(b, "100644 .");
@ -1169,6 +1247,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeNameIsDotDot() { public void testInvalidTreeNameIsDotDot() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 .."); entry(b, "100644 ..");
@ -1181,6 +1260,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeTruncatedInName() { public void testInvalidTreeTruncatedInName() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append("100644 b"); b.append("100644 b");
@ -1193,6 +1273,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeTruncatedInObjectId() { public void testInvalidTreeTruncatedInObjectId() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append("100644 b\0\1\2"); b.append("100644 b\0\1\2");
@ -1205,6 +1286,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeBadSorting1() { public void testInvalidTreeBadSorting1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 foobar"); entry(b, "100644 foobar");
@ -1218,6 +1300,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeBadSorting2() { public void testInvalidTreeBadSorting2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "40000 a"); entry(b, "40000 a");
@ -1231,6 +1314,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeBadSorting3() { public void testInvalidTreeBadSorting3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a0c"); entry(b, "100644 a0c");
@ -1244,6 +1328,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeDuplicateNames1() { public void testInvalidTreeDuplicateNames1() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a"); entry(b, "100644 a");
@ -1257,6 +1342,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeDuplicateNames2() { public void testInvalidTreeDuplicateNames2() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a"); entry(b, "100644 a");
@ -1270,6 +1356,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeDuplicateNames3() { public void testInvalidTreeDuplicateNames3() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a"); entry(b, "100644 a");
@ -1283,6 +1370,7 @@ public class ObjectCheckerTest extends TestCase {
} }
} }
@Test
public void testInvalidTreeDuplicateNames4() { public void testInvalidTreeDuplicateNames4() {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
entry(b, "100644 a"); entry(b, "100644 a");

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdRefTest.java

@ -43,9 +43,15 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class ObjectIdRefTest extends TestCase { import org.junit.Test;
public class ObjectIdRefTest {
private static final ObjectId ID_A = ObjectId private static final ObjectId ID_A = ObjectId
.fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed"); .fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed");
@ -54,6 +60,7 @@ public class ObjectIdRefTest extends TestCase {
private static final String name = "refs/heads/a.test.ref"; private static final String name = "refs/heads/a.test.ref";
@Test
public void testConstructor_PeeledStatusNotKnown() { public void testConstructor_PeeledStatusNotKnown() {
ObjectIdRef r; ObjectIdRef r;
@ -84,6 +91,7 @@ public class ObjectIdRefTest extends TestCase {
assertFalse("not symbolic", r.isSymbolic()); assertFalse("not symbolic", r.isSymbolic());
} }
@Test
public void testConstructor_Peeled() { public void testConstructor_Peeled() {
ObjectIdRef r; ObjectIdRef r;
@ -106,6 +114,7 @@ public class ObjectIdRefTest extends TestCase {
assertSame(ID_B, r.getPeeledObjectId()); assertSame(ID_B, r.getPeeledObjectId());
} }
@Test
public void testToString() { public void testToString() {
ObjectIdRef r; ObjectIdRef r;

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java

@ -45,21 +45,28 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ObjectIdTest extends TestCase { import org.junit.Test;
public class ObjectIdTest {
@Test
public void test001_toString() { public void test001_toString() {
final String x = "def4c620bc3713bb1bb26b808ec9312548e73946"; final String x = "def4c620bc3713bb1bb26b808ec9312548e73946";
final ObjectId oid = ObjectId.fromString(x); final ObjectId oid = ObjectId.fromString(x);
assertEquals(x, oid.name()); assertEquals(x, oid.name());
} }
@Test
public void test002_toString() { public void test002_toString() {
final String x = "ff00eedd003713bb1bb26b808ec9312548e73946"; final String x = "ff00eedd003713bb1bb26b808ec9312548e73946";
final ObjectId oid = ObjectId.fromString(x); final ObjectId oid = ObjectId.fromString(x);
assertEquals(x, oid.name()); assertEquals(x, oid.name());
} }
@Test
public void test003_equals() { public void test003_equals() {
final String x = "def4c620bc3713bb1bb26b808ec9312548e73946"; final String x = "def4c620bc3713bb1bb26b808ec9312548e73946";
final ObjectId a = ObjectId.fromString(x); final ObjectId a = ObjectId.fromString(x);
@ -68,47 +75,56 @@ public class ObjectIdTest extends TestCase {
assertTrue("a and b are same", a.equals(b)); assertTrue("a and b are same", a.equals(b));
} }
@Test
public void test004_isId() { public void test004_isId() {
assertTrue("valid id", ObjectId assertTrue("valid id", ObjectId
.isId("def4c620bc3713bb1bb26b808ec9312548e73946")); .isId("def4c620bc3713bb1bb26b808ec9312548e73946"));
} }
@Test
public void test005_notIsId() { public void test005_notIsId() {
assertFalse("bob is not an id", ObjectId.isId("bob")); assertFalse("bob is not an id", ObjectId.isId("bob"));
} }
@Test
public void test006_notIsId() { public void test006_notIsId() {
assertFalse("39 digits is not an id", ObjectId assertFalse("39 digits is not an id", ObjectId
.isId("def4c620bc3713bb1bb26b808ec9312548e7394")); .isId("def4c620bc3713bb1bb26b808ec9312548e7394"));
} }
@Test
public void test007_isId() { public void test007_isId() {
assertTrue("uppercase is accepted", ObjectId assertTrue("uppercase is accepted", ObjectId
.isId("Def4c620bc3713bb1bb26b808ec9312548e73946")); .isId("Def4c620bc3713bb1bb26b808ec9312548e73946"));
} }
@Test
public void test008_notIsId() { public void test008_notIsId() {
assertFalse("g is not a valid hex digit", ObjectId assertFalse("g is not a valid hex digit", ObjectId
.isId("gef4c620bc3713bb1bb26b808ec9312548e73946")); .isId("gef4c620bc3713bb1bb26b808ec9312548e73946"));
} }
@Test
public void test009_toString() { public void test009_toString() {
final String x = "ff00eedd003713bb1bb26b808ec9312548e73946"; final String x = "ff00eedd003713bb1bb26b808ec9312548e73946";
final ObjectId oid = ObjectId.fromString(x); final ObjectId oid = ObjectId.fromString(x);
assertEquals(x, ObjectId.toString(oid)); assertEquals(x, ObjectId.toString(oid));
} }
@Test
public void test010_toString() { public void test010_toString() {
final String x = "0000000000000000000000000000000000000000"; final String x = "0000000000000000000000000000000000000000";
assertEquals(x, ObjectId.toString(null)); assertEquals(x, ObjectId.toString(null));
} }
@Test
public void test011_toString() { public void test011_toString() {
final String x = "0123456789ABCDEFabcdef1234567890abcdefAB"; final String x = "0123456789ABCDEFabcdef1234567890abcdefAB";
final ObjectId oid = ObjectId.fromString(x); final ObjectId oid = ObjectId.fromString(x);
assertEquals(x.toLowerCase(), oid.name()); assertEquals(x.toLowerCase(), oid.name());
} }
@Test
public void testGetByte() { public void testGetByte() {
byte[] raw = new byte[20]; byte[] raw = new byte[20];
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
@ -123,6 +139,7 @@ public class ObjectIdTest extends TestCase {
assertEquals("index " + i, raw[i] & 0xff, id.getByte(i)); assertEquals("index " + i, raw[i] & 0xff, id.getByte(i));
} }
@Test
public void testSetByte() { public void testSetByte() {
byte[] exp = new byte[20]; byte[] exp = new byte[20];
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)

30
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectLoaderTest.java

@ -44,29 +44,38 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase;
import org.eclipse.jgit.errors.LargeObjectException; import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.junit.TestRng;
import org.junit.Test;
public class ObjectLoaderTest extends TestCase { public class ObjectLoaderTest {
private TestRng rng; private TestRng rng;
protected void setUp() throws Exception { private TestRng getRng() {
super.setUp(); if (rng == null)
rng = new TestRng(getName()); rng = new TestRng(JGitTestUtil.getName());
return rng;
} }
@Test
public void testSmallObjectLoader() throws MissingObjectException, public void testSmallObjectLoader() throws MissingObjectException,
IOException { IOException {
final byte[] act = rng.nextBytes(512); final byte[] act = getRng().nextBytes(512);
final ObjectLoader ldr = new ObjectLoader.SmallObject(OBJ_BLOB, act); final ObjectLoader ldr = new ObjectLoader.SmallObject(OBJ_BLOB, act);
assertEquals(OBJ_BLOB, ldr.getType()); assertEquals(OBJ_BLOB, ldr.getType());
@ -106,9 +115,10 @@ public class ObjectLoaderTest extends TestCase {
assertTrue("same content", Arrays.equals(act, tmp.toByteArray())); assertTrue("same content", Arrays.equals(act, tmp.toByteArray()));
} }
@Test
public void testLargeObjectLoader() throws MissingObjectException, public void testLargeObjectLoader() throws MissingObjectException,
IOException { IOException {
final byte[] act = rng.nextBytes(512); final byte[] act = getRng().nextBytes(512);
final ObjectLoader ldr = new ObjectLoader() { final ObjectLoader ldr = new ObjectLoader() {
@Override @Override
public byte[] getCachedBytes() throws LargeObjectException { public byte[] getCachedBytes() throws LargeObjectException {
@ -179,9 +189,10 @@ public class ObjectLoaderTest extends TestCase {
assertTrue("same content", Arrays.equals(act, tmp.toByteArray())); assertTrue("same content", Arrays.equals(act, tmp.toByteArray()));
} }
@Test
public void testLimitedGetCachedBytes() throws LargeObjectException, public void testLimitedGetCachedBytes() throws LargeObjectException,
MissingObjectException, IOException { MissingObjectException, IOException {
byte[] act = rng.nextBytes(512); byte[] act = getRng().nextBytes(512);
ObjectLoader ldr = new ObjectLoader.SmallObject(OBJ_BLOB, act) { ObjectLoader ldr = new ObjectLoader.SmallObject(OBJ_BLOB, act) {
@Override @Override
public boolean isLarge() { public boolean isLarge() {
@ -206,6 +217,7 @@ public class ObjectLoaderTest extends TestCase {
assertTrue("same content", Arrays.equals(act, copy)); assertTrue("same content", Arrays.equals(act, copy));
} }
@Test
public void testLimitedGetCachedBytesExceedsJavaLimits() public void testLimitedGetCachedBytesExceedsJavaLimits()
throws LargeObjectException, MissingObjectException, IOException { throws LargeObjectException, MissingObjectException, IOException {
ObjectLoader ldr = new ObjectLoader() { ObjectLoader ldr = new ObjectLoader() {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java

@ -42,6 +42,9 @@
*/ */
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;

37
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java

@ -45,6 +45,12 @@
*/ */
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -58,6 +64,7 @@ import org.eclipse.jgit.errors.CheckoutConflictException;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.junit.Test;
public abstract class ReadTreeTest extends RepositoryTestCase { public abstract class ReadTreeTest extends RepositoryTestCase {
protected Tree theHead; protected Tree theHead;
@ -66,6 +73,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
// Each of these rules are from the read-tree manpage // Each of these rules are from the read-tree manpage
// go there to see what they mean. // go there to see what they mean.
// Rule 0 is left out for obvious reasons :) // Rule 0 is left out for obvious reasons :)
@Test
public void testRules1thru3_NoIndexEntry() throws IOException { public void testRules1thru3_NoIndexEntry() throws IOException {
Tree head = new Tree(db); Tree head = new Tree(db);
head = buildTree(mk("foo")); head = buildTree(mk("foo"));
@ -154,6 +162,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
// for these rules, they all have clean yes/no options // for these rules, they all have clean yes/no options
// but it doesn't matter if the entry is clean or not // but it doesn't matter if the entry is clean or not
// so we can just ignore the state in the filesystem entirely // so we can just ignore the state in the filesystem entirely
@Test
public void testRules4thru13_IndexEntryNotInHead() throws IOException { public void testRules4thru13_IndexEntryNotInHead() throws IOException {
// rules 4 and 5 // rules 4 and 5
HashMap<String, String> idxMap; HashMap<String, String> idxMap;
@ -251,6 +260,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertTrue(getConflicts().isEmpty()); assertTrue(getConflicts().isEmpty());
} }
@Test
public void testDirectoryFileSimple() throws IOException { public void testDirectoryFileSimple() throws IOException {
Tree treeDF = buildTree(mkmap("DF", "DF")); Tree treeDF = buildTree(mkmap("DF", "DF"));
Tree treeDFDF = buildTree(mkmap("DF/DF", "DF/DF")); Tree treeDFDF = buildTree(mkmap("DF/DF", "DF/DF"));
@ -300,6 +310,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
*19 D 0 F Update *19 D 0 F Update
*/ */
@Test
public void testDirectoryFileConflicts_1() throws Exception { public void testDirectoryFileConflicts_1() throws Exception {
// 1 // 1
doit(mk("DF/DF"), mk("DF"), mk("DF/DF")); doit(mk("DF/DF"), mk("DF"), mk("DF/DF"));
@ -308,6 +319,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertRemoved("DF/DF"); assertRemoved("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_2() throws Exception { public void testDirectoryFileConflicts_2() throws Exception {
// 2 // 2
setupCase(mk("DF/DF"), mk("DF"), mk("DF/DF")); setupCase(mk("DF/DF"), mk("DF"), mk("DF/DF"));
@ -317,6 +329,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
} }
@Test
public void testDirectoryFileConflicts_3() throws Exception { public void testDirectoryFileConflicts_3() throws Exception {
// 3 - the first to break! // 3 - the first to break!
doit(mk("DF/DF"), mk("DF/DF"), mk("DF")); doit(mk("DF/DF"), mk("DF/DF"), mk("DF"));
@ -324,6 +337,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertRemoved("DF"); assertRemoved("DF");
} }
@Test
public void testDirectoryFileConflicts_4() throws Exception { public void testDirectoryFileConflicts_4() throws Exception {
// 4 (basically same as 3, just with H and M different) // 4 (basically same as 3, just with H and M different)
doit(mk("DF/DF"), mkmap("DF/DF", "foo"), mk("DF")); doit(mk("DF/DF"), mkmap("DF/DF", "foo"), mk("DF"));
@ -332,6 +346,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
} }
@Test
public void testDirectoryFileConflicts_5() throws Exception { public void testDirectoryFileConflicts_5() throws Exception {
// 5 // 5
doit(mk("DF/DF"), mk("DF"), mk("DF")); doit(mk("DF/DF"), mk("DF"), mk("DF"));
@ -339,6 +354,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
} }
@Test
public void testDirectoryFileConflicts_6() throws Exception { public void testDirectoryFileConflicts_6() throws Exception {
// 6 // 6
setupCase(mk("DF/DF"), mk("DF"), mk("DF")); setupCase(mk("DF/DF"), mk("DF"), mk("DF"));
@ -347,6 +363,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertRemoved("DF/DF"); assertRemoved("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_7() throws Exception { public void testDirectoryFileConflicts_7() throws Exception {
// 7 // 7
doit(mk("DF"), mk("DF"), mk("DF/DF")); doit(mk("DF"), mk("DF"), mk("DF/DF"));
@ -375,6 +392,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
// This test would fail in DirCacheCheckoutTests. // This test would fail in DirCacheCheckoutTests.
} }
@Test
public void testDirectoryFileConflicts_8() throws Exception { public void testDirectoryFileConflicts_8() throws Exception {
// 8 // 8
setupCase(mk("DF"), mk("DF"), mk("DF/DF")); setupCase(mk("DF"), mk("DF"), mk("DF/DF"));
@ -384,6 +402,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertConflict("DF/DF"); assertConflict("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_9() throws Exception { public void testDirectoryFileConflicts_9() throws Exception {
// 9 // 9
doit(mk("DF"), mkmap("DF", "QP"), mk("DF/DF")); doit(mk("DF"), mkmap("DF", "QP"), mk("DF/DF"));
@ -391,6 +410,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF"); assertUpdated("DF");
} }
@Test
public void testDirectoryFileConflicts_10() throws Exception { public void testDirectoryFileConflicts_10() throws Exception {
// 10 // 10
cleanUpDF(); cleanUpDF();
@ -398,12 +418,14 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertNoConflicts(); assertNoConflicts();
} }
@Test
public void testDirectoryFileConflicts_11() throws Exception { public void testDirectoryFileConflicts_11() throws Exception {
// 11 // 11
doit(mk("DF"), mk("DF/DF"), mkmap("DF/DF", "asdf")); doit(mk("DF"), mk("DF/DF"), mkmap("DF/DF", "asdf"));
assertConflict("DF/DF"); assertConflict("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_12() throws Exception { public void testDirectoryFileConflicts_12() throws Exception {
// 12 // 12
cleanUpDF(); cleanUpDF();
@ -412,6 +434,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF/DF"); assertUpdated("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_13() throws Exception { public void testDirectoryFileConflicts_13() throws Exception {
// 13 // 13
cleanUpDF(); cleanUpDF();
@ -422,6 +445,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF/DF"); assertUpdated("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_14() throws Exception { public void testDirectoryFileConflicts_14() throws Exception {
// 14 // 14
cleanUpDF(); cleanUpDF();
@ -430,6 +454,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF/DF"); assertUpdated("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_15() throws Exception { public void testDirectoryFileConflicts_15() throws Exception {
// 15 // 15
doit(mkmap(), mk("DF/DF"), mk("DF")); doit(mkmap(), mk("DF/DF"), mk("DF"));
@ -441,6 +466,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF/DF"); assertUpdated("DF/DF");
} }
@Test
public void testDirectoryFileConflicts_15b() throws Exception { public void testDirectoryFileConflicts_15b() throws Exception {
// 15, take 2, just to check multi-leveled // 15, take 2, just to check multi-leveled
doit(mkmap(), mk("DF/DF/DF/DF"), mk("DF")); doit(mkmap(), mk("DF/DF/DF/DF"), mk("DF"));
@ -453,6 +479,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF/DF/DF/DF"); assertUpdated("DF/DF/DF/DF");
} }
@Test
public void testDirectoryFileConflicts_16() throws Exception { public void testDirectoryFileConflicts_16() throws Exception {
// 16 // 16
cleanUpDF(); cleanUpDF();
@ -461,6 +488,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF"); assertUpdated("DF");
} }
@Test
public void testDirectoryFileConflicts_17() throws Exception { public void testDirectoryFileConflicts_17() throws Exception {
// 17 // 17
cleanUpDF(); cleanUpDF();
@ -476,6 +504,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
// assertUpdated("DF"); // assertUpdated("DF");
} }
@Test
public void testDirectoryFileConflicts_18() throws Exception { public void testDirectoryFileConflicts_18() throws Exception {
// 18 // 18
cleanUpDF(); cleanUpDF();
@ -484,6 +513,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertUpdated("DF/DF/DF/DF"); assertUpdated("DF/DF/DF/DF");
} }
@Test
public void testDirectoryFileConflicts_19() throws Exception { public void testDirectoryFileConflicts_19() throws Exception {
// 19 // 19
cleanUpDF(); cleanUpDF();
@ -536,6 +566,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
return map; return map;
} }
@Test
public void testUntrackedConflicts() throws IOException { public void testUntrackedConflicts() throws IOException {
setupCase(null, mk("foo"), null); setupCase(null, mk("foo"), null);
writeTrashFile("foo", "foo"); writeTrashFile("foo", "foo");
@ -574,6 +605,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertNoConflicts(); assertNoConflicts();
} }
@Test
public void testCloseNameConflictsX0() throws IOException { public void testCloseNameConflictsX0() throws IOException {
setupCase(mkmap("a/a", "a/a-c"), mkmap("a/a","a/a", "b.b/b.b","b.b/b.bs"), mkmap("a/a", "a/a-c") ); setupCase(mkmap("a/a", "a/a-c"), mkmap("a/a","a/a", "b.b/b.b","b.b/b.bs"), mkmap("a/a", "a/a-c") );
checkout(); checkout();
@ -585,6 +617,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertNoConflicts(); assertNoConflicts();
} }
@Test
public void testCloseNameConflicts1() throws IOException { public void testCloseNameConflicts1() throws IOException {
setupCase(mkmap("a/a", "a/a-c"), mkmap("a/a","a/a", "a.a/a.a","a.a/a.a"), mkmap("a/a", "a/a-c") ); setupCase(mkmap("a/a", "a/a-c"), mkmap("a/a","a/a", "a.a/a.a","a.a/a.a"), mkmap("a/a", "a/a-c") );
checkout(); checkout();
@ -596,6 +629,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertNoConflicts(); assertNoConflicts();
} }
@Test
public void testCheckoutHierarchy() throws IOException { public void testCheckoutHierarchy() throws IOException {
setupCase( setupCase(
mkmap("a", "a", "b/c", "b/c", "d", "d", "e/f", "e/f", "e/g", mkmap("a", "a", "b/c", "b/c", "d", "d", "e/f", "e/f", "e/g",
@ -613,6 +647,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
} }
} }
@Test
public void testCheckoutOutChanges() throws IOException { public void testCheckoutOutChanges() throws IOException {
setupCase(mk("foo"), mk("foo/bar"), mk("foo")); setupCase(mk("foo"), mk("foo/bar"), mk("foo"));
checkout(); checkout();
@ -648,6 +683,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
} }
} }
@Test
public void testCheckoutUncachedChanges() throws IOException { public void testCheckoutUncachedChanges() throws IOException {
setupCase(mk("foo"), mk("foo"), mk("foo")); setupCase(mk("foo"), mk("foo"), mk("foo"));
writeTrashFile("foo", "otherData"); writeTrashFile("foo", "otherData");
@ -657,6 +693,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertTrue(new File(trash, "foo").isFile()); assertTrue(new File(trash, "foo").isFile());
} }
@Test
public void testDontOverwriteDirtyFile() throws IOException { public void testDontOverwriteDirtyFile() throws IOException {
setupCase(mk("foo"), mk("other"), mk("foo")); setupCase(mk("foo"), mk("other"), mk("foo"));
writeTrashFile("foo", "different"); writeTrashFile("foo", "different");

17
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java

@ -45,6 +45,14 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -52,6 +60,7 @@ import java.util.Map;
import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.RefUpdate.Result;
import org.junit.Test;
/** /**
* Misc tests for refs. A lot of things are tested elsewhere so not having a * Misc tests for refs. A lot of things are tested elsewhere so not having a
@ -71,6 +80,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
} }
} }
@Test
public void testReadAllIncludingSymrefs() throws Exception { public void testReadAllIncludingSymrefs() throws Exception {
ObjectId masterId = db.resolve("refs/heads/master"); ObjectId masterId = db.resolve("refs/heads/master");
RefUpdate updateRef = db.updateRef("refs/remotes/origin/master"); RefUpdate updateRef = db.updateRef("refs/remotes/origin/master");
@ -96,6 +106,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertNull(refmaster.getPeeledObjectId()); assertNull(refmaster.getPeeledObjectId());
} }
@Test
public void testReadSymRefToPacked() throws IOException { public void testReadSymRefToPacked() throws IOException {
writeSymref("HEAD", "refs/heads/b"); writeSymref("HEAD", "refs/heads/b");
Ref ref = db.getRef("HEAD"); Ref ref = db.getRef("HEAD");
@ -106,6 +117,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertEquals(Ref.Storage.PACKED, ref.getStorage()); assertEquals(Ref.Storage.PACKED, ref.getStorage());
} }
@Test
public void testReadSymRefToLoosePacked() throws IOException { public void testReadSymRefToLoosePacked() throws IOException {
ObjectId pid = db.resolve("refs/heads/master^"); ObjectId pid = db.resolve("refs/heads/master^");
RefUpdate updateRef = db.updateRef("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master");
@ -122,6 +134,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertEquals(Ref.Storage.LOOSE, ref.getStorage()); assertEquals(Ref.Storage.LOOSE, ref.getStorage());
} }
@Test
public void testReadLooseRef() throws IOException { public void testReadLooseRef() throws IOException {
RefUpdate updateRef = db.updateRef("ref/heads/new"); RefUpdate updateRef = db.updateRef("ref/heads/new");
updateRef.setNewObjectId(db.resolve("refs/heads/master")); updateRef.setNewObjectId(db.resolve("refs/heads/master"));
@ -137,6 +150,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
* @throws IOException * @throws IOException
* @throws InterruptedException * @throws InterruptedException
*/ */
@Test
public void testReadLoosePackedRef() throws IOException, public void testReadLoosePackedRef() throws IOException,
InterruptedException { InterruptedException {
Ref ref = db.getRef("refs/heads/master"); Ref ref = db.getRef("refs/heads/master");
@ -157,6 +171,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testReadSimplePackedRefSameRepo() throws IOException { public void testReadSimplePackedRefSameRepo() throws IOException {
Ref ref = db.getRef("refs/heads/master"); Ref ref = db.getRef("refs/heads/master");
ObjectId pid = db.resolve("refs/heads/master^"); ObjectId pid = db.resolve("refs/heads/master^");
@ -171,11 +186,13 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertEquals(Storage.LOOSE, ref.getStorage()); assertEquals(Storage.LOOSE, ref.getStorage());
} }
@Test
public void testResolvedNamesBranch() throws IOException { public void testResolvedNamesBranch() throws IOException {
Ref ref = db.getRef("a"); Ref ref = db.getRef("a");
assertEquals("refs/heads/a", ref.getName()); assertEquals("refs/heads/a", ref.getName());
} }
@Test
public void testResolvedSymRef() throws IOException { public void testResolvedSymRef() throws IOException {
Ref ref = db.getRef(Constants.HEAD); Ref ref = db.getRef(Constants.HEAD);
assertEquals(Constants.HEAD, ref.getName()); assertEquals(Constants.HEAD, ref.getName());

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

@ -45,11 +45,17 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.junit.Test;
public class ReflogConfigTest extends RepositoryTestCase { public class ReflogConfigTest extends RepositoryTestCase {
@Test
public void testlogAllRefUpdates() throws Exception { public void testlogAllRefUpdates() throws Exception {
long commitTime = 1154236443000L; long commitTime = 1154236443000L;
int tz = -4 * 60; int tz = -4 * 60;

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java

@ -43,13 +43,23 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.junit.Test;
public class RepositoryCacheTest extends RepositoryTestCase { public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testNonBareFileKey() { public void testNonBareFileKey() {
File gitdir = db.getDirectory(); File gitdir = db.getDirectory();
File parent = gitdir.getParentFile(); File parent = gitdir.getParentFile();
@ -63,6 +73,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
assertEquals(other, FileKey.lenient(other, db.getFS()).getFile()); assertEquals(other, FileKey.lenient(other, db.getFS()).getFile());
} }
@Test
public void testBareFileKey() throws IOException { public void testBareFileKey() throws IOException {
Repository bare = createBareRepository(); Repository bare = createBareRepository();
File gitdir = bare.getDirectory(); File gitdir = bare.getDirectory();
@ -77,6 +88,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
assertEquals(gitdir, FileKey.lenient(new File(parent, name), db.getFS()).getFile()); assertEquals(gitdir, FileKey.lenient(new File(parent, name), db.getFS()).getFile());
} }
@Test
public void testFileKeyOpenExisting() throws IOException { public void testFileKeyOpenExisting() throws IOException {
Repository r; Repository r;
@ -91,6 +103,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
r.close(); r.close();
} }
@Test
public void testFileKeyOpenNew() throws IOException { public void testFileKeyOpenNew() throws IOException {
final Repository n = createBareRepository(); final Repository n = createBareRepository();
final File gitdir = n.getDirectory(); final File gitdir = n.getDirectory();
@ -111,6 +124,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
assertFalse(gitdir.exists()); assertFalse(gitdir.exists());
} }
@Test
public void testCacheRegisterOpen() throws Exception { public void testCacheRegisterOpen() throws Exception {
final File dir = db.getDirectory(); final File dir = db.getDirectory();
RepositoryCache.register(db); RepositoryCache.register(db);
@ -121,6 +135,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
assertSame(db, RepositoryCache.open(FileKey.lenient(parent, db.getFS()))); assertSame(db, RepositoryCache.open(FileKey.lenient(parent, db.getFS())));
} }
@Test
public void testCacheOpen() throws Exception { public void testCacheOpen() throws Exception {
final FileKey loc = FileKey.exact(db.getDirectory(), db.getFS()); final FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
final Repository d2 = RepositoryCache.open(loc); final Repository d2 = RepositoryCache.open(loc);

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java

@ -46,38 +46,49 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.junit.Test;
public class RepositoryResolveTest extends SampleDataRepositoryTestCase { public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
@Test
public void testObjectId_existing() throws IOException { public void testObjectId_existing() throws IOException {
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0").name());
} }
@Test
public void testObjectId_nonexisting() throws IOException { public void testObjectId_nonexisting() throws IOException {
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c1",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c1").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c1",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c1").name());
} }
@Test
public void testObjectId_objectid_implicit_firstparent() throws IOException { public void testObjectId_objectid_implicit_firstparent() throws IOException {
assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^").name());
assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^").name()); assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^").name());
assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^^").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^^").name());
} }
@Test
public void testObjectId_objectid_self() throws IOException { public void testObjectId_objectid_self() throws IOException {
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0").name());
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0^0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0^0").name());
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0^0^0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0^0^0").name());
} }
@Test
public void testObjectId_objectid_explicit_firstparent() throws IOException { public void testObjectId_objectid_explicit_firstparent() throws IOException {
assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1").name());
assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1^1").name()); assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1^1").name());
assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1^1^1").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1^1^1").name());
} }
@Test
public void testObjectId_objectid_explicit_otherparents() throws IOException { public void testObjectId_objectid_explicit_otherparents() throws IOException {
assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1").name());
assertEquals("f73b95671f326616d66b2afb3bdfcdbbce110b44",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^2").name()); assertEquals("f73b95671f326616d66b2afb3bdfcdbbce110b44",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^2").name());
@ -85,12 +96,14 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals("d0114ab8ac326bab30e3a657a0397578c5a1af88",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^03").name()); assertEquals("d0114ab8ac326bab30e3a657a0397578c5a1af88",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^03").name());
} }
@Test
public void testRef_refname() throws IOException { public void testRef_refname() throws IOException {
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("master^0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("master^0").name());
assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("master^").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("master^").name());
assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("refs/heads/master^1").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("refs/heads/master^1").name());
} }
@Test
public void testDistance() throws IOException { public void testDistance() throws IOException {
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~0").name());
assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~1").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~1").name());
@ -99,15 +112,18 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~03").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~03").name());
} }
@Test
public void testTree() throws IOException { public void testTree() throws IOException {
assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{tree}").name()); assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{tree}").name());
assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^{tree}").name()); assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^{tree}").name());
} }
@Test
public void testHEAD() throws IOException { public void testHEAD() throws IOException {
assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("HEAD^{tree}").name()); assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("HEAD^{tree}").name());
} }
@Test
public void testDerefCommit() throws IOException { public void testDerefCommit() throws IOException {
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{}").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{}").name());
assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{commit}").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{commit}").name());
@ -115,6 +131,7 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{commit}^{tree}").name()); assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{commit}^{tree}").name());
} }
@Test
public void testDerefTag() throws IOException { public void testDerefTag() throws IOException {
assertEquals("17768080a2318cd89bba4c8b87834401e2095703",db.resolve("refs/tags/B").name()); assertEquals("17768080a2318cd89bba4c8b87834401e2095703",db.resolve("refs/tags/B").name());
assertEquals("d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864",db.resolve("refs/tags/B^{commit}").name()); assertEquals("d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864",db.resolve("refs/tags/B^{commit}").name());
@ -129,6 +146,7 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals("2c349335b7f797072cf729c4f3bb0914ecb6dec9",db.resolve("refs/tags/B10th~2").name()); assertEquals("2c349335b7f797072cf729c4f3bb0914ecb6dec9",db.resolve("refs/tags/B10th~2").name());
} }
@Test
public void testDerefBlob() throws IOException { public void testDerefBlob() throws IOException {
assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("spearce-gpg-pub^{}").name()); assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("spearce-gpg-pub^{}").name());
assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("spearce-gpg-pub^{blob}").name()); assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("spearce-gpg-pub^{blob}").name());
@ -136,12 +154,14 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("fd608fbe625a2b456d9f15c2b1dc41f252057dd7^{blob}").name()); assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("fd608fbe625a2b456d9f15c2b1dc41f252057dd7^{blob}").name());
} }
@Test
public void testDerefTree() throws IOException { public void testDerefTree() throws IOException {
assertEquals("032c063ce34486359e3ee3d4f9e5c225b9e1a4c2",db.resolve("refs/tags/B10th").name()); assertEquals("032c063ce34486359e3ee3d4f9e5c225b9e1a4c2",db.resolve("refs/tags/B10th").name());
assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("032c063ce34486359e3ee3d4f9e5c225b9e1a4c2^{tree}").name()); assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("032c063ce34486359e3ee3d4f9e5c225b9e1a4c2^{tree}").name());
assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("refs/tags/B10th^{tree}").name()); assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("refs/tags/B10th^{tree}").name());
} }
@Test
public void testParseGitDescribeOutput() throws IOException { public void testParseGitDescribeOutput() throws IOException {
ObjectId exp = db.resolve("b"); ObjectId exp = db.resolve("b");
assertEquals(exp, db.resolve("B-g7f82283")); // old style assertEquals(exp, db.resolve("B-g7f82283")); // old style
@ -161,6 +181,7 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals(db.resolve("b~2"), db.resolve("B-6-g7f82283~2")); assertEquals(db.resolve("b~2"), db.resolve("B-6-g7f82283~2"));
} }
@Test
public void testParseLookupPath() throws IOException { public void testParseLookupPath() throws IOException {
ObjectId b2_txt = id("10da5895682013006950e7da534b705252b03be6"); ObjectId b2_txt = id("10da5895682013006950e7da534b705252b03be6");
ObjectId b3_b2_txt = id("e6bfff5c1d0f0ecd501552b43a1e13d8008abc31"); ObjectId b3_b2_txt = id("e6bfff5c1d0f0ecd501552b43a1e13d8008abc31");

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

@ -46,6 +46,8 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -63,6 +65,7 @@ import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
/** /**
* Base class for most JGit unit tests. * Base class for most JGit unit tests.
@ -122,7 +125,8 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected File trash; protected File trash;
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
db = createWorkRepository(); db = createWorkRepository();
trash = db.getWorkTree(); trash = db.getWorkTree();

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java

@ -48,12 +48,12 @@ package org.eclipse.jgit.lib;
import java.io.File; import java.io.File;
import org.eclipse.jgit.util.JGitTestUtil; import org.eclipse.jgit.junit.JGitTestUtil;
/** Test case which includes C Git generated pack files for testing. */ /** Test case which includes C Git generated pack files for testing. */
public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase { public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase {
@Override @Override
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
final String[] packs = { final String[] packs = {

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SymbolicRefTest.java

@ -43,9 +43,15 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class SymbolicRefTest extends TestCase { import org.junit.Test;
public class SymbolicRefTest {
private static final ObjectId ID_A = ObjectId private static final ObjectId ID_A = ObjectId
.fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed"); .fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed");
@ -56,6 +62,7 @@ public class SymbolicRefTest extends TestCase {
private static final String name = "refs/remotes/origin/HEAD"; private static final String name = "refs/remotes/origin/HEAD";
@Test
public void testConstructor() { public void testConstructor() {
Ref t; Ref t;
SymbolicRef r; SymbolicRef r;
@ -83,6 +90,7 @@ public class SymbolicRefTest extends TestCase {
assertTrue("is symbolic", r.isSymbolic()); assertTrue("is symbolic", r.isSymbolic());
} }
@Test
public void testLeaf() { public void testLeaf() {
Ref a; Ref a;
SymbolicRef b, c, d; SymbolicRef b, c, d;
@ -114,6 +122,7 @@ public class SymbolicRefTest extends TestCase {
assertSame(ID_B, b.getPeeledObjectId()); assertSame(ID_B, b.getPeeledObjectId());
} }
@Test
public void testToString() { public void testToString() {
Ref a; Ref a;
SymbolicRef b, c, d; SymbolicRef b, c, d;

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java

@ -43,12 +43,16 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import junit.framework.TestCase; import org.junit.Test;
public class T0001_PersonIdentTest {
public class T0001_PersonIdent extends TestCase { @Test
public void test001_NewIdent() { public void test001_NewIdent() {
final PersonIdent p = new PersonIdent("A U Thor", "author@example.com", final PersonIdent p = new PersonIdent("A U Thor", "author@example.com",
new Date(1142878501000L), TimeZone.getTimeZone("EST")); new Date(1142878501000L), TimeZone.getTimeZone("EST"));
@ -59,6 +63,7 @@ public class T0001_PersonIdent extends TestCase {
p.toExternalString()); p.toExternalString());
} }
@Test
public void test002_NewIdent() { public void test002_NewIdent() {
final PersonIdent p = new PersonIdent("A U Thor", "author@example.com", final PersonIdent p = new PersonIdent("A U Thor", "author@example.com",
new Date(1142878501000L), TimeZone.getTimeZone("GMT+0230")); new Date(1142878501000L), TimeZone.getTimeZone("GMT+0230"));

28
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java

@ -44,12 +44,20 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class T0002_Tree extends SampleDataRepositoryTestCase { import org.junit.Test;
public class T0002_TreeTest extends SampleDataRepositoryTestCase {
private static final ObjectId SOME_FAKE_ID = ObjectId.fromString( private static final ObjectId SOME_FAKE_ID = ObjectId.fromString(
"0123456789abcdef0123456789abcdef01234567"); "0123456789abcdef0123456789abcdef01234567");
@ -71,13 +79,18 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
return Tree.compareNames(abytes, bbytes, lasta, lastb); return Tree.compareNames(abytes, bbytes, lasta, lastb);
} }
@Test
public void test000_sort_01() throws UnsupportedEncodingException { public void test000_sort_01() throws UnsupportedEncodingException {
assertEquals(0, compareNamesUsingSpecialCompare("a","a")); assertEquals(0, compareNamesUsingSpecialCompare("a","a"));
} }
@Test
public void test000_sort_02() throws UnsupportedEncodingException { public void test000_sort_02() throws UnsupportedEncodingException {
assertEquals(-1, compareNamesUsingSpecialCompare("a","b")); assertEquals(-1, compareNamesUsingSpecialCompare("a","b"));
assertEquals(1, compareNamesUsingSpecialCompare("b","a")); assertEquals(1, compareNamesUsingSpecialCompare("b","a"));
} }
@Test
public void test000_sort_03() throws UnsupportedEncodingException { public void test000_sort_03() throws UnsupportedEncodingException {
assertEquals(1, compareNamesUsingSpecialCompare("a:","a")); assertEquals(1, compareNamesUsingSpecialCompare("a:","a"));
assertEquals(1, compareNamesUsingSpecialCompare("a/","a")); assertEquals(1, compareNamesUsingSpecialCompare("a/","a"));
@ -86,16 +99,21 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
assertEquals(1, compareNamesUsingSpecialCompare("a:","a/")); assertEquals(1, compareNamesUsingSpecialCompare("a:","a/"));
assertEquals(-1, compareNamesUsingSpecialCompare("a/","a:")); assertEquals(-1, compareNamesUsingSpecialCompare("a/","a:"));
} }
@Test
public void test000_sort_04() throws UnsupportedEncodingException { public void test000_sort_04() throws UnsupportedEncodingException {
assertEquals(-1, compareNamesUsingSpecialCompare("a.a","a/a")); assertEquals(-1, compareNamesUsingSpecialCompare("a.a","a/a"));
assertEquals(1, compareNamesUsingSpecialCompare("a/a","a.a")); assertEquals(1, compareNamesUsingSpecialCompare("a/a","a.a"));
} }
@Test
public void test000_sort_05() throws UnsupportedEncodingException { public void test000_sort_05() throws UnsupportedEncodingException {
assertEquals(-1, compareNamesUsingSpecialCompare("a.","a/")); assertEquals(-1, compareNamesUsingSpecialCompare("a.","a/"));
assertEquals(1, compareNamesUsingSpecialCompare("a/","a.")); assertEquals(1, compareNamesUsingSpecialCompare("a/","a."));
} }
@Test
public void test001_createEmpty() throws IOException { public void test001_createEmpty() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
assertTrue("isLoaded", t.isLoaded()); assertTrue("isLoaded", t.isLoaded());
@ -114,6 +132,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
assertTrue("no foo child", t.findBlobMember("foo") == null); assertTrue("no foo child", t.findBlobMember("foo") == null);
} }
@Test
public void test002_addFile() throws IOException { public void test002_addFile() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
t.setId(SOME_FAKE_ID); t.setId(SOME_FAKE_ID);
@ -139,6 +158,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
assertTrue("iterator is empty", i != null && i.length == 1); assertTrue("iterator is empty", i != null && i.length == 1);
} }
@Test
public void test004_addTree() throws IOException { public void test004_addTree() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
t.setId(SOME_FAKE_ID); t.setId(SOME_FAKE_ID);
@ -169,6 +189,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
assertTrue("iterator is empty", i.length == 1); assertTrue("iterator is empty", i.length == 1);
} }
@Test
public void test005_addRecursiveFile() throws IOException { public void test005_addRecursiveFile() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
final FileTreeEntry f = t.addFile("a/b/c"); final FileTreeEntry f = t.addFile("a/b/c");
@ -180,6 +201,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
.getParent()); .getParent());
} }
@Test
public void test005_addRecursiveTree() throws IOException { public void test005_addRecursiveTree() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
final Tree f = t.addTree("a/b/c"); final Tree f = t.addTree("a/b/c");
@ -191,6 +213,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
.getParent()); .getParent());
} }
@Test
public void test006_addDeepTree() throws IOException { public void test006_addDeepTree() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
@ -240,6 +263,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
assertTrue("t no id", t.getId() == null); assertTrue("t no id", t.getId() == null);
} }
@Test
public void test007_manyFileLookup() throws IOException { public void test007_manyFileLookup() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
final List<FileTreeEntry> files = new ArrayList<FileTreeEntry>(26 * 26); final List<FileTreeEntry> files = new ArrayList<FileTreeEntry>(26 * 26);
@ -262,6 +286,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
} }
} }
@Test
public void test008_SubtreeInternalSorting() throws IOException { public void test008_SubtreeInternalSorting() throws IOException {
final Tree t = new Tree(db); final Tree t = new Tree(db);
final FileTreeEntry e0 = t.addFile("a-b"); final FileTreeEntry e0 = t.addFile("a-b");
@ -278,6 +303,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase {
assertSame(e2, ents[4]); assertSame(e2, ents[4]);
} }
@Test
public void test009_SymlinkAndGitlink() throws IOException { public void test009_SymlinkAndGitlink() throws IOException {
final Tree symlinkTree = db.mapTree("symlink"); final Tree symlinkTree = db.mapTree("symlink");
assertTrue("Symlink entry exists", symlinkTree.existsBlob("symlink.txt")); assertTrue("Symlink entry exists", symlinkTree.existsBlob("symlink.txt"));

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java

@ -43,12 +43,19 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import junit.framework.TestCase; import org.junit.Test;
public class ThreadSafeProgressMonitorTest extends TestCase { public class ThreadSafeProgressMonitorTest {
@Test
public void testFailsMethodsOnBackgroundThread() public void testFailsMethodsOnBackgroundThread()
throws InterruptedException { throws InterruptedException {
final MockProgressMonitor mock = new MockProgressMonitor(); final MockProgressMonitor mock = new MockProgressMonitor();
@ -84,6 +91,7 @@ public class ThreadSafeProgressMonitorTest extends TestCase {
assertEquals(0, mock.value); assertEquals(0, mock.value);
} }
@Test
public void testMethodsOkOnMainThread() { public void testMethodsOkOnMainThread() {
final MockProgressMonitor mock = new MockProgressMonitor(); final MockProgressMonitor mock = new MockProgressMonitor();
final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock); final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock);
@ -106,6 +114,7 @@ public class ThreadSafeProgressMonitorTest extends TestCase {
assertEquals(0, mock.value); assertEquals(0, mock.value);
} }
@Test
public void testUpdateOnBackgroundThreads() throws InterruptedException { public void testUpdateOnBackgroundThreads() throws InterruptedException {
final MockProgressMonitor mock = new MockProgressMonitor(); final MockProgressMonitor mock = new MockProgressMonitor();
final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock); final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock);

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorLeafOnlyTest.java

@ -44,11 +44,18 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.junit.Test;
public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { public class TreeIteratorLeafOnlyTest extends RepositoryTestCase {
/** Empty tree */ /** Empty tree */
@Test
public void testEmpty() { public void testEmpty() {
Tree tree = new Tree(db); Tree tree = new Tree(db);
TreeIterator i = makeIterator(tree); TreeIterator i = makeIterator(tree);
@ -60,6 +67,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleF1() throws IOException { public void testSimpleF1() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("x"); tree.addFile("x");
@ -73,6 +81,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleF2() throws IOException { public void testSimpleF2() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("a"); tree.addFile("a");
@ -88,6 +97,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleT() throws IOException { public void testSimpleT() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addTree("a"); tree.addTree("a");
@ -95,6 +105,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase {
assertFalse(i.hasNext()); assertFalse(i.hasNext());
} }
@Test
public void testTricky() throws IOException { public void testTricky() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("a.b"); tree.addFile("a.b");

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPostOrderTest.java

@ -44,11 +44,18 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.junit.Test;
public class TreeIteratorPostOrderTest extends RepositoryTestCase { public class TreeIteratorPostOrderTest extends RepositoryTestCase {
/** Empty tree */ /** Empty tree */
@Test
public void testEmpty() { public void testEmpty() {
Tree tree = new Tree(db); Tree tree = new Tree(db);
TreeIterator i = makeIterator(tree); TreeIterator i = makeIterator(tree);
@ -62,6 +69,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleF1() throws IOException { public void testSimpleF1() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("x"); tree.addFile("x");
@ -78,6 +86,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleF2() throws IOException { public void testSimpleF2() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("a"); tree.addFile("a");
@ -96,6 +105,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleT() throws IOException { public void testSimpleT() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addTree("a"); tree.addTree("a");
@ -107,6 +117,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase {
assertFalse(i.hasNext()); assertFalse(i.hasNext());
} }
@Test
public void testTricky() throws IOException { public void testTricky() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("a.b"); tree.addFile("a.b");

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPreOrderTest.java

@ -44,11 +44,18 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.junit.Test;
public class TreeIteratorPreOrderTest extends RepositoryTestCase { public class TreeIteratorPreOrderTest extends RepositoryTestCase {
/** Empty tree */ /** Empty tree */
@Test
public void testEmpty() { public void testEmpty() {
Tree tree = new Tree(db); Tree tree = new Tree(db);
TreeIterator i = makeIterator(tree); TreeIterator i = makeIterator(tree);
@ -62,6 +69,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleF1() throws IOException { public void testSimpleF1() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("x"); tree.addFile("x");
@ -78,6 +86,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleF2() throws IOException { public void testSimpleF2() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("a"); tree.addFile("a");
@ -96,6 +105,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSimpleT() throws IOException { public void testSimpleT() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addTree("a"); tree.addTree("a");
@ -107,6 +117,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase {
assertFalse(i.hasNext()); assertFalse(i.hasNext());
} }
@Test
public void testTricky() throws IOException { public void testTricky() throws IOException {
Tree tree = new Tree(db); Tree tree = new Tree(db);
tree.addFile("a.b"); tree.addFile("a.b");

22
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java

@ -43,23 +43,28 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
public class ValidRefNameTest extends TestCase { import org.junit.Test;
public class ValidRefNameTest {
private static void assertValid(final boolean exp, final String name) { private static void assertValid(final boolean exp, final String name) {
assertEquals("\"" + name + "\"", exp, Repository.isValidRefName(name)); assertEquals("\"" + name + "\"", exp, Repository.isValidRefName(name));
} }
@Test
public void testEmptyString() { public void testEmptyString() {
assertValid(false, ""); assertValid(false, "");
assertValid(false, "/"); assertValid(false, "/");
} }
@Test
public void testMustHaveTwoComponents() { public void testMustHaveTwoComponents() {
assertValid(false, "master"); assertValid(false, "master");
assertValid(true, "heads/master"); assertValid(true, "heads/master");
} }
@Test
public void testValidHead() { public void testValidHead() {
assertValid(true, "refs/heads/master"); assertValid(true, "refs/heads/master");
assertValid(true, "refs/heads/pu"); assertValid(true, "refs/heads/pu");
@ -67,27 +72,33 @@ public class ValidRefNameTest extends TestCase {
assertValid(true, "refs/heads/FoO"); assertValid(true, "refs/heads/FoO");
} }
@Test
public void testValidTag() { public void testValidTag() {
assertValid(true, "refs/tags/v1.0"); assertValid(true, "refs/tags/v1.0");
} }
@Test
public void testNoLockSuffix() { public void testNoLockSuffix() {
assertValid(false, "refs/heads/master.lock"); assertValid(false, "refs/heads/master.lock");
} }
@Test
public void testNoDirectorySuffix() { public void testNoDirectorySuffix() {
assertValid(false, "refs/heads/master/"); assertValid(false, "refs/heads/master/");
} }
@Test
public void testNoSpace() { public void testNoSpace() {
assertValid(false, "refs/heads/i haz space"); assertValid(false, "refs/heads/i haz space");
} }
@Test
public void testNoAsciiControlCharacters() { public void testNoAsciiControlCharacters() {
for (char c = '\0'; c < ' '; c++) for (char c = '\0'; c < ' '; c++)
assertValid(false, "refs/heads/mast" + c + "er"); assertValid(false, "refs/heads/mast" + c + "er");
} }
@Test
public void testNoBareDot() { public void testNoBareDot() {
assertValid(false, "refs/heads/."); assertValid(false, "refs/heads/.");
assertValid(false, "refs/heads/.."); assertValid(false, "refs/heads/..");
@ -95,6 +106,7 @@ public class ValidRefNameTest extends TestCase {
assertValid(false, "refs/heads/../master"); assertValid(false, "refs/heads/../master");
} }
@Test
public void testNoLeadingOrTrailingDot() { public void testNoLeadingOrTrailingDot() {
assertValid(false, "."); assertValid(false, ".");
assertValid(false, "refs/heads/.bar"); assertValid(false, "refs/heads/.bar");
@ -102,11 +114,13 @@ public class ValidRefNameTest extends TestCase {
assertValid(false, "refs/heads/bar."); assertValid(false, "refs/heads/bar.");
} }
@Test
public void testContainsDot() { public void testContainsDot() {
assertValid(true, "refs/heads/m.a.s.t.e.r"); assertValid(true, "refs/heads/m.a.s.t.e.r");
assertValid(false, "refs/heads/master..pu"); assertValid(false, "refs/heads/master..pu");
} }
@Test
public void testNoMagicRefCharacters() { public void testNoMagicRefCharacters() {
assertValid(false, "refs/heads/master^"); assertValid(false, "refs/heads/master^");
assertValid(false, "refs/heads/^master"); assertValid(false, "refs/heads/^master");
@ -121,6 +135,7 @@ public class ValidRefNameTest extends TestCase {
assertValid(false, ":refs/heads/master"); assertValid(false, ":refs/heads/master");
} }
@Test
public void testShellGlob() { public void testShellGlob() {
assertValid(false, "refs/heads/master?"); assertValid(false, "refs/heads/master?");
assertValid(false, "refs/heads/?master"); assertValid(false, "refs/heads/?master");
@ -135,6 +150,7 @@ public class ValidRefNameTest extends TestCase {
assertValid(false, "*refs/heads/master"); assertValid(false, "*refs/heads/master");
} }
@Test
public void testValidSpecialCharacters() { public void testValidSpecialCharacters() {
assertValid(true, "refs/heads/!"); assertValid(true, "refs/heads/!");
assertValid(true, "refs/heads/\""); assertValid(true, "refs/heads/\"");
@ -166,10 +182,12 @@ public class ValidRefNameTest extends TestCase {
assertValid(false, "refs/heads/\\"); assertValid(false, "refs/heads/\\");
} }
@Test
public void testUnicodeNames() { public void testUnicodeNames() {
assertValid(true, "refs/heads/\u00e5ngstr\u00f6m"); assertValid(true, "refs/heads/\u00e5ngstr\u00f6m");
} }
@Test
public void testRefLogQueryIsValidRef() { public void testRefLogQueryIsValidRef() {
assertValid(false, "refs/heads/master@{1}"); assertValid(false, "refs/heads/master@{1}");
assertValid(false, "refs/heads/master@{1.hour.ago}"); assertValid(false, "refs/heads/master@{1.hour.ago}");

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckoutTest.java

@ -44,13 +44,21 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.jgit.errors.CheckoutConflictException; import org.eclipse.jgit.errors.CheckoutConflictException;
import org.junit.Test;
public class WorkDirCheckoutTest extends RepositoryTestCase { public class WorkDirCheckoutTest extends RepositoryTestCase {
@Test
public void testFindingConflicts() throws IOException { public void testFindingConflicts() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
index.add(trash, writeTrashFile("bar", "bar")); index.add(trash, writeTrashFile("bar", "bar"));
@ -86,6 +94,7 @@ public class WorkDirCheckoutTest extends RepositoryTestCase {
assertTrue(removedEntries.contains("foo")); assertTrue(removedEntries.contains("foo"));
} }
@Test
public void testCheckingOutWithConflicts() throws IOException { public void testCheckingOutWithConflicts() throws IOException {
GitIndex index = new GitIndex(db); GitIndex index = new GitIndex(db);
index.add(trash, writeTrashFile("bar", "bar")); index.add(trash, writeTrashFile("bar", "bar"));

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java

@ -45,6 +45,9 @@
package org.eclipse.jgit.merge; package org.eclipse.jgit.merge;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheBuilder;
@ -57,8 +60,10 @@ import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.junit.Test;
public class CherryPickTest extends RepositoryTestCase { public class CherryPickTest extends RepositoryTestCase {
@Test
public void testPick() throws Exception { public void testPick() throws Exception {
// B---O // B---O
// \----P---T // \----P---T

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java

@ -43,16 +43,17 @@
package org.eclipse.jgit.merge; package org.eclipse.jgit.merge;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.diff.RawTextComparator;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
public class MergeAlgorithmTest extends TestCase { public class MergeAlgorithmTest {
MergeFormatter fmt=new MergeFormatter(); MergeFormatter fmt=new MergeFormatter();
/** /**
@ -61,6 +62,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testTwoConflictingModifications() throws IOException { public void testTwoConflictingModifications() throws IOException {
assertEquals(t("a<b=Z>Zdefghij"), assertEquals(t("a<b=Z>Zdefghij"),
merge("abcdefghij", "abZdefghij", "aZZdefghij")); merge("abcdefghij", "abZdefghij", "aZZdefghij"));
@ -73,6 +75,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testOneAgainstTwoConflictingModifications() throws IOException { public void testOneAgainstTwoConflictingModifications() throws IOException {
assertEquals(t("aZ<Z=c>Zefghij"), assertEquals(t("aZ<Z=c>Zefghij"),
merge("abcdefghij", "aZZZefghij", "aZcZefghij")); merge("abcdefghij", "aZZZefghij", "aZcZefghij"));
@ -84,6 +87,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testNoAgainstOneModification() throws IOException { public void testNoAgainstOneModification() throws IOException {
assertEquals(t("aZcZefghij"), assertEquals(t("aZcZefghij"),
merge("abcdefghij", "abcdefghij", "aZcZefghij")); merge("abcdefghij", "abcdefghij", "aZcZefghij"));
@ -95,6 +99,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testTwoNonConflictingModifications() throws IOException { public void testTwoNonConflictingModifications() throws IOException {
assertEquals(t("YbZdefghij"), assertEquals(t("YbZdefghij"),
merge("abcdefghij", "abZdefghij", "Ybcdefghij")); merge("abcdefghij", "abZdefghij", "Ybcdefghij"));
@ -106,6 +111,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testTwoComplicatedModifications() throws IOException { public void testTwoComplicatedModifications() throws IOException {
assertEquals(t("a<ZZZZfZhZj=bYdYYYYiY>"), assertEquals(t("a<ZZZZfZhZj=bYdYYYYiY>"),
merge("abcdefghij", "aZZZZfZhZj", "abYdYYYYiY")); merge("abcdefghij", "aZZZZfZhZj", "abYdYYYYiY"));
@ -116,6 +122,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testConflictAtStart() throws IOException { public void testConflictAtStart() throws IOException {
assertEquals(t("<Z=Y>bcdefghij"), assertEquals(t("<Z=Y>bcdefghij"),
merge("abcdefghij", "Zbcdefghij", "Ybcdefghij")); merge("abcdefghij", "Zbcdefghij", "Ybcdefghij"));
@ -126,6 +133,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testConflictAtEnd() throws IOException { public void testConflictAtEnd() throws IOException {
assertEquals(t("abcdefghi<Z=Y>"), assertEquals(t("abcdefghi<Z=Y>"),
merge("abcdefghij", "abcdefghiZ", "abcdefghiY")); merge("abcdefghij", "abcdefghiZ", "abcdefghiY"));
@ -137,6 +145,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testSameModification() throws IOException { public void testSameModification() throws IOException {
assertEquals(t("abZdefghij"), assertEquals(t("abZdefghij"),
merge("abcdefghij", "abZdefghij", "abZdefghij")); merge("abcdefghij", "abZdefghij", "abZdefghij"));
@ -148,19 +157,23 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testDeleteVsModify() throws IOException { public void testDeleteVsModify() throws IOException {
assertEquals(t("ab<=Z>defghij"), assertEquals(t("ab<=Z>defghij"),
merge("abcdefghij", "abdefghij", "abZdefghij")); merge("abcdefghij", "abdefghij", "abZdefghij"));
} }
@Test
public void testInsertVsModify() throws IOException { public void testInsertVsModify() throws IOException {
assertEquals(t("a<bZ=XY>"), merge("ab", "abZ", "aXY")); assertEquals(t("a<bZ=XY>"), merge("ab", "abZ", "aXY"));
} }
@Test
public void testAdjacentModifications() throws IOException { public void testAdjacentModifications() throws IOException {
assertEquals(t("a<Zc=bY>d"), merge("abcd", "aZcd", "abYd")); assertEquals(t("a<Zc=bY>d"), merge("abcd", "aZcd", "abYd"));
} }
@Test
public void testSeperateModifications() throws IOException { public void testSeperateModifications() throws IOException {
assertEquals(t("aZcYe"), merge("abcde", "aZcde", "abcYe")); assertEquals(t("aZcYe"), merge("abcde", "aZcde", "abcYe"));
} }
@ -172,6 +185,7 @@ public class MergeAlgorithmTest extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testTwoSimilarModsAndOneInsert() throws IOException { public void testTwoSimilarModsAndOneInsert() throws IOException {
assertEquals(t("IAAJ"), merge("iA", "IA", "IAAJ")); assertEquals(t("IAAJ"), merge("iA", "IA", "IAAJ"));
assertEquals(t("aBcDde"), merge("abcde", "aBcde", "aBcDde")); assertEquals(t("aBcDde"), merge("abcde", "aBcde", "aBcDde"));

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java

@ -42,15 +42,19 @@
*/ */
package org.eclipse.jgit.merge; package org.eclipse.jgit.merge;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.Ref.Storage; import org.junit.Before;
import org.junit.Test;
/** /**
* Test construction of merge message by {@link MergeMessageFormatter}. * Test construction of merge message by {@link MergeMessageFormatter}.
@ -60,7 +64,8 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
private MergeMessageFormatter formatter; private MergeMessageFormatter formatter;
@Override @Override
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
super.setUp(); super.setUp();
RefUpdate createRemoteRefA = db RefUpdate createRemoteRefA = db
@ -76,6 +81,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
formatter = new MergeMessageFormatter(); formatter = new MergeMessageFormatter();
} }
@Test
public void testOneBranch() throws IOException { public void testOneBranch() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.getRef("refs/heads/a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.getRef("refs/heads/master");
@ -83,6 +89,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
assertEquals("Merge branch 'a'", message); assertEquals("Merge branch 'a'", message);
} }
@Test
public void testTwoBranches() throws IOException { public void testTwoBranches() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.getRef("refs/heads/a");
Ref b = db.getRef("refs/heads/b"); Ref b = db.getRef("refs/heads/b");
@ -91,6 +98,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
assertEquals("Merge branches 'a' and 'b'", message); assertEquals("Merge branches 'a' and 'b'", message);
} }
@Test
public void testThreeBranches() throws IOException { public void testThreeBranches() throws IOException {
Ref c = db.getRef("refs/heads/c"); Ref c = db.getRef("refs/heads/c");
Ref b = db.getRef("refs/heads/b"); Ref b = db.getRef("refs/heads/b");
@ -100,6 +108,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
assertEquals("Merge branches 'c', 'b' and 'a'", message); assertEquals("Merge branches 'c', 'b' and 'a'", message);
} }
@Test
public void testRemoteBranch() throws Exception { public void testRemoteBranch() throws Exception {
Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); Ref remoteA = db.getRef("refs/remotes/origin/remote-a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.getRef("refs/heads/master");
@ -107,6 +116,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
assertEquals("Merge remote branch 'origin/remote-a'", message); assertEquals("Merge remote branch 'origin/remote-a'", message);
} }
@Test
public void testMixed() throws IOException { public void testMixed() throws IOException {
Ref c = db.getRef("refs/heads/c"); Ref c = db.getRef("refs/heads/c");
Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); Ref remoteA = db.getRef("refs/remotes/origin/remote-a");
@ -116,6 +126,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
message); message);
} }
@Test
public void testTag() throws IOException { public void testTag() throws IOException {
Ref tagA = db.getRef("refs/tags/A"); Ref tagA = db.getRef("refs/tags/A");
Ref master = db.getRef("refs/heads/master"); Ref master = db.getRef("refs/heads/master");
@ -123,6 +134,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
assertEquals("Merge tag 'A'", message); assertEquals("Merge tag 'A'", message);
} }
@Test
public void testCommit() throws IOException { public void testCommit() throws IOException {
ObjectId objectId = ObjectId ObjectId objectId = ObjectId
.fromString("6db9c2ebf75590eef973081736730a9ea169a0c4"); .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4");
@ -134,6 +146,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
message); message);
} }
@Test
public void testPullWithUri() throws IOException { public void testPullWithUri() throws IOException {
String name = "branch 'test' of http://egit.eclipse.org/jgit.git"; String name = "branch 'test' of http://egit.eclipse.org/jgit.git";
ObjectId objectId = ObjectId ObjectId objectId = ObjectId
@ -146,6 +159,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
message); message);
} }
@Test
public void testIntoOtherThanMaster() throws IOException { public void testIntoOtherThanMaster() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.getRef("refs/heads/a");
Ref b = db.getRef("refs/heads/b"); Ref b = db.getRef("refs/heads/b");

17
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java

@ -45,6 +45,9 @@
package org.eclipse.jgit.merge; package org.eclipse.jgit.merge;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
@ -59,9 +62,11 @@ import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.junit.Test;
public class SimpleMergeTest extends SampleDataRepositoryTestCase { public class SimpleMergeTest extends SampleDataRepositoryTestCase {
@Test
public void testOurs() throws IOException { public void testOurs() throws IOException {
Merger ourMerger = MergeStrategy.OURS.newMerger(db); Merger ourMerger = MergeStrategy.OURS.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") }); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
@ -69,6 +74,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertEquals(db.mapTree("a").getId(), ourMerger.getResultTreeId()); assertEquals(db.mapTree("a").getId(), ourMerger.getResultTreeId());
} }
@Test
public void testTheirs() throws IOException { public void testTheirs() throws IOException {
Merger ourMerger = MergeStrategy.THEIRS.newMerger(db); Merger ourMerger = MergeStrategy.THEIRS.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") }); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
@ -76,6 +82,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertEquals(db.mapTree("c").getId(), ourMerger.getResultTreeId()); assertEquals(db.mapTree("c").getId(), ourMerger.getResultTreeId());
} }
@Test
public void testTrivialTwoWay() throws IOException { public void testTrivialTwoWay() throws IOException {
Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") }); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
@ -83,6 +90,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",ourMerger.getResultTreeId().name()); assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",ourMerger.getResultTreeId().name());
} }
@Test
public void testTrivialTwoWay_disjointhistories() throws IOException { public void testTrivialTwoWay_disjointhistories() throws IOException {
Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c~4") }); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c~4") });
@ -90,6 +98,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertEquals("86265c33b19b2be71bdd7b8cb95823f2743d03a8",ourMerger.getResultTreeId().name()); assertEquals("86265c33b19b2be71bdd7b8cb95823f2743d03a8",ourMerger.getResultTreeId().name());
} }
@Test
public void testTrivialTwoWay_ok() throws IOException { public void testTrivialTwoWay_ok() throws IOException {
Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a^0^0^0"), db.resolve("a^0^0^1") }); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a^0^0^0"), db.resolve("a^0^0^1") });
@ -97,12 +106,14 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertEquals(db.mapTree("a^0^0").getId(), ourMerger.getResultTreeId()); assertEquals(db.mapTree("a^0^0").getId(), ourMerger.getResultTreeId());
} }
@Test
public void testTrivialTwoWay_conflict() throws IOException { public void testTrivialTwoWay_conflict() throws IOException {
Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("f"), db.resolve("g") }); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("f"), db.resolve("g") });
assertFalse(merge); assertFalse(merge);
} }
@Test
public void testTrivialTwoWay_validSubtreeSort() throws Exception { public void testTrivialTwoWay_validSubtreeSort() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();
@ -155,6 +166,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(tw.next()); assertFalse(tw.next());
} }
@Test
public void testTrivialTwoWay_concurrentSubtreeChange() throws Exception { public void testTrivialTwoWay_concurrentSubtreeChange() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();
@ -202,6 +214,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(tw.next()); assertFalse(tw.next());
} }
@Test
public void testTrivialTwoWay_conflictSubtreeChange() throws Exception { public void testTrivialTwoWay_conflictSubtreeChange() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();
@ -235,6 +248,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(merge); assertFalse(merge);
} }
@Test
public void testTrivialTwoWay_leftDFconflict1() throws Exception { public void testTrivialTwoWay_leftDFconflict1() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();
@ -267,6 +281,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(merge); assertFalse(merge);
} }
@Test
public void testTrivialTwoWay_rightDFconflict1() throws Exception { public void testTrivialTwoWay_rightDFconflict1() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();
@ -299,6 +314,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(merge); assertFalse(merge);
} }
@Test
public void testTrivialTwoWay_leftDFconflict2() throws Exception { public void testTrivialTwoWay_leftDFconflict2() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();
@ -329,6 +345,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
assertFalse(merge); assertFalse(merge);
} }
@Test
public void testTrivialTwoWay_rightDFconflict2() throws Exception { public void testTrivialTwoWay_rightDFconflict2() throws Exception {
final DirCache treeB = db.readDirCache(); final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache(); final DirCache treeO = db.readDirCache();

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/NonTranslatedBundle.java

@ -43,9 +43,6 @@
package org.eclipse.jgit.nls; package org.eclipse.jgit.nls;
import org.eclipse.jgit.nls.NLS;
import org.eclipse.jgit.nls.TranslationBundle;
public class NonTranslatedBundle extends TranslationBundle { public class NonTranslatedBundle extends TranslationBundle {
public static NonTranslatedBundle get() { public static NonTranslatedBundle get() {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save