diff --git a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF index 5283e8aea..ff4464e6c 100644 --- a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF @@ -8,7 +8,6 @@ Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: javax.servlet;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.http;version="[7.1.0,8.0.0)", org.eclipse.jetty.http.security;version="[7.1.0,8.0.0)", diff --git a/org.eclipse.jgit.http.test/org.eclipse.jgit.core.http --All-Tests (Java 6).launch b/org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests (Java 6).launch similarity index 100% rename from org.eclipse.jgit.http.test/org.eclipse.jgit.core.http --All-Tests (Java 6).launch rename to org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests (Java 6).launch diff --git a/org.eclipse.jgit.http.test/org.eclipse.jgit.core.http --All-Tests.launch b/org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests.launch similarity index 100% rename from org.eclipse.jgit.http.test/org.eclipse.jgit.core.http --All-Tests.launch rename to org.eclipse.jgit.http.test/org.eclipse.jgit.core.http--All-Tests.launch diff --git a/org.eclipse.jgit.http.test/org.eclipse.jgit.http--All-Tests.launch b/org.eclipse.jgit.http.test/org.eclipse.jgit.http--All-Tests.launch index 819e9827b..f22dc4bbe 100644 --- a/org.eclipse.jgit.http.test/org.eclipse.jgit.http--All-Tests.launch +++ b/org.eclipse.jgit.http.test/org.eclipse.jgit.http--All-Tests.launch @@ -9,7 +9,7 @@ - + diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java index ddb32c94e..4aa0919a1 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java @@ -43,6 +43,9 @@ package org.eclipse.jgit.http.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.util.Collections; 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.Transport; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class AdvertiseErrorTest extends HttpTestCase { private FileRepository remoteRepository; private URIish remoteURI; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); final TestRepository src = createTestRepository(); @@ -120,6 +126,7 @@ public class AdvertiseErrorTest extends HttpTestCase { cfg.save(); } + @Test public void testPush_CreateBranch() throws Exception { final TestRepository src = createTestRepository(); final RevBlob Q_txt = src.blob("new text"); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java index 3442af94d..6bdb4969f 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.http.test; +import static org.junit.Assert.fail; + import java.io.IOException; 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.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; +import org.junit.Before; +import org.junit.Test; public class AsIsServiceTest extends LocalDiskRepositoryTestCase { private Repository db; private AsIsFileService service; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); db = createBareRepository(); service = new AsIsFileService(); } + @Test public void testDisabledSingleton() throws ServiceNotAuthorizedException { service = AsIsFileService.DISABLED; try { @@ -84,12 +90,14 @@ public class AsIsServiceTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_Default() throws ServiceNotEnabledException, ServiceNotAuthorizedException { service.access(new R(null, "1.2.3.4"), db); service.access(new R("bob", "1.2.3.4"), db); } + @Test public void testCreate_Disabled() throws ServiceNotAuthorizedException, IOException { final StoredConfig cfg = db.getConfig(); @@ -111,6 +119,7 @@ public class AsIsServiceTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_Enabled() throws ServiceNotEnabledException, ServiceNotAuthorizedException { db.getConfig().setBoolean("http", null, "getanyfile", true); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java index 81d5f4f51..ff6c43d45 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java @@ -43,6 +43,11 @@ 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 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.StoredConfig; import org.eclipse.jgit.transport.ReceivePack; +import org.junit.Before; +import org.junit.Test; public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { private Repository db; private ReceivePackFactory factory; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); db = createBareRepository(); factory = new DefaultReceivePackFactory(); } + @Test public void testDisabledSingleton() throws ServiceNotAuthorizedException { factory = ReceivePackFactory.DISABLED; @@ -95,6 +104,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_NullUser() throws ServiceNotEnabledException { try { factory.create(new R(null, "localhost"), db); @@ -104,6 +114,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_EmptyStringUser() throws ServiceNotEnabledException { try { factory.create(new R("", "localhost"), db); @@ -113,6 +124,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_AuthUser() throws ServiceNotEnabledException, ServiceNotAuthorizedException { ReceivePack rp; @@ -130,6 +142,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { assertEquals(author.getWhen(), id.getWhen()); } + @Test public void testCreate_Disabled() throws ServiceNotAuthorizedException, IOException { final StoredConfig cfg = db.getConfig(); @@ -158,6 +171,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_Enabled() throws ServiceNotEnabledException, ServiceNotAuthorizedException, IOException { final StoredConfig cfg = db.getConfig(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java index 24bf480dd..def29dc02 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java @@ -43,6 +43,10 @@ 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 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.StoredConfig; import org.eclipse.jgit.transport.UploadPack; +import org.junit.Before; +import org.junit.Test; public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { private Repository db; private UploadPackFactory factory; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); db = createBareRepository(); factory = new DefaultUploadPackFactory(); } + @Test public void testDisabledSingleton() throws ServiceNotAuthorizedException { factory = UploadPackFactory.DISABLED; @@ -94,6 +102,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_Default() throws ServiceNotEnabledException, ServiceNotAuthorizedException { UploadPack up; @@ -107,6 +116,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { assertSame(db, up.getRepository()); } + @Test public void testCreate_Disabled() throws ServiceNotAuthorizedException, IOException { final StoredConfig cfg = db.getConfig(); @@ -128,6 +138,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCreate_Enabled() throws ServiceNotEnabledException, ServiceNotAuthorizedException { db.getConfig().setBoolean("http", null, "uploadpack", true); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java index e6f763c91..5899dd41d 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java +++ b/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_PRAGMA; 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.IOException; @@ -70,6 +75,8 @@ import org.eclipse.jgit.transport.HttpTransport; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class DumbClientDumbServerTest extends HttpTestCase { private Repository remoteRepository; @@ -80,7 +87,8 @@ public class DumbClientDumbServerTest extends HttpTestCase { private RevCommit A, B; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); final TestRepository src = createTestRepository(); @@ -102,6 +110,7 @@ public class DumbClientDumbServerTest extends HttpTestCase { src.update(master, B); } + @Test public void testListRemote() throws IOException { Repository dst = createBareRepository(); @@ -164,6 +173,7 @@ public class DumbClientDumbServerTest extends HttpTestCase { assertEquals(200, head.getStatus()); } + @Test public void testInitialClone_Loose() throws Exception { Repository dst = createBareRepository(); assertFalse(dst.hasObject(A_txt)); @@ -186,6 +196,7 @@ public class DumbClientDumbServerTest extends HttpTestCase { assertEquals(200, loose.get(0).getStatus()); } + @Test public void testInitialClone_Packed() throws Exception { new TestRepository(remoteRepository).packAndPrune(); @@ -225,6 +236,7 @@ public class DumbClientDumbServerTest extends HttpTestCase { assertEquals(200, event.getStatus()); } + @Test public void testPushNotSupported() throws Exception { final TestRepository src = createTestRepository(); final RevCommit Q = src.commit().create(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java index 92a118904..2347d06cf 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java +++ b/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_PRAGMA; 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.util.List; @@ -75,6 +81,8 @@ import org.eclipse.jgit.transport.HttpTransport; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class DumbClientSmartServerTest extends HttpTestCase { private Repository remoteRepository; @@ -85,7 +93,8 @@ public class DumbClientSmartServerTest extends HttpTestCase { private RevCommit A, B; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); final TestRepository src = createTestRepository(); @@ -118,6 +127,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { src.update(master, B); } + @Test public void testListRemote() throws IOException { Repository dst = createBareRepository(); @@ -179,6 +189,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { assertEquals("text/plain", head.getResponseHeader(HDR_CONTENT_TYPE)); } + @Test public void testInitialClone_Small() throws Exception { Repository dst = createBareRepository(); assertFalse(dst.hasObject(A_txt)); @@ -204,6 +215,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { .getResponseHeader(HDR_CONTENT_TYPE)); } + @Test public void testInitialClone_Packed() throws Exception { new TestRepository(remoteRepository).packAndPrune(); @@ -239,6 +251,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { HDR_CONTENT_TYPE)); } + @Test public void testPushNotSupported() throws Exception { final TestRepository src = createTestRepository(); final RevCommit Q = src.commit().create(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ErrorServletTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ErrorServletTest.java index f92052d1c..dab107426 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ErrorServletTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ErrorServletTest.java @@ -43,21 +43,24 @@ package org.eclipse.jgit.http.test; +import static org.junit.Assert.assertEquals; + import java.net.HttpURLConnection; import java.net.URI; -import junit.framework.TestCase; - import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.http.server.glue.ErrorServlet; 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; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { server = new AppServer(); @@ -68,13 +71,14 @@ public class ErrorServletTest extends TestCase { server.setUp(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (server != null) { server.tearDown(); } - super.tearDown(); } + @Test public void testHandler() throws Exception { final URI uri = server.getURI(); assertEquals(404, ((HttpURLConnection) uri.resolve("/404").toURL() diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java index d7ca5900f..a7e31a5d4 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java @@ -43,6 +43,13 @@ 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.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.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.Repository; +import org.junit.Test; public class FileResolverTest extends LocalDiskRepositoryTestCase { + @Test public void testUnreasonableNames() throws ServiceNotEnabledException { assertUnreasonable(""); assertUnreasonable("a\\b"); @@ -83,6 +92,7 @@ public class FileResolverTest extends LocalDiskRepositoryTestCase { } } + @Test public void testExportOk() throws IOException { final Repository a = createBareRepository(); final String name = a.getDirectory().getName(); @@ -116,6 +126,7 @@ public class FileResolverTest extends LocalDiskRepositoryTestCase { } } + @Test public void testNotAGitRepository() throws IOException, ServiceNotEnabledException { final Repository a = createBareRepository(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletInitTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletInitTest.java index d6c1c46e5..78db5747f 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletInitTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletInitTest.java @@ -43,30 +43,35 @@ 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 javax.servlet.ServletException; -import junit.framework.TestCase; - import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.http.server.GitServlet; import org.eclipse.jgit.junit.http.AppServer; import org.eclipse.jgit.junit.http.MockServletConfig; 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; - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (server != null) { server.tearDown(); server = null; } - super.tearDown(); } + @Test public void testDefaultConstructor_NoBasePath() throws Exception { GitServlet s = new GitServlet(); try { @@ -77,6 +82,7 @@ public class GitServletInitTest extends TestCase { } } + @Test public void testDefaultConstructor_WithBasePath() throws Exception { MockServletConfig c = new MockServletConfig(); c.setInitParameter("base-path", "."); @@ -87,6 +93,7 @@ public class GitServletInitTest extends TestCase { s.destroy(); } + @Test public void testInitUnderContainer_NoBasePath() throws Exception { server = new AppServer(); @@ -104,6 +111,7 @@ public class GitServletInitTest extends TestCase { assertTrue("Wanted base-path", why.getMessage().contains("base-path")); } + @Test public void testInitUnderContainer_WithBasePath() throws Exception { server = new AppServer(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java index b75735dea..31f4bb435 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java @@ -43,6 +43,10 @@ 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.Collections; 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.Transport; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class HookMessageTest extends HttpTestCase { private FileRepository remoteRepository; private URIish remoteURI; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); final TestRepository src = createTestRepository(); @@ -130,6 +137,7 @@ public class HookMessageTest extends HttpTestCase { cfg.save(); } + @Test public void testPush_CreateBranch() throws Exception { final TestRepository src = createTestRepository(); final RevBlob Q_txt = src.blob("new text"); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java index 6cf282f3b..063d9d4da 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java @@ -43,6 +43,13 @@ 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.net.URI; import java.util.List; @@ -86,7 +93,7 @@ public class HttpClientTests extends HttpTestCase { private URIish smartAuthBasicURI; - protected void setUp() throws Exception { + public void setUp() throws Exception { super.setUp(); remoteRepository = createTestRepository(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java index f73f54ffb..e764fe542 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java +++ b/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_LENGTH; 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.PrintWriter; @@ -92,6 +98,8 @@ import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class SmartClientSmartServerTest extends HttpTestCase { private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding"; @@ -106,7 +114,8 @@ public class SmartClientSmartServerTest extends HttpTestCase { private RevCommit A, B; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); final TestRepository src = createTestRepository(); @@ -165,6 +174,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { src.update("refs/garbage/a/very/long/ref/name/to/compress", B); } + @Test public void testListRemote() throws IOException { Repository dst = createBareRepository(); @@ -213,6 +223,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING)); } + @Test public void testInitialClone_Small() throws Exception { Repository dst = createBareRepository(); assertFalse(dst.hasObject(A_txt)); @@ -257,6 +268,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { .getResponseHeader(HDR_CONTENT_TYPE)); } + @Test public void testFetchUpdateExisting() throws Exception { // Bootstrap by doing the clone. // @@ -336,6 +348,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { .getResponseHeader(HDR_CONTENT_TYPE)); } + @Test public void testInitialClone_BrokenServer() throws Exception { Repository dst = createBareRepository(); assertFalse(dst.hasObject(A_txt)); @@ -376,6 +389,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { .getResponseHeader(HDR_CONTENT_TYPE)); } + @Test public void testPush_NotAuthorized() throws Exception { final TestRepository src = createTestRepository(); final RevBlob Q_txt = src.blob("new text"); @@ -418,6 +432,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { assertEquals(401, info.getStatus()); } + @Test public void testPush_CreateBranch() throws Exception { final TestRepository src = createTestRepository(); final RevBlob Q_txt = src.blob("new text"); @@ -490,6 +505,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { .getResponseHeader(HDR_CONTENT_TYPE)); } + @Test public void testPush_ChunkedEncoding() throws Exception { final TestRepository src = createTestRepository(); final RevBlob Q_bin = src.blob(new TestRng("Q").nextBytes(128 * 1024)); diff --git a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF index f240f1ffb..1c28dd112 100644 --- a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF @@ -9,7 +9,6 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: javax.servlet;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.http;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.revwalk;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" diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java index 2d1c98c91..1e7a6e79a 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java @@ -43,6 +43,9 @@ package org.eclipse.jgit.junit.http; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.InetAddress; import java.net.URI; @@ -51,8 +54,6 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; - import org.eclipse.jetty.http.security.Constraint; import org.eclipse.jetty.http.security.Password; import org.eclipse.jetty.security.Authenticator; @@ -282,10 +283,10 @@ public class AppServer { } private void assertNotYetSetUp() { - Assert.assertFalse("server is not running", server.isRunning()); + assertFalse("server is not running", server.isRunning()); } private void assertAlreadySetUp() { - Assert.assertTrue("server is running", server.isRunning()); + assertTrue("server is running", server.isRunning()); } } diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java index 7da903461..56d05c60c 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.junit.http; +import static org.junit.Assert.fail; + import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -73,12 +75,12 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { /** In-memory application server; subclass must start. */ protected AppServer server; - protected void setUp() throws Exception { + public void setUp() throws Exception { super.setUp(); server = new AppServer(); } - protected void tearDown() throws Exception { + public void tearDown() throws Exception { server.tearDown(); super.tearDown(); } diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java index b186e1f24..f71bc9350 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java @@ -43,11 +43,6 @@ 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.util.ArrayList; import java.util.List; @@ -57,6 +52,11 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; 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}. */ class TestRequestLog extends HandlerWrapper { private static final int MAX = 16; diff --git a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF index 63f040399..b5de6baf7 100644 --- a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF @@ -7,8 +7,7 @@ Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: junit.framework;version="[4.0.0,5.0.0)", - org.eclipse.jgit.diff;version="[0.11.0,0.12.0)", +Import-Package: 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.errors;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.filter;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" Require-Bundle: com.jcraft.jsch;bundle-version="[0.1.37,0.2.0)" diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java similarity index 68% rename from org.eclipse.jgit.test/tst/org/eclipse/jgit/util/JGitTestUtil.java rename to org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java index 37418417d..38a451fbf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/JGitTestUtil.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java @@ -43,12 +43,17 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.eclipse.jgit.util; +package org.eclipse.jgit.junit; import java.io.File; +import java.lang.reflect.Method; import java.net.URISyntaxException; import java.net.URL; +import org.eclipse.jgit.util.RawParseUtils; +import org.junit.Assert; +import org.junit.Test; + public abstract class JGitTestUtil { public static final String CLASSPATH_TO_RESOURCES = "org/eclipse/jgit/test/resources/"; @@ -56,6 +61,52 @@ public abstract class JGitTestUtil { 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) { if (fileName == null || fileName.length() <= 0) { return null; diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index dd143826e..3917c487d 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.junit; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -57,10 +60,6 @@ import java.util.List; import java.util.Map; 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.PersonIdent; 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.IO; import org.eclipse.jgit.util.SystemReader; +import org.junit.After; +import org.junit.Before; /** * 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 * descriptors or address space for the test process. */ -public abstract class LocalDiskRepositoryTestCase extends TestCase { +public abstract class LocalDiskRepositoryTestCase { private static Thread shutdownHook; private static int testCount; @@ -110,9 +111,8 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase { private MockSystemReader mockSystemReader; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { synchronized(this) { if (shutdownHook == null) { @@ -131,7 +131,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase { Runtime.getRuntime().addShutdownHook(shutdownHook); } } - recursiveDelete(testName(), trash, true, false); + recursiveDelete(testId(), trash, true, false); mockSystemReader = new MockSystemReader(); mockSystemReader.userGitConfig = new FileBasedConfig(new File(trash, @@ -174,8 +174,8 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase { return stringBuilder.toString(); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { RepositoryCache.clear(); for (Repository r : toClose) r.close(); @@ -188,8 +188,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase { if (useMMAP) System.gc(); - recursiveDelete(testName(), trash, false, true); - super.tearDown(); + recursiveDelete(testId(), trash, false, true); } /** 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. */ protected void recursiveDelete(final File dir) { - recursiveDelete(testName(), dir, false, true); + recursiveDelete(testId(), dir, false, true); } 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"); } - protected static void assertEquals(AnyObjectId exp, AnyObjectId act) { - Assert.assertEquals(exp, act); - } - private static String[] toEnvArray(final Map env) { final String[] envp = new String[env.size()]; int i = 0; @@ -431,7 +426,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase { return new HashMap(System.getenv()); } - private String testName() { - return getClass().getName() + "." + getName(); + private String testId() { + return getClass().getName() + "." + testCount; } } diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 71446a0dc..eea7811c0 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.junit; +import static org.junit.Assert.*; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -56,9 +58,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import junit.framework.Assert; -import junit.framework.AssertionFailedError; - import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheEditor; @@ -277,12 +276,10 @@ public class TestRepository { * @param path * the path to find the entry of. * @return the parsed object entry at this path, never null. - * @throws AssertionFailedError - * if the path does not exist in the given tree. * @throws Exception */ public RevObject get(final RevTree tree, final String path) - throws AssertionFailedError, Exception { + throws Exception { final TreeWalk tw = new TreeWalk(pool.getObjectReader()); tw.setFilter(PathFilterGroup.createFromStrings(Collections .singleton(path))); @@ -296,7 +293,7 @@ public class TestRepository { final FileMode entmode = tw.getFileMode(0); 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. } @@ -598,7 +595,7 @@ public class TestRepository { md.update(Constants.encodeASCII(bin.length)); md.update((byte) 0); md.update(bin); - Assert.assertEquals(id, ObjectId.fromRaw(md.digest())); + assertEquals(id, ObjectId.fromRaw(md.digest())); } /** diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index 0a674c21b..91f841191 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -7,8 +7,7 @@ Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: junit.framework;version="[4.0.0,5.0.0)", - org.eclipse.jgit;version="[0.11.0,0.12.0)", +Import-Package: 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.errors;version="[0.11.0,0.12.0)", org.eclipse.jgit.awtui;version="[0.11.0,0.12.0)", diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java index c5591b9bf..4c59d5a94 100644 --- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java +++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java @@ -44,6 +44,11 @@ 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.IOException; import java.io.InputStream; @@ -53,6 +58,8 @@ import java.lang.reflect.Method; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.GitIndex.Entry; import org.eclipse.jgit.util.FS; +import org.junit.Before; +import org.junit.Test; public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { @@ -113,12 +120,14 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { private File trash; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); db = createWorkRepository(); trash = db.getWorkTree(); } + @Test public void testCreateEmptyIndex() throws Exception { GitIndex index = new GitIndex(db); index.write(); @@ -130,12 +139,14 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, indexr.getMembers().length); } + @Test public void testReadWithNoIndex() throws Exception { GitIndex index = new GitIndex(db); index.read(); assertEquals(0, index.getMembers().length); } + @Test public void testCreateSimpleSortTestIndex() throws Exception { GitIndex index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); @@ -163,6 +174,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, system(trash, "git status")); } + @Test public void testUpdateSimpleSortTestIndex() throws Exception { GitIndex index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); @@ -178,6 +190,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, system(trash, "git status")); } + @Test public void testWriteTree() throws Exception { GitIndex index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); @@ -198,6 +211,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, system(trash, "git status")); } + @Test public void testReadTree() throws Exception { // Prepare tree GitIndex index = new GitIndex(db); @@ -236,6 +250,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, system(trash, "git status")); } + @Test public void testReadTree2() throws Exception { // Prepare a larger tree to test some odd cases in tree writing GitIndex index = new GitIndex(db); @@ -281,6 +296,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals("a:b", membersr[5].getName()); } + @Test public void testDelete() throws Exception { GitIndex index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); @@ -305,6 +321,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, system(trash, "git status")); } + @Test public void testCheckout() throws Exception { // Prepare tree, remote it and checkout GitIndex index = new GitIndex(db); @@ -336,6 +353,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { assertEquals(0, system(trash, "git status")); } + @Test public void test030_executeBit_coreModeTrue() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { if (!FS.DETECTED.supportsExecute()) { 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 { if (!FS.DETECTED.supportsExecute()) { System.err.println("Test ignored since platform FS does not support the execute permission"); diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java index ff442b618..dc5821b5c 100644 --- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java +++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java @@ -43,6 +43,11 @@ 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.IOException; import java.io.InputStreamReader; @@ -50,14 +55,14 @@ import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.HashSet; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.TemporaryBuffer; +import org.junit.Test; -public class EGitPatchHistoryTest extends TestCase { +public class EGitPatchHistoryTest { + @Test public void testParseHistory() throws Exception { final NumStatReader numstat = new NumStatReader(); numstat.read(); diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml index 896cf9990..395fb9a67 100644 --- a/org.eclipse.jgit.test/pom.xml +++ b/org.eclipse.jgit.test/pom.xml @@ -129,8 +129,6 @@ -Xmx256m -Dfile.encoding=UTF-8 **/*Test.java - **/*TestCase.java - **/T000*.java diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index 556fc1208..33f305d48 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java @@ -43,6 +43,9 @@ */ package org.eclipse.jgit.api; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileInputStream; 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.RepositoryTestCase; import org.eclipse.jgit.util.FileUtils; +import org.junit.Test; public class AddCommandTest extends RepositoryTestCase { + @Test public void testAddNothing() { Git git = new Git(db); @@ -73,6 +78,7 @@ public class AddCommandTest extends RepositoryTestCase { } + @Test public void testAddNonExistingSingleFile() throws NoFilepatternException { Git git = new Git(db); @@ -81,6 +87,7 @@ public class AddCommandTest extends RepositoryTestCase { } + @Test public void testAddExistingSingleFile() throws IOException, NoFilepatternException { File file = new File(db.getWorkTree(), "a.txt"); file.createNewFile(); @@ -97,6 +104,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException { new File(db.getWorkTree(), "sub").mkdir(); File file = new File(db.getWorkTree(), "sub/a.txt"); @@ -114,6 +122,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException { File file = new File(db.getWorkTree(), "a.txt"); file.createNewFile(); @@ -137,6 +146,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddExistingSingleFileTwiceWithCommit() throws Exception { File file = new File(db.getWorkTree(), "a.txt"); file.createNewFile(); @@ -162,6 +172,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddRemovedFile() throws Exception { File file = new File(db.getWorkTree(), "a.txt"); file.createNewFile(); @@ -183,6 +194,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddRemovedCommittedFile() throws Exception { File file = new File(db.getWorkTree(), "a.txt"); file.createNewFile(); @@ -206,6 +218,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddWithConflicts() throws Exception { // prepare conflict @@ -259,6 +272,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddTwoFiles() throws Exception { File file = new File(db.getWorkTree(), "a.txt"); file.createNewFile(); @@ -280,6 +294,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddFolder() throws Exception { new File(db.getWorkTree(), "sub").mkdir(); File file = new File(db.getWorkTree(), "sub/a.txt"); @@ -302,6 +317,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddIgnoredFile() throws Exception { new File(db.getWorkTree(), "sub").mkdir(); File file = new File(db.getWorkTree(), "sub/a.txt"); @@ -330,6 +346,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAddWholeRepo() throws Exception { new File(db.getWorkTree(), "sub").mkdir(); 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 b exists not in workdir but in index -> unchanged // file c exists in workdir but not in index -> added + @Test public void testAddWithoutParameterUpdate() throws Exception { new File(db.getWorkTree(), "sub").mkdir(); 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 b exists not in workdir but in index -> deleted // file c exists in workdir but not in index -> unchanged + @Test public void testAddWithParameterUpdate() throws Exception { new File(db.getWorkTree(), "sub").mkdir(); File file = new File(db.getWorkTree(), "sub/a.txt"); @@ -457,6 +476,7 @@ public class AddCommandTest extends RepositoryTestCase { indexState(CONTENT)); } + @Test public void testAssumeUnchanged() throws Exception { Git git = new Git(db); String path = "a.txt"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index 83f161e05..eb1b72ed9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -42,6 +42,11 @@ */ 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 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.RemoteConfig; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class BranchCommandTest extends RepositoryTestCase { private Git git; @@ -74,7 +81,8 @@ public class BranchCommandTest extends RepositoryTestCase { RevCommit secondCommit; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); git = new Git(db); // checkout master @@ -128,6 +136,7 @@ public class BranchCommandTest extends RepositoryTestCase { return localGit; } + @Test public void testCreateAndList() throws Exception { int localBefore; int remoteBefore; @@ -180,6 +189,7 @@ public class BranchCommandTest extends RepositoryTestCase { - allBefore); } + @Test public void testCreateFromCommit() throws Exception { Ref branch = git.branchCreate().setName("FromInitial").setStartPoint( initialCommit).call(); @@ -198,6 +208,7 @@ public class BranchCommandTest extends RepositoryTestCase { assertEquals(secondCommit.getId(), branch.getObjectId()); } + @Test public void testCreateForce() throws Exception { // using commits Ref newBranch = createBranch(git, "NewForce", false, secondCommit @@ -230,6 +241,7 @@ public class BranchCommandTest extends RepositoryTestCase { assertEquals(newBranch.getTarget().getObjectId(), initialCommit.getId()); } + @Test public void testDelete() throws Exception { createBranch(git, "ForDelete", false, "master", null); git.branchDelete().setBranchNames("ForDelete").call(); @@ -274,6 +286,7 @@ public class BranchCommandTest extends RepositoryTestCase { } } + @Test public void testPullConfigRemoteBranch() throws Exception { Git localGit = setUpRepoWithRemote(); Ref remote = localGit.branchList().setListMode(ListMode.REMOTE).call() @@ -305,6 +318,7 @@ public class BranchCommandTest extends RepositoryTestCase { localGit.branchDelete().setBranchNames("newFromRemote").call(); } + @Test public void testPullConfigLocalBranch() throws Exception { Git localGit = setUpRepoWithRemote(); // by default, we should not create pull configuration @@ -324,6 +338,7 @@ public class BranchCommandTest extends RepositoryTestCase { "newFromRemote", "remote")); } + @Test public void testPullConfigRenameLocalBranch() throws Exception { Git localGit = setUpRepoWithRemote(); // by default, we should not create pull configuration @@ -348,6 +363,7 @@ public class BranchCommandTest extends RepositoryTestCase { "newFromRemote", "remote")); } + @Test public void testRenameLocalBranch() throws Exception { // null newName not allowed try { @@ -402,6 +418,7 @@ public class BranchCommandTest extends RepositoryTestCase { } } + @Test public void testRenameRemoteTrackingBranch() throws Exception { Git localGit = setUpRepoWithRemote(); Ref remoteBranch = localGit.branchList().setListMode(ListMode.REMOTE) @@ -412,6 +429,7 @@ public class BranchCommandTest extends RepositoryTestCase { assertEquals(Constants.R_REMOTES + "newRemote", renamed.getName()); } + @Test public void testCreationImplicitStart() throws JGitInternalException, GitAPIException { git.branchCreate().setName("topic").call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index 1166464d5..743733586 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -42,6 +42,13 @@ */ 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.FileInputStream; import java.io.IOException; @@ -57,6 +64,8 @@ import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.util.FileUtils; +import org.junit.Before; +import org.junit.Test; public class CheckoutCommandTest extends RepositoryTestCase { private Git git; @@ -66,7 +75,8 @@ public class CheckoutCommandTest extends RepositoryTestCase { RevCommit secondCommit; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); git = new Git(db); // commit something @@ -85,6 +95,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { secondCommit = git.commit().setMessage("Second commit").call(); } + @Test public void testSimpleCheckout() { try { git.checkout().setName("test").call(); @@ -93,6 +104,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } } + @Test public void testCheckout() { try { git.checkout().setName("test").call(); @@ -109,6 +121,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } } + @Test public void testCreateBranchOnCheckout() throws IOException { try { git.checkout().setCreateBranch(true).setName("test2").call(); @@ -118,6 +131,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertNotNull(db.getRef("test2")); } + @Test public void testCheckoutToNonExistingBranch() throws JGitInternalException, RefAlreadyExistsException, InvalidRefNameException { try { @@ -128,6 +142,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } } + @Test public void testCheckoutWithConflict() { CheckoutCommand co = git.checkout(); try { @@ -141,6 +156,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } } + @Test public void testCheckoutWithNonDeletedFiles() throws Exception { File testFile = writeTrashFile("temp", ""); FileInputStream fis = new FileInputStream(testFile); @@ -176,6 +192,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } } + @Test public void testCheckoutCommit() { try { Ref result = git.checkout().setName(initialCommit.name()).call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java index 935412e7a..6f57a6278 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java @@ -42,22 +42,28 @@ */ package org.eclipse.jgit.api; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import java.io.File; import java.io.IOException; 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.lib.Constants; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Test; /** * Test cherry-pick command */ public class CherryPickCommandTest extends RepositoryTestCase { + @Test public void testCherryPick() throws IOException, JGitInternalException, GitAPIException { Git git = new Git(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index c1e24617e..67a9a1b3f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -42,6 +42,10 @@ */ 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.IOException; import java.io.PrintWriter; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java index 27e0b1b54..756802a3f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java @@ -42,6 +42,8 @@ */ package org.eclipse.jgit.api; +import static org.junit.Assert.assertEquals; + import java.io.IOException; 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.RemoteConfig; import org.eclipse.jgit.transport.URIish; +import org.junit.Test; public class FetchCommandTest extends RepositoryTestCase { + @Test public void testFetch() throws JGitInternalException, IOException, GitAPIException, URISyntaxException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java index 428cad850..755370c92 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java @@ -42,19 +42,27 @@ */ 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.IOException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Before; +import org.junit.Test; public class InitCommandTest extends RepositoryTestCase { @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); } + @Test public void testInitRepository() { try { File directory = createTempDirectory("testInitRepository"); @@ -67,6 +75,7 @@ public class InitCommandTest extends RepositoryTestCase { } } + @Test public void testInitBareRepository() { try { File directory = createTempDirectory("testInitBareRepository"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java index d75ec32f0..a35396cc9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java @@ -43,6 +43,11 @@ */ 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.IOException; import java.util.Iterator; @@ -58,8 +63,10 @@ import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Test; public class MergeCommandTest extends RepositoryTestCase { + @Test public void testMergeInItself() throws Exception { Git git = new Git(db); git.commit().setMessage("initial commit").call(); @@ -68,6 +75,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); } + @Test public void testAlreadyUpToDate() throws Exception { Git git = new Git(db); RevCommit first = git.commit().setMessage("initial commit").call(); @@ -80,6 +88,7 @@ public class MergeCommandTest extends RepositoryTestCase { } + @Test public void testFastForward() throws Exception { Git git = new Git(db); RevCommit first = git.commit().setMessage("initial commit").call(); @@ -95,6 +104,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(second, result.getNewHead()); } + @Test public void testFastForwardWithFiles() throws Exception { Git git = new Git(db); @@ -121,6 +131,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(second, result.getNewHead()); } + @Test public void testMultipleHeads() throws Exception { Git git = new Git(db); @@ -153,6 +164,7 @@ public class MergeCommandTest extends RepositoryTestCase { } + @Test public void testContentMerge() throws Exception { Git git = new Git(db); @@ -197,6 +209,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(RepositoryState.MERGING, db.getRepositoryState()); } + @Test public void testMergeNonVersionedPaths() throws Exception { Git git = new Git(db); @@ -247,6 +260,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(RepositoryState.MERGING, db.getRepositoryState()); } + @Test public void testMultipleCreations() throws Exception { Git git = new Git(db); @@ -272,6 +286,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); } + @Test public void testMultipleCreationsSameContent() throws Exception { 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"))); } + @Test public void testSuccessfulContentMerge() throws Exception { Git git = new Git(db); @@ -355,6 +371,7 @@ public class MergeCommandTest extends RepositoryTestCase { // test index state } + @Test public void testSuccessfulContentMergeAndDirtyworkingTree() throws Exception { Git git = new Git(db); @@ -414,6 +431,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(RepositoryState.SAFE, db.getRepositoryState()); } + @Test public void testSingleDeletion() throws Exception { Git git = new Git(db); @@ -466,6 +484,7 @@ public class MergeCommandTest extends RepositoryTestCase { read(new File(db.getWorkTree(), "c/c/c"))); } + @Test public void testMultipleDeletions() throws Exception { Git git = new Git(db); @@ -494,6 +513,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(MergeStatus.MERGED, result.getMergeStatus()); } + @Test public void testDeletionAndConflict() throws Exception { Git git = new Git(db); @@ -536,6 +556,7 @@ public class MergeCommandTest extends RepositoryTestCase { read(new File(db.getWorkTree(), "c/c/c"))); } + @Test public void testMergeFailingWithDirtyWorkingTree() throws Exception { Git git = new Git(db); @@ -574,6 +595,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(RepositoryState.SAFE, db.getRepositoryState()); } + @Test public void testMergeConflictFileFolder() throws Exception { Git git = new Git(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java index 5d54a1c89..ed5650461 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java @@ -42,6 +42,11 @@ */ 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.File; 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.RemoteConfig; import org.eclipse.jgit.transport.URIish; +import org.junit.Before; +import org.junit.Test; public class PullCommandTest extends RepositoryTestCase { /** Second Test repository */ @@ -72,6 +79,7 @@ public class PullCommandTest extends RepositoryTestCase { private File targetFile; + @Test public void testPullFastForward() throws Exception { PullResult res = target.pull().call(); // nothing to update since we don't have different data yet @@ -94,6 +102,7 @@ public class PullCommandTest extends RepositoryTestCase { assertFileContentsEqual(targetFile, "Another change"); } + @Test public void testPullConflict() throws Exception { PullResult res = target.pull().call(); // nothing to update since we don't have different data yet @@ -127,6 +136,7 @@ public class PullCommandTest extends RepositoryTestCase { assertFileContentsEqual(targetFile, result); } + @Test public void testPullLocalConflict() throws Exception { target.branchCreate().setName("basedOnMaster").setStartPoint( "refs/heads/master").setUpstreamMode(SetupUpstreamMode.TRACK) @@ -168,7 +178,8 @@ public class PullCommandTest extends RepositoryTestCase { } @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); dbTarget = createWorkRepository(); source = new Git(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java index 04232f6d0..a32492690 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java @@ -42,6 +42,9 @@ */ package org.eclipse.jgit.api; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.IOException; 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.RemoteConfig; import org.eclipse.jgit.transport.URIish; +import org.junit.Test; public class PushCommandTest extends RepositoryTestCase { + @Test public void testPush() throws JGitInternalException, IOException, GitAPIException, URISyntaxException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java index 9c8f4a7d1..af3bb1cfa 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java @@ -42,6 +42,12 @@ */ 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.File; import java.io.FileInputStream; @@ -63,6 +69,8 @@ import org.eclipse.jgit.lib.RepositoryState; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Before; +import org.junit.Test; public class RebaseCommandTest extends RepositoryTestCase { private static final String FILE1 = "file1"; @@ -70,7 +78,8 @@ public class RebaseCommandTest extends RepositoryTestCase { protected Git git; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); this.git = new Git(db); } @@ -112,6 +121,7 @@ public class RebaseCommandTest extends RepositoryTestCase { refUpdate.forceUpdate(); } + @Test public void testFastForwardWithNewFile() throws Exception { // create file1 on master writeTrashFile(FILE1, FILE1); @@ -134,6 +144,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(Status.UP_TO_DATE, res.getStatus()); } + @Test public void testUpToDate() throws Exception { // create file1 on master writeTrashFile(FILE1, FILE1); @@ -146,6 +157,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(Status.UP_TO_DATE, res.getStatus()); } + @Test public void testUnknownUpstream() throws Exception { // create file1 on master writeTrashFile(FILE1, FILE1); @@ -162,6 +174,7 @@ public class RebaseCommandTest extends RepositoryTestCase { } } + @Test public void testConflictFreeWithSingleFile() throws Exception { // create file1 on master File theFile = writeTrashFile(FILE1, "1\n2\n3\n"); @@ -196,6 +209,7 @@ public class RebaseCommandTest extends RepositoryTestCase { db.resolve(Constants.HEAD)).getParent(0)); } + @Test public void testDetachedHead() throws Exception { // create file1 on master File theFile = writeTrashFile(FILE1, "1\n2\n3\n"); @@ -233,6 +247,7 @@ public class RebaseCommandTest extends RepositoryTestCase { } + @Test public void testFilesAddedFromTwoBranches() throws Exception { // create file1 on master writeTrashFile(FILE1, FILE1); @@ -277,6 +292,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertFalse(new File(db.getWorkTree(), "file3").exists()); } + @Test public void testStopOnConflict() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -336,6 +352,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertFalse(new File(db.getDirectory(), "rebase-merge").exists()); } + @Test public void testStopOnConflictAndContinue() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -390,6 +407,7 @@ public class RebaseCommandTest extends RepositoryTestCase { .getFullMessage()); } + @Test public void testStopOnConflictAndFailContinueIfFileIsDirty() throws Exception { // create file1 on master @@ -430,6 +448,7 @@ public class RebaseCommandTest extends RepositoryTestCase { checkFile(trashFile, "Some local change"); } + @Test public void testStopOnLastConflictAndContinue() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -465,6 +484,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(RepositoryState.SAFE, db.getRepositoryState()); } + @Test public void testStopOnLastConflictAndSkip() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -500,6 +520,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(RepositoryState.SAFE, db.getRepositoryState()); } + @Test public void testMergeFirstStopOnLastConflictAndSkip() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -538,6 +559,7 @@ public class RebaseCommandTest extends RepositoryTestCase { checkFile(FILE1, "merged"); } + @Test public void testStopOnConflictAndSkipNoConflict() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -574,6 +596,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(Status.OK, res.getStatus()); } + @Test public void testStopOnConflictAndSkipWithConflict() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -612,6 +635,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(Status.STOPPED, res.getStatus()); } + @Test public void testStopOnConflictCommitAndContinue() throws Exception { // create file1 on master RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1", @@ -699,6 +723,7 @@ public class RebaseCommandTest extends RepositoryTestCase { checkFile(file, sb.toString()); } + @Test public void testStopOnConflictFileCreationAndDeletion() throws Exception { // create file1 on master writeTrashFile(FILE1, "Hello World"); @@ -786,6 +811,7 @@ public class RebaseCommandTest extends RepositoryTestCase { } + @Test public void testAuthorScriptConverter() throws Exception { // -1 h timezone offset PersonIdent ident = new PersonIdent("Author name", "a.mail@some.com", @@ -821,6 +847,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals(ident.getTimeZoneOffset(), parsedIdent.getTimeZoneOffset()); } + @Test public void testRepositoryStateChecks() throws Exception { try { git.rebase().setOperation(Operation.ABORT).call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java index 3283971d4..d826b4c13 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java @@ -42,11 +42,15 @@ */ package org.eclipse.jgit.api; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Before; +import org.junit.Test; public class RmCommandTest extends RepositoryTestCase { @@ -55,7 +59,8 @@ public class RmCommandTest extends RepositoryTestCase { private static final String FILE = "test.txt"; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); git = new Git(db); // commit something @@ -64,6 +69,7 @@ public class RmCommandTest extends RepositoryTestCase { git.commit().setMessage("Initial commit").call(); } + @Test public void testRemove() throws JGitInternalException, NoFilepatternException, IllegalStateException, IOException { assertEquals("[test.txt, mode:100644, content:Hello world]", diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java index 47b49af1b..d4da87ab0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java @@ -42,6 +42,9 @@ */ 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.InvalidTagNameException; 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.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTag; +import org.junit.Test; public class TagCommandTest extends RepositoryTestCase { + @Test public void testTaggingOnHead() throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException, @@ -65,6 +70,7 @@ public class TagCommandTest extends RepositoryTestCase { assertEquals(commit.getId(), tag.getObject().getId()); } + @Test public void testTagging() throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException, @@ -77,6 +83,7 @@ public class TagCommandTest extends RepositoryTestCase { assertEquals(commit.getId(), tag.getObject().getId()); } + @Test public void testEmptyTagName() throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException { @@ -91,6 +98,7 @@ public class TagCommandTest extends RepositoryTestCase { } } + @Test public void testInvalidTagName() throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, @@ -105,6 +113,7 @@ public class TagCommandTest extends RepositoryTestCase { } } + @Test public void testFailureOnSignedTags() throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java index bee333b16..85b5eb7c0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java @@ -43,76 +43,91 @@ package org.eclipse.jgit.diff; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + 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() { EditList r = diff(t(""), t("")); assertTrue("is empty", r.isEmpty()); } + @Test public void testCreateFile() { EditList r = diff(t(""), t("AB")); assertEquals(1, r.size()); assertEquals(new Edit(0, 0, 0, 2), r.get(0)); } + @Test public void testDeleteFile() { EditList r = diff(t("AB"), t("")); assertEquals(1, r.size()); assertEquals(new Edit(0, 2, 0, 0), r.get(0)); } + @Test public void testDegenerate_InsertMiddle() { EditList r = diff(t("ac"), t("aBc")); assertEquals(1, r.size()); assertEquals(new Edit(1, 1, 1, 2), r.get(0)); } + @Test public void testDegenerate_DeleteMiddle() { EditList r = diff(t("aBc"), t("ac")); assertEquals(1, r.size()); assertEquals(new Edit(1, 2, 1, 1), r.get(0)); } + @Test public void testDegenerate_ReplaceMiddle() { EditList r = diff(t("bCd"), t("bEd")); assertEquals(1, r.size()); assertEquals(new Edit(1, 2, 1, 2), r.get(0)); } + @Test public void testDegenerate_InsertsIntoMidPosition() { EditList r = diff(t("aaaa"), t("aaXaa")); assertEquals(1, r.size()); assertEquals(new Edit(2, 2, 2, 3), r.get(0)); } + @Test public void testDegenerate_InsertStart() { EditList r = diff(t("bc"), t("Abc")); assertEquals(1, r.size()); assertEquals(new Edit(0, 0, 0, 1), r.get(0)); } + @Test public void testDegenerate_DeleteStart() { EditList r = diff(t("Abc"), t("bc")); assertEquals(1, r.size()); assertEquals(new Edit(0, 1, 0, 0), r.get(0)); } + @Test public void testDegenerate_InsertEnd() { EditList r = diff(t("bc"), t("bcD")); assertEquals(1, r.size()); assertEquals(new Edit(2, 2, 2, 3), r.get(0)); } + @Test public void testDegenerate_DeleteEnd() { EditList r = diff(t("bcD"), t("bc")); assertEquals(1, r.size()); assertEquals(new Edit(2, 3, 2, 2), r.get(0)); } + @Test public void testEdit_ReplaceCommonDelete() { EditList r = diff(t("RbC"), t("Sb")); assertEquals(2, r.size()); @@ -120,6 +135,7 @@ public abstract class AbstractDiffTestCase extends TestCase { assertEquals(new Edit(2, 3, 2, 2), r.get(1)); } + @Test public void testEdit_CommonReplaceCommonDeleteCommon() { EditList r = diff(t("aRbCd"), t("aSbd")); assertEquals(2, r.size()); @@ -127,6 +143,7 @@ public abstract class AbstractDiffTestCase extends TestCase { assertEquals(new Edit(3, 4, 3, 3), r.get(1)); } + @Test public void testEdit_MoveBlock() { EditList r = diff(t("aYYbcdz"), t("abcdYYz")); assertEquals(2, r.size()); @@ -134,6 +151,7 @@ public abstract class AbstractDiffTestCase extends TestCase { assertEquals(new Edit(6, 6, 4, 6), r.get(1)); } + @Test public void testEdit_InvertBlocks() { EditList r = diff(t("aYYbcdXXz"), t("aXXbcdYYz")); assertEquals(2, r.size()); @@ -141,6 +159,7 @@ public abstract class AbstractDiffTestCase extends TestCase { assertEquals(new Edit(6, 8, 6, 8), r.get(1)); } + @Test public void testEdit_UniqueCommonLargerThanMatchPoint() { // We are testing 3 unique common matches, but two of // 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)); } + @Test public void testEdit_CommonGrowsPrefixAndSuffix() { // Here there is only one common unique point, but we can grow it // 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)); } + @Test public void testEdit_DuplicateAButCommonUniqueInB() { EditList r = diff(t("AbbcR"), t("CbcS")); assertEquals(2, r.size()); @@ -166,6 +187,7 @@ public abstract class AbstractDiffTestCase extends TestCase { assertEquals(new Edit(4, 5, 3, 4), r.get(1)); } + @Test public void testEdit_InsertNearCommonTail() { EditList r = diff(t("aq}nb"), t("aCq}nD}nb")); assertEquals(new Edit(1, 1, 1, 2), r.get(0)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java index d9c95d765..31f70cf28 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterReflowTest.java @@ -44,17 +44,21 @@ package org.eclipse.jgit.diff; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.ByteArrayOutputStream; import java.io.IOException; 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.Patch; 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 b; @@ -65,12 +69,13 @@ public class DiffFormatterReflowTest extends TestCase { private DiffFormatter fmt; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { out = new ByteArrayOutputStream(); fmt = new DiffFormatter(out); } + @Test public void testNegativeContextFails() throws IOException { init("X"); try { @@ -81,52 +86,61 @@ public class DiffFormatterReflowTest extends TestCase { } } + @Test public void testContext0() throws IOException { init("X"); fmt.setContext(0); assertFormatted(); } + @Test public void testContext1() throws IOException { init("X"); fmt.setContext(1); assertFormatted(); } + @Test public void testContext3() throws IOException { init("X"); fmt.setContext(3); assertFormatted(); } + @Test public void testContext5() throws IOException { init("X"); fmt.setContext(5); assertFormatted(); } + @Test public void testContext10() throws IOException { init("X"); fmt.setContext(10); assertFormatted(); } + @Test public void testContext100() throws IOException { init("X"); fmt.setContext(100); assertFormatted(); } + @Test public void testEmpty1() throws IOException { init("E"); assertFormatted("E.patch"); } + @Test public void testNoNewLine1() throws IOException { init("Y"); assertFormatted("Y.patch"); } + @Test public void testNoNewLine2() throws IOException { init("Z"); assertFormatted("Z.patch"); @@ -139,7 +153,7 @@ public class DiffFormatterReflowTest extends TestCase { } private void assertFormatted() throws IOException { - assertFormatted(getName() + ".out"); + assertFormatted(JGitTestUtil.getName() + ".out"); } private void assertFormatted(final String name) throws IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java index eefbefb07..646e4d611 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.diff; +import static org.junit.Assert.assertEquals; + import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.junit.TestRepository; 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.util.RawParseUtils; import org.eclipse.jgit.util.io.DisabledOutputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class DiffFormatterTest extends RepositoryTestCase { private static final String DIFF = "diff --git "; @@ -69,6 +74,7 @@ public class DiffFormatterTest extends RepositoryTestCase { private TestRepository testDb; @Override + @Before public void setUp() throws Exception { super.setUp(); testDb = new TestRepository(db); @@ -78,12 +84,14 @@ public class DiffFormatterTest extends RepositoryTestCase { } @Override + @After public void tearDown() throws Exception { if (df != null) df.release(); super.tearDown(); } + @Test public void testCreateFileHeader_Add() throws Exception { ObjectId adId = blob("a\nd\n"); DiffEntry ent = DiffEntry.add("FOO", adId); @@ -119,6 +127,7 @@ public class DiffFormatterTest extends RepositoryTestCase { assertEquals(Edit.Type.INSERT, e.getType()); } + @Test public void testCreateFileHeader_Delete() throws Exception { ObjectId adId = blob("a\nd\n"); DiffEntry ent = DiffEntry.delete("FOO", adId); @@ -154,6 +163,7 @@ public class DiffFormatterTest extends RepositoryTestCase { assertEquals(Edit.Type.DELETE, e.getType()); } + @Test public void testCreateFileHeader_Modify() throws Exception { ObjectId adId = blob("a\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()); } + @Test public void testCreateFileHeader_Binary() throws Exception { ObjectId adId = blob("a\nd\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()); } + @Test public void testCreateFileHeader_GitLink() throws Exception { ObjectId aId = blob("a\n"); ObjectId bId = blob("b\n"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java index 5c2c3d0a2..30f32098a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java @@ -43,11 +43,17 @@ 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 junit.framework.TestCase; +import org.junit.Test; -public class EditListTest extends TestCase { +public class EditListTest { + @Test public void testEmpty() { final EditList l = new EditList(); assertEquals(0, l.size()); @@ -60,6 +66,7 @@ public class EditListTest extends TestCase { assertEquals(l.hashCode(), new EditList().hashCode()); } + @Test public void testAddOne() { final Edit e = new Edit(1, 2, 1, 1); final EditList l = new EditList(); @@ -79,6 +86,7 @@ public class EditListTest extends TestCase { assertEquals(l.hashCode(), l2.hashCode()); } + @Test public void testAddTwo() { final Edit e1 = new Edit(1, 2, 1, 1); final Edit e2 = new Edit(8, 8, 8, 12); @@ -104,6 +112,7 @@ public class EditListTest extends TestCase { assertEquals(l.hashCode(), l2.hashCode()); } + @Test public void testSet() { final Edit e1 = new Edit(1, 2, 1, 1); final Edit e2 = new Edit(3, 4, 3, 3); @@ -114,6 +123,7 @@ public class EditListTest extends TestCase { assertSame(e2, l.get(0)); } + @Test public void testRemove() { final Edit e1 = new Edit(1, 2, 1, 1); final Edit e2 = new Edit(8, 8, 8, 12); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java index 598e6d2b6..a9cb2fbdd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java @@ -44,9 +44,15 @@ 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() { final Edit e = new Edit(1, 2, 3, 4); assertEquals(1, e.getBeginA()); @@ -55,6 +61,7 @@ public class EditTest extends TestCase { assertEquals(4, e.getEndB()); } + @Test public void testCreateEmpty() { final Edit e = new Edit(1, 3); assertEquals(1, e.getBeginA()); @@ -65,6 +72,7 @@ public class EditTest extends TestCase { assertSame(Edit.Type.EMPTY, e.getType()); } + @Test public void testSwap() { final Edit e = new Edit(1, 2, 3, 4); e.swap(); @@ -74,6 +82,7 @@ public class EditTest extends TestCase { assertEquals(2, e.getEndB()); } + @Test public void testType_Insert() { final Edit e = new Edit(1, 1, 1, 2); assertSame(Edit.Type.INSERT, e.getType()); @@ -82,6 +91,7 @@ public class EditTest extends TestCase { assertEquals(1, e.getLengthB()); } + @Test public void testType_Delete() { final Edit e = new Edit(1, 2, 1, 1); assertSame(Edit.Type.DELETE, e.getType()); @@ -90,6 +100,7 @@ public class EditTest extends TestCase { assertEquals(0, e.getLengthB()); } + @Test public void testType_Replace() { final Edit e = new Edit(1, 2, 1, 4); assertSame(Edit.Type.REPLACE, e.getType()); @@ -98,6 +109,7 @@ public class EditTest extends TestCase { assertEquals(3, e.getLengthB()); } + @Test public void testType_Empty() { final Edit e = new Edit(1, 1, 2, 2); assertSame(Edit.Type.EMPTY, e.getType()); @@ -107,11 +119,13 @@ public class EditTest extends TestCase { assertEquals(0, e.getLengthB()); } + @Test public void testToString() { final Edit e = new Edit(1, 2, 1, 4); assertEquals("REPLACE(1-2,1-4)", e.toString()); } + @Test public void testEquals1() { final Edit e1 = 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("")); } + @Test public void testNotEquals1() { assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(0, 2, 3, 4))); } + @Test public void testNotEquals2() { assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 0, 3, 4))); } + @Test public void testNotEquals3() { assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 0, 4))); } + @Test public void testNotEquals4() { assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 3, 0))); } + @Test public void testExtendA() { 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); } + @Test public void testExtendB() { 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); } + @Test public void testBeforeAfterCuts() { final Edit whole = new Edit(1, 8, 2, 9); final Edit mid = new Edit(4, 5, 3, 6); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java index 85740e1f8..886ffcfd2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.diff; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + public class HistogramDiffTest extends AbstractDiffTestCase { @Override @@ -52,6 +56,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase { return hd; } + @Test public void testEdit_NoUniqueMiddleSide_FlipBlocks() { EditList r = diff(t("aRRSSz"), t("aSSRRz")); 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 } + @Test public void testEdit_NoUniqueMiddleSide_Insert2() { EditList r = diff(t("aRSz"), t("aRRSSz")); assertEquals(1, r.size()); assertEquals(new Edit(2, 2, 2, 4), r.get(0)); } + @Test public void testEdit_NoUniqueMiddleSide_FlipAndExpand() { EditList r = diff(t("aRSz"), t("aSSRRz")); 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" } + @Test public void testEdit_LcsContainsUnique() { EditList r = diff(t("nqnjrnjsnm"), t("AnqnjrnjsnjTnmZ")); 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()); } + @Test public void testExceedsChainLength_DuringScanOfA() { HistogramDiff hd = new HistogramDiff(); hd.setFallbackAlgorithm(null); @@ -102,6 +111,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase { assertEquals(new Edit(0, 4, 0, 4), r.get(0)); } + @Test public void testExceedsChainLength_DuringScanOfB() { HistogramDiff hd = new HistogramDiff(); hd.setFallbackAlgorithm(null); @@ -112,6 +122,7 @@ public class HistogramDiffTest extends AbstractDiffTestCase { assertEquals(new Edit(0, 4, 0, 4), r.get(0)); } + @Test public void testFallbackToMyersDiff() { HistogramDiff hd = new HistogramDiff(); hd.setMaxChainLength(4); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespaceTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespaceTest.java index f97763f5c..a8026ccbf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespaceTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespaceTest.java @@ -44,13 +44,17 @@ 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; + @Test public void testEqualsWithoutWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\nfoo-b\nfoo\n")); @@ -73,6 +77,7 @@ public class RawTextIgnoreAllWhitespaceTest extends TestCase { assertFalse(cmp.equals(b, 2, a, 2)); } + @Test public void testEqualsWithWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\n \n a b c\na \n")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespaceTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespaceTest.java index e510bddc6..59a84890e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespaceTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespaceTest.java @@ -44,13 +44,17 @@ 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; + @Test public void testEqualsWithoutWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\nfoo-b\nfoo\n")); @@ -73,6 +77,7 @@ public class RawTextIgnoreLeadingWhitespaceTest extends TestCase { assertFalse(cmp.equals(b, 2, a, 2)); } + @Test public void testEqualsWithWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\n \n a b c\n a\nb \n")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespaceTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespaceTest.java index de7e5bf4d..1154be8c7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespaceTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespaceTest.java @@ -44,13 +44,17 @@ 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; + @Test public void testEqualsWithoutWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\nfoo-b\nfoo\n")); @@ -73,6 +77,7 @@ public class RawTextIgnoreTrailingWhitespaceTest extends TestCase { assertFalse(cmp.equals(b, 2, a, 2)); } + @Test public void testEqualsWithWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\n \n a b c\na \n b\n")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java index c601130be..939cb4387 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java @@ -44,13 +44,17 @@ 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; + @Test public void testEqualsWithoutWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\nfoo-b\nfoo\n")); @@ -73,6 +77,7 @@ public class RawTextIgnoreWhitespaceChangeTest extends TestCase { assertFalse(cmp.equals(b, 2, a, 2)); } + @Test public void testEqualsWithWhitespace() { final RawText a = new RawText(Constants .encodeASCII("foo-a\n \n a b c\na \n foo\na b c\n")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java index e18d1c4eb..7e6e1354d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java @@ -44,21 +44,26 @@ 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.IOException; import java.io.UnsupportedEncodingException; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.RawParseUtils; +import org.junit.Test; -public class RawTextTest extends TestCase { +public class RawTextTest { + @Test public void testEmpty() { final RawText r = new RawText(new byte[0]); assertEquals(0, r.size()); } + @Test public void testEquals() { final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\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)); } + @Test public void testWriteLine1() throws IOException { final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b\n")); final ByteArrayOutputStream o = new ByteArrayOutputStream(); @@ -84,6 +90,7 @@ public class RawTextTest extends TestCase { assertEquals("foo-a", RawParseUtils.decode(r)); } + @Test public void testWriteLine2() throws IOException { final RawText a = new RawText(Constants.encodeASCII("foo-a\nfoo-b")); final ByteArrayOutputStream o = new ByteArrayOutputStream(); @@ -92,6 +99,7 @@ public class RawTextTest extends TestCase { assertEquals("foo-b", RawParseUtils.decode(r)); } + @Test public void testWriteLine3() throws IOException { final RawText a = new RawText(Constants.encodeASCII("a\n\nb\n")); final ByteArrayOutputStream o = new ByteArrayOutputStream(); @@ -100,6 +108,7 @@ public class RawTextTest extends TestCase { assertEquals("", RawParseUtils.decode(r)); } + @Test public void testComparatorReduceCommonStartEnd() throws UnsupportedEncodingException { final RawTextComparator c = RawTextComparator.DEFAULT; @@ -134,6 +143,7 @@ public class RawTextTest extends TestCase { assertEquals(new Edit(2, 3, 2, 3), e); } + @Test public void testComparatorReduceCommonStartEnd_EmptyLine() throws UnsupportedEncodingException { RawText a; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java index 862fc0a59..70e45444a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java @@ -43,6 +43,11 @@ 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 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.ObjectId; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Before; +import org.junit.Test; public class RenameDetectorTest extends RepositoryTestCase { private static final String PATH_A = "src/A"; @@ -63,12 +70,14 @@ public class RenameDetectorTest extends RepositoryTestCase { private TestRepository testDb; @Override + @Before public void setUp() throws Exception { super.setUp(); testDb = new TestRepository(db); rd = new RenameDetector(db); } + @Test public void testExactRename_OneRename() throws Exception { ObjectId foo = blob("foo"); @@ -83,6 +92,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(b, a, 100, entries.get(0)); } + @Test public void testExactRename_DifferentObjects() throws Exception { ObjectId foo = blob("foo"); ObjectId bar = blob("bar"); @@ -102,6 +112,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(q, entries.get(2)); } + @Test public void testExactRename_OneRenameOneModify() throws Exception { ObjectId foo = blob("foo"); ObjectId bar = blob("bar"); @@ -122,6 +133,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(c, entries.get(1)); } + @Test public void testExactRename_ManyRenames() throws Exception { ObjectId foo = blob("foo"); ObjectId bar = blob("bar"); @@ -143,6 +155,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(d, c, 100, entries.get(1)); } + @Test public void testExactRename_MultipleIdenticalDeletes() throws Exception { ObjectId foo = blob("foo"); @@ -165,6 +178,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(a, d, 100, entries.get(2)); } + @Test public void testExactRename_PathBreaksTie() throws Exception { ObjectId foo = blob("foo"); @@ -189,6 +203,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertCopy(d, e, 100, entries.get(2)); } + @Test public void testExactRename_OneDeleteManyAdds() throws Exception { ObjectId foo = blob("foo"); @@ -210,6 +225,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertCopy(d, b, 100, entries.get(2)); } + @Test public void testInexactRename_OnePair() throws Exception { ObjectId aId = blob("foo\nbar\nbaz\nblarg\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)); } + @Test public void testInexactRename_OneRenameTwoUnrelatedFiles() throws Exception { ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); @@ -248,6 +265,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(d, entries.get(2)); } + @Test public void testInexactRename_LastByteDifferent() throws Exception { ObjectId aId = blob("foo\nbar\na"); ObjectId bId = blob("foo\nbar\nb"); @@ -263,6 +281,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(b, a, 88, entries.get(0)); } + @Test public void testInexactRename_NewlinesOnly() throws Exception { ObjectId aId = blob("\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)); } + @Test public void testInexactRename_SameContentMultipleTimes() throws Exception { ObjectId aId = blob("a\na\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)); } + @Test public void testInexactRenames_OnePair2() throws Exception { ObjectId aId = blob("ab\nab\nab\nac\nad\nae\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)); } + @Test public void testNoRenames_SingleByteFiles() throws Exception { ObjectId aId = blob("a"); ObjectId bId = blob("b"); @@ -325,6 +347,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(b, entries.get(1)); } + @Test public void testNoRenames_EmptyFile1() throws Exception { ObjectId aId = blob(""); DiffEntry a = DiffEntry.add(PATH_A, aId); @@ -336,6 +359,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(a, entries.get(0)); } + @Test public void testNoRenames_EmptyFile2() throws Exception { ObjectId aId = blob(""); ObjectId bId = blob("blah"); @@ -352,6 +376,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(b, entries.get(1)); } + @Test public void testNoRenames_SymlinkAndFile() throws Exception { ObjectId aId = blob("src/dest"); @@ -368,6 +393,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(b, entries.get(1)); } + @Test public void testNoRenames_GitlinkAndFile() throws Exception { ObjectId aId = blob("src/dest"); @@ -384,6 +410,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(b, entries.get(1)); } + @Test public void testNoRenames_SymlinkAndFileSamePath() throws Exception { ObjectId aId = blob("src/dest"); @@ -401,6 +428,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(b, entries.get(1)); } + @Test public void testBreakModify_BreakAll() throws Exception { ObjectId aId = blob("foo"); ObjectId bId = blob("bar"); @@ -422,6 +450,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(DiffEntry.breakModify(m).get(0), a, 100, entries.get(1)); } + @Test public void testBreakModify_BreakNone() throws Exception { ObjectId aId = blob("foo"); ObjectId bId = blob("bar"); @@ -443,6 +472,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(a, entries.get(1)); } + @Test public void testBreakModify_BreakBelowScore() throws Exception { ObjectId aId = blob("foo"); ObjectId bId = blob("bar"); @@ -464,6 +494,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(DiffEntry.breakModify(m).get(0), a, 100, entries.get(1)); } + @Test public void testBreakModify_DontBreakAboveScore() throws Exception { ObjectId aId = blob("blah\nblah\nfoo"); ObjectId bId = blob("blah\nblah\nbar"); @@ -485,6 +516,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertSame(a, entries.get(1)); } + @Test public void testBreakModify_RejoinIfUnpaired() throws Exception { ObjectId aId = blob("foo"); ObjectId bId = blob("bar"); @@ -511,6 +543,7 @@ public class RenameDetectorTest extends RepositoryTestCase { assertEquals(0, modify.score); } + @Test public void testSetRenameScore_IllegalArgs() throws Exception { try { rd.setRenameScore(-1); @@ -527,6 +560,7 @@ public class RenameDetectorTest extends RepositoryTestCase { } } + @Test public void testRenameLimit() throws Exception { ObjectId aId = blob("foo\nbar\nbaz\nblarg\n"); ObjectId bId = blob("foo\nbar\nbaz\nblah\n"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java index 1da5828b3..95423609a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java @@ -43,15 +43,18 @@ package org.eclipse.jgit.diff; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import java.io.IOException; -import junit.framework.TestCase; - import org.eclipse.jgit.diff.SimilarityIndex.TableFullException; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class SimilarityIndexTest extends TestCase { +public class SimilarityIndexTest { + @Test public void testIndexingSmallObject() throws TableFullException { SimilarityIndex si = hash("" // + "A\n" // @@ -71,6 +74,7 @@ public class SimilarityIndexTest extends TestCase { assertEquals(2, si.count(si.findIndex(key_D))); } + @Test public void testIndexingLargeObject() throws IOException, TableFullException { byte[] in = ("" // @@ -83,6 +87,7 @@ public class SimilarityIndexTest extends TestCase { assertEquals(2, si.size()); } + @Test public void testCommonScore_SameFiles() throws TableFullException { String text = "" // + "A\n" // @@ -98,6 +103,7 @@ public class SimilarityIndexTest extends TestCase { assertEquals(100, dst.score(src, 100)); } + @Test public void testCommonScore_EmptyFiles() throws TableFullException { SimilarityIndex src = hash(""); SimilarityIndex dst = hash(""); @@ -105,6 +111,7 @@ public class SimilarityIndexTest extends TestCase { assertEquals(0, dst.common(src)); } + @Test public void testCommonScore_TotallyDifferentFiles() throws TableFullException { SimilarityIndex src = hash("A\n"); @@ -113,6 +120,7 @@ public class SimilarityIndexTest extends TestCase { assertEquals(0, dst.common(src)); } + @Test public void testCommonScore_SimiliarBy75() throws TableFullException { SimilarityIndex src = hash("A\nB\nC\nD\n"); SimilarityIndex dst = hash("A\nB\nC\nQ\n"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java index b6e4e42c7..487f04329 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java @@ -43,13 +43,20 @@ 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 org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class DirCacheBasicTest extends RepositoryTestCase { + @Test public void testReadMissing_RealIndex() throws Exception { final File idx = new File(db.getDirectory(), "index"); assertFalse(idx.exists()); @@ -59,6 +66,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertEquals(0, dc.getEntryCount()); } + @Test public void testReadMissing_TempIndex() throws Exception { final File idx = new File(db.getDirectory(), "tmp_index"); assertFalse(idx.exists()); @@ -68,6 +76,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertEquals(0, dc.getEntryCount()); } + @Test public void testLockMissing_RealIndex() throws Exception { final File idx = new File(db.getDirectory(), "index"); final File lck = new File(db.getDirectory(), "index.lock"); @@ -85,6 +94,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertFalse(lck.exists()); } + @Test public void testLockMissing_TempIndex() throws Exception { final File idx = new File(db.getDirectory(), "tmp_index"); final File lck = new File(db.getDirectory(), "tmp_index.lock"); @@ -102,6 +112,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertFalse(lck.exists()); } + @Test public void testWriteEmptyUnlock_RealIndex() throws Exception { final File idx = new File(db.getDirectory(), "index"); final File lck = new File(db.getDirectory(), "index.lock"); @@ -118,6 +129,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertFalse(lck.exists()); } + @Test public void testWriteEmptyCommit_RealIndex() throws Exception { final File idx = new File(db.getDirectory(), "index"); final File lck = new File(db.getDirectory(), "index.lock"); @@ -135,6 +147,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertEquals(12 + 20, idx.length()); } + @Test public void testWriteEmptyReadEmpty_RealIndex() throws Exception { final File idx = new File(db.getDirectory(), "index"); 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 { final File idx = new File(db.getDirectory(), "index"); final File lck = new File(db.getDirectory(), "index.lock"); @@ -172,6 +186,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { } } + @Test public void testBuildThenClear() throws Exception { final DirCache dc = db.readDirCache(); @@ -194,6 +209,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertFalse(dc.hasUnmergedPaths()); } + @Test public void testDetectUnmergedPaths() throws Exception { final DirCache dc = db.readDirCache(); final DirCacheEntry[] ents = new DirCacheEntry[3]; @@ -212,6 +228,7 @@ public class DirCacheBasicTest extends RepositoryTestCase { assertTrue(dc.hasUnmergedPaths()); } + @Test public void testFindOnEmpty() throws Exception { final DirCache dc = DirCache.newInCore(); final byte[] path = Constants.encode("a"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java index 10dcd2af8..84a223680 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java @@ -43,14 +43,22 @@ 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 org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; +import org.junit.Test; public class DirCacheBuilderIteratorTest extends RepositoryTestCase { + @Test public void testPathFilterGroup_DoesNotSkipTail() throws Exception { final DirCache dc = db.readDirCache(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java index 81ffab914..1c1cb0fcb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java @@ -43,13 +43,22 @@ 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 org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class DirCacheBuilderTest extends RepositoryTestCase { + @Test public void testBuildEmpty() throws Exception { { final DirCache dc = db.lockDirCache(); @@ -65,6 +74,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { } } + @Test public void testBuildRejectsUnsetFileMode() throws Exception { final DirCache dc = DirCache.newInCore(); final DirCacheBuilder b = dc.builder(); @@ -79,6 +89,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { } } + @Test public void testBuildOneFile_FinishWriteCommit() throws Exception { final String path = "a-file-path"; final FileMode mode = FileMode.REGULAR_FILE; @@ -128,6 +139,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { } } + @Test public void testBuildOneFile_Commit() throws Exception { final String path = "a-file-path"; final FileMode mode = FileMode.REGULAR_FILE; @@ -175,6 +187,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { } } + @Test public void testFindSingleFile() throws Exception { final String path = "a-file-path"; final DirCache dc = db.readDirCache(); @@ -201,6 +214,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { assertSame(entOrig, dc.getEntry(path)); } + @Test public void testAdd_InGitSortOrder() throws Exception { final DirCache dc = db.readDirCache(); @@ -225,6 +239,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { } } + @Test public void testAdd_ReverseGitSortOrder() throws Exception { final DirCache dc = db.readDirCache(); @@ -249,6 +264,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase { } } + @Test public void testBuilderClear() throws Exception { final DirCache dc = db.readDirCache(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java index 00b94b38c..634b43a2e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java @@ -43,6 +43,11 @@ 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.ByteArrayOutputStream; import java.io.File; @@ -55,6 +60,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.FileMode; 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.util.FS; import org.eclipse.jgit.util.IO; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.Test; public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { private final File index = pathOf("gitgit.index"); + @Test public void testReadIndex_LsFiles() throws Exception { final Map ls = readLsFiles(); final DirCache dc = new DirCache(index, FS.DETECTED); @@ -80,6 +87,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { } } + @Test public void testTreeWalk_LsFiles() throws Exception { final Repository db = createBareRepository(); final Map ls = readLsFiles(); @@ -104,6 +112,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { } } + @Test public void testUnsupportedOptionalExtension() throws Exception { final DirCache dc = new DirCache(pathOf("gitgit.index.ZZZZ"), FS.DETECTED); @@ -112,6 +121,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { assertEquals("A", dc.getEntry(0).getPathString()); } + @Test public void testUnsupportedRequiredExtension() throws Exception { final DirCache dc = new DirCache(pathOf("gitgit.index.aaaa"), FS.DETECTED); @@ -124,6 +134,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { } } + @Test public void testCorruptChecksumAtFooter() throws Exception { final DirCache dc = new DirCache(pathOf("gitgit.index.badchecksum"), FS.DETECTED); @@ -146,6 +157,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { assertEquals(c.stage, j.getStage()); } + @Test public void testReadIndex_DirCacheTree() throws Exception { final Map cList = readLsFiles(); final Map cTree = readLsTree(); @@ -181,6 +193,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { } } + @Test public void testReadWriteV3() throws Exception { final File file = pathOf("gitgit.index.v3"); final DirCache dc = new DirCache(file, FS.DETECTED); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java index 446fd7060..7c90f25b5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java @@ -43,12 +43,18 @@ 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.FileMode; +import org.junit.Test; -public class DirCacheEntryTest extends TestCase { +public class DirCacheEntryTest { + @Test public void testIsValidPath() { assertTrue(isValidPath("a")); assertTrue(isValidPath("a/b")); @@ -67,6 +73,7 @@ public class DirCacheEntryTest extends TestCase { return DirCacheEntry.isValidPath(Constants.encode(path)); } + @Test public void testCreate_ByStringPath() { assertEquals("a", new DirCacheEntry("a").getPathString()); assertEquals("a/b", new DirCacheEntry("a/b").getPathString()); @@ -79,6 +86,7 @@ public class DirCacheEntryTest extends TestCase { } } + @Test public void testCreate_ByStringPathAndStage() { DirCacheEntry e; @@ -120,6 +128,7 @@ public class DirCacheEntryTest extends TestCase { } } + @Test public void testSetFileMode() { final DirCacheEntry e = new DirCacheEntry("a"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java index 5533fe358..e861bed17 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java @@ -43,10 +43,16 @@ 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.RepositoryTestCase; +import org.junit.Test; public class DirCacheFindTest extends RepositoryTestCase { + @Test public void testEntriesWithin() throws Exception { final DirCache dc = db.readDirCache(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java index bc84753f9..752441322 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java @@ -43,17 +43,25 @@ 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.util.Collections; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.util.FS; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.Test; public class DirCacheIteratorTest extends RepositoryTestCase { + @Test public void testEmptyTree_NoTreeWalk() throws Exception { final DirCache dc = DirCache.newInCore(); assertEquals(0, dc.getEntryCount()); @@ -62,6 +70,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertTrue(i.eof()); } + @Test public void testEmptyTree_WithTreeWalk() throws Exception { final DirCache dc = DirCache.newInCore(); assertEquals(0, dc.getEntryCount()); @@ -71,6 +80,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertFalse(tw.next()); } + @Test public void testNoSubtree_NoTreeWalk() throws Exception { final DirCache dc = DirCache.newInCore(); @@ -96,6 +106,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertEquals(paths.length, pathIdx); } + @Test public void testNoSubtree_WithTreeWalk() throws Exception { final DirCache dc = DirCache.newInCore(); @@ -128,6 +139,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertEquals(paths.length, pathIdx); } + @Test public void testSingleSubtree_NoRecursion() throws Exception { final DirCache dc = DirCache.newInCore(); @@ -171,6 +183,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertEquals(expPaths.length, pathIdx); } + @Test public void testSingleSubtree_Recursive() throws Exception { final DirCache dc = DirCache.newInCore(); @@ -205,6 +218,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertEquals(paths.length, pathIdx); } + @Test public void testTwoLevelSubtree_Recursive() throws Exception { final DirCache dc = DirCache.newInCore(); @@ -238,6 +252,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { assertEquals(paths.length, pathIdx); } + @Test public void testTwoLevelSubtree_FilterPath() throws Exception { final DirCache dc = DirCache.newInCore(); @@ -273,6 +288,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase { } } + @Test public void testRemovedSubtree() throws Exception { final File path = JGitTestUtil .getTestResourceFile("dircache.testRemovedSubtree"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java index a6d7e39eb..c38e601a3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java @@ -43,29 +43,40 @@ 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 org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class DirCacheLargePathTest extends RepositoryTestCase { + @Test public void testPath_4090() throws Exception { testLongPath(4090); } + @Test public void testPath_4094() throws Exception { testLongPath(4094); } + @Test public void testPath_4095() throws Exception { testLongPath(4095); } + @Test public void testPath_4096() throws Exception { testLongPath(4096); } + @Test public void testPath_16384() throws Exception { testLongPath(16384); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java index dfca2fb29..99291dd7c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java @@ -43,18 +43,28 @@ 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 org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class DirCacheTreeTest extends RepositoryTestCase { + @Test public void testEmptyCache_NoCacheTree() throws Exception { final DirCache dc = db.readDirCache(); assertNull(dc.getCacheTree(false)); } + @Test public void testEmptyCache_CreateEmptyCacheTree() throws Exception { final DirCache dc = db.readDirCache(); final DirCacheTree tree = dc.getCacheTree(true); @@ -68,6 +78,7 @@ public class DirCacheTreeTest extends RepositoryTestCase { assertFalse(tree.isValid()); } + @Test public void testEmptyCache_Clear_NoCacheTree() throws Exception { final DirCache dc = db.readDirCache(); final DirCacheTree tree = dc.getCacheTree(true); @@ -77,6 +88,7 @@ public class DirCacheTreeTest extends RepositoryTestCase { assertNotSame(tree, dc.getCacheTree(true)); } + @Test public void testSingleSubtree() throws Exception { final DirCache dc = db.readDirCache(); @@ -114,6 +126,7 @@ public class DirCacheTreeTest extends RepositoryTestCase { assertFalse(aTree.isValid()); } + @Test public void testTwoLevelSubtree() throws Exception { final DirCache dc = db.readDirCache(); @@ -171,6 +184,7 @@ public class DirCacheTreeTest extends RepositoryTestCase { * @throws CorruptObjectException * @throws IOException */ + @Test public void testWriteReadTree() throws CorruptObjectException, IOException { final DirCache dc = db.lockDirCache(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java index c6bfb19fc..6a93e714c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java @@ -42,10 +42,16 @@ */ 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.storage.file.FileBasedConfig; +import org.junit.Test; public class ConfigChangeEventTest extends RepositoryTestCase { + @Test public void testFileRepository_ChangeEventsOnlyOnSave() throws Exception { final ConfigChangedEvent[] events = new ConfigChangedEvent[1]; db.getListenerList().addConfigChangedListener( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java index 752a1e2f6..66943c242 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java @@ -44,12 +44,14 @@ package org.eclipse.jgit.fnmatch; -import org.eclipse.jgit.errors.InvalidPatternException; -import org.eclipse.jgit.fnmatch.FileNameMatcher; +import static org.junit.Assert.assertEquals; +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, final boolean matchExpected, final boolean appendCanMatchExpected) @@ -71,178 +73,222 @@ public class FileNameMatcherTest extends TestCase { assertEquals(appendCanMatchExpected, matcher.canAppendMatch()); } + @Test public void testVerySimplePatternCase0() throws Exception { assertMatch("", "", true, false); } + @Test public void testVerySimplePatternCase1() throws Exception { assertMatch("ab", "a", false, true); } + @Test public void testVerySimplePatternCase2() throws Exception { assertMatch("ab", "ab", true, false); } + @Test public void testVerySimplePatternCase3() throws Exception { assertMatch("ab", "ac", false, false); } + @Test public void testVerySimplePatternCase4() throws Exception { assertMatch("ab", "abc", false, false); } + @Test public void testVerySimpleWirdcardCase0() throws Exception { assertMatch("?", "a", true, false); } + @Test public void testVerySimpleWildCardCase1() throws Exception { assertMatch("??", "a", false, true); } + @Test public void testVerySimpleWildCardCase2() throws Exception { assertMatch("??", "ab", true, false); } + @Test public void testVerySimpleWildCardCase3() throws Exception { assertMatch("??", "abc", false, false); } + @Test public void testVerySimpleStarCase0() throws Exception { assertMatch("*", "", true, true); } + @Test public void testVerySimpleStarCase1() throws Exception { assertMatch("*", "a", true, true); } + @Test public void testVerySimpleStarCase2() throws Exception { assertMatch("*", "ab", true, true); } + @Test public void testSimpleStarCase0() throws Exception { assertMatch("a*b", "a", false, true); } + @Test public void testSimpleStarCase1() throws Exception { assertMatch("a*c", "ac", true, true); } + @Test public void testSimpleStarCase2() throws Exception { assertMatch("a*c", "ab", false, true); } + @Test public void testSimpleStarCase3() throws Exception { assertMatch("a*c", "abc", true, true); } + @Test public void testManySolutionsCase0() throws Exception { assertMatch("a*a*a", "aaa", true, true); } + @Test public void testManySolutionsCase1() throws Exception { assertMatch("a*a*a", "aaaa", true, true); } + @Test public void testManySolutionsCase2() throws Exception { assertMatch("a*a*a", "ababa", true, true); } + @Test public void testManySolutionsCase3() throws Exception { assertMatch("a*a*a", "aaaaaaaa", true, true); } + @Test public void testManySolutionsCase4() throws Exception { assertMatch("a*a*a", "aaaaaaab", false, true); } + @Test public void testVerySimpleGroupCase0() throws Exception { assertMatch("[ab]", "a", true, false); } + @Test public void testVerySimpleGroupCase1() throws Exception { assertMatch("[ab]", "b", true, false); } + @Test public void testVerySimpleGroupCase2() throws Exception { assertMatch("[ab]", "ab", false, false); } + @Test public void testVerySimpleGroupRangeCase0() throws Exception { assertMatch("[b-d]", "a", false, false); } + @Test public void testVerySimpleGroupRangeCase1() throws Exception { assertMatch("[b-d]", "b", true, false); } + @Test public void testVerySimpleGroupRangeCase2() throws Exception { assertMatch("[b-d]", "c", true, false); } + @Test public void testVerySimpleGroupRangeCase3() throws Exception { assertMatch("[b-d]", "d", true, false); } + @Test public void testVerySimpleGroupRangeCase4() throws Exception { assertMatch("[b-d]", "e", false, false); } + @Test public void testVerySimpleGroupRangeCase5() throws Exception { assertMatch("[b-d]", "-", false, false); } + @Test public void testTwoGroupsCase0() throws Exception { assertMatch("[b-d][ab]", "bb", true, false); } + @Test public void testTwoGroupsCase1() throws Exception { assertMatch("[b-d][ab]", "ca", true, false); } + @Test public void testTwoGroupsCase2() throws Exception { assertMatch("[b-d][ab]", "fa", false, false); } + @Test public void testTwoGroupsCase3() throws Exception { assertMatch("[b-d][ab]", "bc", false, false); } + @Test public void testTwoRangesInOneGroupCase0() throws Exception { assertMatch("[b-ce-e]", "a", false, false); } + @Test public void testTwoRangesInOneGroupCase1() throws Exception { assertMatch("[b-ce-e]", "b", true, false); } + @Test public void testTwoRangesInOneGroupCase2() throws Exception { assertMatch("[b-ce-e]", "c", true, false); } + @Test public void testTwoRangesInOneGroupCase3() throws Exception { assertMatch("[b-ce-e]", "d", false, false); } + @Test public void testTwoRangesInOneGroupCase4() throws Exception { assertMatch("[b-ce-e]", "e", true, false); } + @Test public void testTwoRangesInOneGroupCase5() throws Exception { assertMatch("[b-ce-e]", "f", false, false); } + @Test public void testIncompleteRangesInOneGroupCase0() throws Exception { assertMatch("a[b-]", "ab", true, false); } + @Test public void testIncompleteRangesInOneGroupCase1() throws Exception { assertMatch("a[b-]", "ac", false, false); } + @Test public void testIncompleteRangesInOneGroupCase2() throws Exception { assertMatch("a[b-]", "a-", true, false); } + @Test public void testCombinedRangesInOneGroupCase0() throws Exception { assertMatch("[a-c-e]", "b", true, false); } @@ -254,383 +300,476 @@ public class FileNameMatcherTest extends TestCase { * @throws Exception * for some reasons */ + @Test public void testCombinedRangesInOneGroupCase1() throws Exception { assertMatch("[a-c-e]", "d", false, false); } + @Test public void testCombinedRangesInOneGroupCase2() throws Exception { assertMatch("[a-c-e]", "e", true, false); } + @Test public void testInversedGroupCase0() throws Exception { assertMatch("[!b-c]", "a", true, false); } + @Test public void testInversedGroupCase1() throws Exception { assertMatch("[!b-c]", "b", false, false); } + @Test public void testInversedGroupCase2() throws Exception { assertMatch("[!b-c]", "c", false, false); } + @Test public void testInversedGroupCase3() throws Exception { assertMatch("[!b-c]", "d", true, false); } + @Test public void testAlphaGroupCase0() throws Exception { assertMatch("[[:alpha:]]", "d", true, false); } + @Test public void testAlphaGroupCase1() throws Exception { assertMatch("[[:alpha:]]", ":", false, false); } + @Test public void testAlphaGroupCase2() throws Exception { // \u00f6 = 'o' with dots on it assertMatch("[[:alpha:]]", "\u00f6", true, false); } + @Test public void test2AlphaGroupsCase0() throws Exception { // \u00f6 = 'o' with dots on it assertMatch("[[:alpha:]][[:alpha:]]", "a\u00f6", true, false); assertMatch("[[:alpha:]][[:alpha:]]", "a1", false, false); } + @Test public void testAlnumGroupCase0() throws Exception { assertMatch("[[:alnum:]]", "a", true, false); } + @Test public void testAlnumGroupCase1() throws Exception { assertMatch("[[:alnum:]]", "1", true, false); } + @Test public void testAlnumGroupCase2() throws Exception { assertMatch("[[:alnum:]]", ":", false, false); } + @Test public void testBlankGroupCase0() throws Exception { assertMatch("[[:blank:]]", " ", true, false); } + @Test public void testBlankGroupCase1() throws Exception { assertMatch("[[:blank:]]", "\t", true, false); } + @Test public void testBlankGroupCase2() throws Exception { assertMatch("[[:blank:]]", "\r", false, false); } + @Test public void testBlankGroupCase3() throws Exception { assertMatch("[[:blank:]]", "\n", false, false); } + @Test public void testBlankGroupCase4() throws Exception { assertMatch("[[:blank:]]", "a", false, false); } + @Test public void testCntrlGroupCase0() throws Exception { assertMatch("[[:cntrl:]]", "a", false, false); } + @Test public void testCntrlGroupCase1() throws Exception { assertMatch("[[:cntrl:]]", String.valueOf((char) 7), true, false); } + @Test public void testDigitGroupCase0() throws Exception { assertMatch("[[:digit:]]", "0", true, false); } + @Test public void testDigitGroupCase1() throws Exception { assertMatch("[[:digit:]]", "5", true, false); } + @Test public void testDigitGroupCase2() throws Exception { assertMatch("[[:digit:]]", "9", true, false); } + @Test public void testDigitGroupCase3() throws Exception { // \u06f9 = EXTENDED ARABIC-INDIC DIGIT NINE assertMatch("[[:digit:]]", "\u06f9", true, false); } + @Test public void testDigitGroupCase4() throws Exception { assertMatch("[[:digit:]]", "a", false, false); } + @Test public void testDigitGroupCase5() throws Exception { assertMatch("[[:digit:]]", "]", false, false); } + @Test public void testGraphGroupCase0() throws Exception { assertMatch("[[:graph:]]", "]", true, false); } + @Test public void testGraphGroupCase1() throws Exception { assertMatch("[[:graph:]]", "a", true, false); } + @Test public void testGraphGroupCase2() throws Exception { assertMatch("[[:graph:]]", ".", true, false); } + @Test public void testGraphGroupCase3() throws Exception { assertMatch("[[:graph:]]", "0", true, false); } + @Test public void testGraphGroupCase4() throws Exception { assertMatch("[[:graph:]]", " ", false, false); } + @Test public void testGraphGroupCase5() throws Exception { // \u00f6 = 'o' with dots on it assertMatch("[[:graph:]]", "\u00f6", true, false); } + @Test public void testLowerGroupCase0() throws Exception { assertMatch("[[:lower:]]", "a", true, false); } + @Test public void testLowerGroupCase1() throws Exception { assertMatch("[[:lower:]]", "h", true, false); } + @Test public void testLowerGroupCase2() throws Exception { assertMatch("[[:lower:]]", "A", false, false); } + @Test public void testLowerGroupCase3() throws Exception { assertMatch("[[:lower:]]", "H", false, false); } + @Test public void testLowerGroupCase4() throws Exception { // \u00e4 = small 'a' with dots on it assertMatch("[[:lower:]]", "\u00e4", true, false); } + @Test public void testLowerGroupCase5() throws Exception { assertMatch("[[:lower:]]", ".", false, false); } + @Test public void testPrintGroupCase0() throws Exception { assertMatch("[[:print:]]", "]", true, false); } + @Test public void testPrintGroupCase1() throws Exception { assertMatch("[[:print:]]", "a", true, false); } + @Test public void testPrintGroupCase2() throws Exception { assertMatch("[[:print:]]", ".", true, false); } + @Test public void testPrintGroupCase3() throws Exception { assertMatch("[[:print:]]", "0", true, false); } + @Test public void testPrintGroupCase4() throws Exception { assertMatch("[[:print:]]", " ", true, false); } + @Test public void testPrintGroupCase5() throws Exception { // \u00f6 = 'o' with dots on it assertMatch("[[:print:]]", "\u00f6", true, false); } + @Test public void testPunctGroupCase0() throws Exception { assertMatch("[[:punct:]]", ".", true, false); } + @Test public void testPunctGroupCase1() throws Exception { assertMatch("[[:punct:]]", "@", true, false); } + @Test public void testPunctGroupCase2() throws Exception { assertMatch("[[:punct:]]", " ", false, false); } + @Test public void testPunctGroupCase3() throws Exception { assertMatch("[[:punct:]]", "a", false, false); } + @Test public void testSpaceGroupCase0() throws Exception { assertMatch("[[:space:]]", " ", true, false); } + @Test public void testSpaceGroupCase1() throws Exception { assertMatch("[[:space:]]", "\t", true, false); } + @Test public void testSpaceGroupCase2() throws Exception { assertMatch("[[:space:]]", "\r", true, false); } + @Test public void testSpaceGroupCase3() throws Exception { assertMatch("[[:space:]]", "\n", true, false); } + @Test public void testSpaceGroupCase4() throws Exception { assertMatch("[[:space:]]", "a", false, false); } + @Test public void testUpperGroupCase0() throws Exception { assertMatch("[[:upper:]]", "a", false, false); } + @Test public void testUpperGroupCase1() throws Exception { assertMatch("[[:upper:]]", "h", false, false); } + @Test public void testUpperGroupCase2() throws Exception { assertMatch("[[:upper:]]", "A", true, false); } + @Test public void testUpperGroupCase3() throws Exception { assertMatch("[[:upper:]]", "H", true, false); } + @Test public void testUpperGroupCase4() throws Exception { // \u00c4 = 'A' with dots on it assertMatch("[[:upper:]]", "\u00c4", true, false); } + @Test public void testUpperGroupCase5() throws Exception { assertMatch("[[:upper:]]", ".", false, false); } + @Test public void testXDigitGroupCase0() throws Exception { assertMatch("[[:xdigit:]]", "a", true, false); } + @Test public void testXDigitGroupCase1() throws Exception { assertMatch("[[:xdigit:]]", "d", true, false); } + @Test public void testXDigitGroupCase2() throws Exception { assertMatch("[[:xdigit:]]", "f", true, false); } + @Test public void testXDigitGroupCase3() throws Exception { assertMatch("[[:xdigit:]]", "0", true, false); } + @Test public void testXDigitGroupCase4() throws Exception { assertMatch("[[:xdigit:]]", "5", true, false); } + @Test public void testXDigitGroupCase5() throws Exception { assertMatch("[[:xdigit:]]", "9", true, false); } + @Test public void testXDigitGroupCase6() throws Exception { assertMatch("[[:xdigit:]]", "۹", false, false); } + @Test public void testXDigitGroupCase7() throws Exception { assertMatch("[[:xdigit:]]", ".", false, false); } + @Test public void testWordroupCase0() throws Exception { assertMatch("[[:word:]]", "g", true, false); } + @Test public void testWordroupCase1() throws Exception { // \u00f6 = 'o' with dots on it assertMatch("[[:word:]]", "\u00f6", true, false); } + @Test public void testWordroupCase2() throws Exception { assertMatch("[[:word:]]", "5", true, false); } + @Test public void testWordroupCase3() throws Exception { assertMatch("[[:word:]]", "_", true, false); } + @Test public void testWordroupCase4() throws Exception { assertMatch("[[:word:]]", " ", false, false); } + @Test public void testWordroupCase5() throws Exception { assertMatch("[[:word:]]", ".", false, false); } + @Test public void testMixedGroupCase0() throws Exception { assertMatch("[A[:lower:]C3-5]", "A", true, false); } + @Test public void testMixedGroupCase1() throws Exception { assertMatch("[A[:lower:]C3-5]", "C", true, false); } + @Test public void testMixedGroupCase2() throws Exception { assertMatch("[A[:lower:]C3-5]", "e", true, false); } + @Test public void testMixedGroupCase3() throws Exception { assertMatch("[A[:lower:]C3-5]", "3", true, false); } + @Test public void testMixedGroupCase4() throws Exception { assertMatch("[A[:lower:]C3-5]", "4", true, false); } + @Test public void testMixedGroupCase5() throws Exception { assertMatch("[A[:lower:]C3-5]", "5", true, false); } + @Test public void testMixedGroupCase6() throws Exception { assertMatch("[A[:lower:]C3-5]", "B", false, false); } + @Test public void testMixedGroupCase7() throws Exception { assertMatch("[A[:lower:]C3-5]", "2", false, false); } + @Test public void testMixedGroupCase8() throws Exception { assertMatch("[A[:lower:]C3-5]", "6", false, false); } + @Test public void testMixedGroupCase9() throws Exception { assertMatch("[A[:lower:]C3-5]", ".", false, false); } + @Test public void testSpecialGroupCase0() throws Exception { assertMatch("[[]", "[", true, false); } + @Test public void testSpecialGroupCase1() throws Exception { assertMatch("[]]", "]", true, false); } + @Test public void testSpecialGroupCase2() throws Exception { assertMatch("[]a]", "]", true, false); } + @Test public void testSpecialGroupCase3() throws Exception { assertMatch("[a[]", "[", true, false); } + @Test public void testSpecialGroupCase4() throws Exception { assertMatch("[a[]", "a", true, false); } + @Test public void testSpecialGroupCase5() throws Exception { assertMatch("[!]]", "]", false, false); } + @Test public void testSpecialGroupCase6() throws Exception { assertMatch("[!]]", "x", true, false); } + @Test public void testSpecialGroupCase7() throws Exception { assertMatch("[:]]", ":]", true, false); } + @Test public void testSpecialGroupCase8() throws Exception { assertMatch("[:]]", ":", false, true); } + @Test public void testSpecialGroupCase9() throws Exception { try { assertMatch("[[:]", ":", true, true); @@ -640,6 +779,7 @@ public class FileNameMatcherTest extends TestCase { } } + @Test public void testUnsupportedGroupCase0() throws Exception { try { assertMatch("[[=a=]]", "b", false, false); @@ -649,6 +789,7 @@ public class FileNameMatcherTest extends TestCase { } } + @Test public void testUnsupportedGroupCase1() throws Exception { try { assertMatch("[[.a.]]", "b", false, false); @@ -658,26 +799,32 @@ public class FileNameMatcherTest extends TestCase { } } + @Test public void testFilePathSimpleCase() throws Exception { assertFileNameMatch("a/b", "a/b", '/', true, false); } + @Test public void testFilePathCase0() throws Exception { assertFileNameMatch("a*b", "a/b", '/', false, false); } + @Test public void testFilePathCase1() throws Exception { assertFileNameMatch("a?b", "a/b", '/', false, false); } + @Test public void testFilePathCase2() throws Exception { assertFileNameMatch("a*b", "a\\b", '\\', false, false); } + @Test public void testFilePathCase3() throws Exception { assertFileNameMatch("a?b", "a\\b", '\\', false, false); } + @Test public void testReset() throws Exception { final String pattern = "helloworld"; final FileNameMatcher matcher = new FileNameMatcher(pattern, null); @@ -700,6 +847,7 @@ public class FileNameMatcherTest extends TestCase { assertEquals(false, matcher.canAppendMatch()); } + @Test public void testCreateMatcherForSuffix() throws Exception { final String pattern = "helloworld"; final FileNameMatcher matcher = new FileNameMatcher(pattern, null); @@ -731,6 +879,7 @@ public class FileNameMatcherTest extends TestCase { assertEquals(false, childMatcher.canAppendMatch()); } + @Test public void testCopyConstructor() throws Exception { final String pattern = "helloworld"; final FileNameMatcher matcher = new FileNameMatcher(pattern, null); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java index cacad7555..ce2508a3e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java @@ -42,15 +42,19 @@ */ package org.eclipse.jgit.ignore; -import junit.framework.Assert; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; /** * Tests ignore pattern matches */ -public class IgnoreMatcherTest extends TestCase{ +public class IgnoreMatcherTest { + @Test public void testBasic() { String pattern = "/test.stp"; assertMatched(pattern, "/test.stp"); @@ -59,6 +63,7 @@ public class IgnoreMatcherTest extends TestCase{ assertNotMatched(pattern, "/test.stp"); } + @Test public void testFileNameWildcards() { //Test basic * and ? for any pattern + any character String pattern = "*.st?"; @@ -118,6 +123,7 @@ public class IgnoreMatcherTest extends TestCase{ assertNotMatched(pattern, "/src/new.c"); } + @Test public void testTargetWithoutLeadingSlash() { //Test basic * and ? for any pattern + any character String pattern = "/*.st?"; @@ -177,6 +183,7 @@ public class IgnoreMatcherTest extends TestCase{ assertNotMatched(pattern, "src/new.c"); } + @Test public void testParentDirectoryGitIgnores() { //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"); } + @Test public void testTrailingSlash() { String pattern = "/src/"; assertMatched(pattern, "/src/"); @@ -220,6 +228,7 @@ public class IgnoreMatcherTest extends TestCase{ assertNotMatched(pattern, "/srcA/"); } + @Test public void testNameOnlyMatches() { /* * Name-only matches do not contain any path separators @@ -270,11 +279,13 @@ public class IgnoreMatcherTest extends TestCase{ assertNotMatched(pattern, "/cr3"); } + @Test public void testNegation() { String pattern = "!/test.stp"; assertMatched(pattern, "/test.stp"); } + @Test public void testGetters() { IgnoreRule r = new IgnoreRule("/pattern/"); assertFalse(r.getNameOnly()); @@ -329,7 +340,8 @@ public class IgnoreMatcherTest extends TestCase{ */ public void assertMatched(String pattern, String 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) { boolean value = match(pattern, target); - Assert.assertFalse("Expected no match for: " + pattern + " with: " + target, value); + assertFalse("Expected no match for: " + pattern + " with: " + target, + value); } /** diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java index 867e0603d..51d4c0f94 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java @@ -42,6 +42,10 @@ */ 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.IOException; @@ -52,6 +56,7 @@ import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.util.FileUtils; +import org.junit.Test; /** * Tests ignore node behavior on the local filesystem. @@ -67,6 +72,7 @@ public class IgnoreNodeTest extends RepositoryTestCase { private TreeWalk walk; + @Test public void testRules() throws IOException { writeIgnoreFile(".git/info/exclude", "*~", "/out"); @@ -105,6 +111,7 @@ public class IgnoreNodeTest extends RepositoryTestCase { assertEntry(F, ignored, "src/config/old/lex.out"); } + @Test public void testNegation() throws IOException { writeIgnoreFile(".gitignore", "*.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"); } + @Test public void testSlashOnlyMatchesDirectory() throws IOException { writeIgnoreFile(".gitignore", "out/"); writeTrashFile("out", ""); @@ -138,6 +146,7 @@ public class IgnoreNodeTest extends RepositoryTestCase { assertEntry(F, ignored, "out/foo"); } + @Test public void testWithSlashDoesNotMatchInSubDirectory() throws IOException { writeIgnoreFile(".gitignore", "a/b"); writeTrashFile("a/a", ""); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbreviatedObjectIdTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbreviatedObjectIdTest.java index 9430a20e7..fc53f95b9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbreviatedObjectIdTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/AbbreviatedObjectIdTest.java @@ -43,9 +43,17 @@ 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() { final AbbreviatedObjectId i; i = AbbreviatedObjectId.fromString(new byte[] {}, 0, 0); @@ -55,6 +63,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertEquals("", i.name()); } + @Test public void testEmpty_FromString() { final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(""); assertNotNull(i); @@ -63,6 +72,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertEquals("", i.name()); } + @Test public void testFull_FromByteArray() { final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final byte[] b = Constants.encodeASCII(s); @@ -79,6 +89,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertEquals(f.hashCode(), i.hashCode()); } + @Test public void testFull_FromString() { final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -93,6 +104,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertEquals(f.hashCode(), i.hashCode()); } + @Test public void test1_FromString() { final String s = "7"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -103,6 +115,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test2_FromString() { final String s = "7b"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -113,6 +126,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test3_FromString() { final String s = "7b6"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -123,6 +137,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test4_FromString() { final String s = "7b6e"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -133,6 +148,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test5_FromString() { final String s = "7b6e8"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -143,6 +159,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test6_FromString() { final String s = "7b6e80"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -153,6 +170,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test7_FromString() { final String s = "7b6e806"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -163,6 +181,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test8_FromString() { final String s = "7b6e8067"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -173,6 +192,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test9_FromString() { final String s = "7b6e8067e"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -183,6 +203,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void test17_FromString() { final String s = "7b6e8067ec96acef9"; final AbbreviatedObjectId i = AbbreviatedObjectId.fromString(s); @@ -193,6 +214,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertNull(i.toObjectId()); } + @Test public void testEquals_Short() { final String s = "7b6e8067"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s); @@ -203,6 +225,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertTrue(b.equals(a)); } + @Test public void testEquals_Full() { final String s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s); @@ -213,6 +236,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertTrue(b.equals(a)); } + @Test public void testNotEquals_SameLength() { final String sa = "7b6e8067"; final String sb = "7b6e806e"; @@ -222,6 +246,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(b.equals(a)); } + @Test public void testNotEquals_DiffLength() { final String sa = "7b6e8067abcd"; final String sb = "7b6e8067"; @@ -231,6 +256,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(b.equals(a)); } + @Test public void testPrefixCompare_Full() { final String s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(s1); @@ -249,6 +275,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(i3.startsWith(a)); } + @Test public void testPrefixCompare_1() { final String sa = "7"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); @@ -269,6 +296,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(i3.startsWith(a)); } + @Test public void testPrefixCompare_7() { final String sa = "7b6e806"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); @@ -289,6 +317,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(i3.startsWith(a)); } + @Test public void testPrefixCompare_8() { final String sa = "7b6e8067"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); @@ -309,6 +338,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(i3.startsWith(a)); } + @Test public void testPrefixCompare_9() { final String sa = "7b6e8067e"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); @@ -329,6 +359,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(i3.startsWith(a)); } + @Test public void testPrefixCompare_17() { final String sa = "7b6e8067ec96acef9"; final AbbreviatedObjectId a = AbbreviatedObjectId.fromString(sa); @@ -349,6 +380,7 @@ public class AbbreviatedObjectIdTest extends TestCase { assertFalse(i3.startsWith(a)); } + @Test public void testIsId() { // These are all too short. assertFalse(AbbreviatedObjectId.isId("")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index 65d1b6e24..8737b697c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -48,28 +48,37 @@ 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.util.Arrays; import java.util.LinkedList; import java.util.Set; -import junit.framework.TestCase; - import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.SystemReader; +import org.junit.Test; /** * Test reading of git config */ -public class ConfigTest extends TestCase { +public class ConfigTest { + @Test public void test001_ReadBareKey() throws ConfigInvalidException { final Config c = parse("[foo]\nbar\n"); assertEquals(true, c.getBoolean("foo", null, "bar", false)); assertEquals("", c.getString("foo", null, "bar")); } + @Test public void test002_ReadWithSubsection() throws ConfigInvalidException { final Config c = parse("[foo \"zip\"]\nbar\n[foo \"zap\"]\nbar=false\nn=3\n"); 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)); } + @Test public void test003_PutRemote() { final Config c = new Config(); c.setString("sec", "ext", "name", "value"); @@ -88,6 +98,7 @@ public class ConfigTest extends TestCase { assertEquals(expText, c.toText()); } + @Test public void test004_PutGetSimple() { Config c = new Config(); c.setString("my", null, "somename", "false"); @@ -95,6 +106,7 @@ public class ConfigTest extends TestCase { assertEquals("[my]\n\tsomename = false\n", c.toText()); } + @Test public void test005_PutGetStringList() { Config c = new Config(); final LinkedList values = new LinkedList(); @@ -110,12 +122,14 @@ public class ConfigTest extends TestCase { assertEquals(expText, c.toText()); } + @Test public void test006_readCaseInsensitive() throws ConfigInvalidException { final Config c = parse("[Foo]\nBar\n"); assertEquals(true, c.getBoolean("foo", null, "bar", false)); assertEquals("", c.getString("foo", null, "bar")); } + @Test public void test007_readUserConfig() { final MockSystemReader mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); @@ -176,6 +190,7 @@ public class ConfigTest extends TestCase { assertEquals("author@localemail", authorEmail); } + @Test public void testReadBoolean_TrueFalse1() throws ConfigInvalidException { final Config c = parse("[s]\na = true\nb = false\n"); assertEquals("true", c.getString("s", null, "a")); @@ -185,6 +200,7 @@ public class ConfigTest extends TestCase { assertFalse(c.getBoolean("s", "b", true)); } + @Test public void testReadBoolean_TrueFalse2() throws ConfigInvalidException { final Config c = parse("[s]\na = TrUe\nb = fAlSe\n"); assertEquals("TrUe", c.getString("s", null, "a")); @@ -194,6 +210,7 @@ public class ConfigTest extends TestCase { assertFalse(c.getBoolean("s", "b", true)); } + @Test public void testReadBoolean_YesNo1() throws ConfigInvalidException { final Config c = parse("[s]\na = yes\nb = no\n"); assertEquals("yes", c.getString("s", null, "a")); @@ -203,6 +220,7 @@ public class ConfigTest extends TestCase { assertFalse(c.getBoolean("s", "b", true)); } + @Test public void testReadBoolean_YesNo2() throws ConfigInvalidException { final Config c = parse("[s]\na = yEs\nb = NO\n"); assertEquals("yEs", c.getString("s", null, "a")); @@ -212,6 +230,7 @@ public class ConfigTest extends TestCase { assertFalse(c.getBoolean("s", "b", true)); } + @Test public void testReadBoolean_OnOff1() throws ConfigInvalidException { final Config c = parse("[s]\na = on\nb = off\n"); assertEquals("on", c.getString("s", null, "a")); @@ -221,6 +240,7 @@ public class ConfigTest extends TestCase { assertFalse(c.getBoolean("s", "b", true)); } + @Test public void testReadBoolean_OnOff2() throws ConfigInvalidException { final Config c = parse("[s]\na = ON\nb = OFF\n"); assertEquals("ON", c.getString("s", null, "a")); @@ -234,6 +254,7 @@ public class ConfigTest extends TestCase { ONE_TWO; } + @Test public void testGetEnum() throws ConfigInvalidException { Config c = parse("[s]\na = ON\nb = input\nc = true\nd = off\n"); 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)); } + @Test public void testSetEnum() { final Config c = new Config(); c.setEnum("s", "b", "c", TestEnum.ONE_TWO); assertEquals("[s \"b\"]\n\tc = one two\n", c.toText()); } + @Test public void testReadLong() throws ConfigInvalidException { assertReadLong(1L); assertReadLong(-1L); @@ -279,6 +302,7 @@ public class ConfigTest extends TestCase { } } + @Test public void testBooleanWithNoValue() throws ConfigInvalidException { Config c = parse("[my]\n\tempty\n"); assertEquals("", c.getString("my", null, "empty")); @@ -288,6 +312,7 @@ public class ConfigTest extends TestCase { assertEquals("[my]\n\tempty\n", c.toText()); } + @Test public void testEmptyString() throws ConfigInvalidException { Config c = parse("[my]\n\tempty =\n"); assertNull(c.getString("my", null, "empty")); @@ -308,6 +333,7 @@ public class ConfigTest extends TestCase { assertEquals("[my]\n\tempty =\n", c.toText()); } + @Test public void testUnsetBranchSection() throws ConfigInvalidException { Config c = parse("" // + "[branch \"keep\"]\n" @@ -329,6 +355,7 @@ public class ConfigTest extends TestCase { + " packedGitLimit = 14\n", c.toText()); } + @Test public void testUnsetSingleSection() throws ConfigInvalidException { Config c = parse("" // + "[branch \"keep\"]\n" @@ -349,6 +376,7 @@ public class ConfigTest extends TestCase { + " packedGitLimit = 14\n", c.toText()); } + @Test public void test008_readSectionNames() throws ConfigInvalidException { final Config c = parse("[a]\n [B]\n"); Set sections = c.getSections(); @@ -356,6 +384,7 @@ public class ConfigTest extends TestCase { assertTrue("Sections should contain \"b\"", sections.contains("b")); } + @Test public void test009_readNamesInSection() throws ConfigInvalidException { String configString = "[core]\n" + "repositoryformatversion = 0\n" + "filemode = false\n" + "logallrefupdates = true\n"; @@ -366,6 +395,7 @@ public class ConfigTest extends TestCase { .contains("filemode")); } + @Test public void test010_readNamesInSubSection() throws ConfigInvalidException { String configString = "[a \"sub1\"]\n"// + "x = 0\n" // @@ -386,6 +416,7 @@ public class ConfigTest extends TestCase { assertTrue("Subsection should contain \"b\"", names.contains("b")); } + @Test public void testQuotingForSubSectionNames() { String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n"; String result; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConstantsEncodingTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConstantsEncodingTest.java index 96568ff23..114d9da90 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConstantsEncodingTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConstantsEncodingTest.java @@ -43,12 +43,17 @@ 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.util.Arrays; -import junit.framework.TestCase; +import org.junit.Test; -public class ConstantsEncodingTest extends TestCase { +public class ConstantsEncodingTest { + @Test public void testEncodeASCII_SimpleASCII() throws UnsupportedEncodingException { final String src = "abc"; @@ -58,6 +63,7 @@ public class ConstantsEncodingTest extends TestCase { assertEquals(src, new String(res, 0, res.length, "UTF-8")); } + @Test public void testEncodeASCII_FailOnNonASCII() { final String src = "Ūnĭcōde̽"; try { @@ -68,6 +74,7 @@ public class ConstantsEncodingTest extends TestCase { } } + @Test public void testEncodeASCII_Number13() { final long src = 13; final byte[] exp = { '1', '3' }; @@ -75,6 +82,7 @@ public class ConstantsEncodingTest extends TestCase { assertTrue(Arrays.equals(exp, res)); } + @Test public void testEncode_SimpleASCII() throws UnsupportedEncodingException { final String src = "abc"; 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")); } + @Test public void testEncode_Unicode() throws UnsupportedEncodingException { final String src = "Ūnĭcōde̽"; final byte[] exp = { (byte) 0xC5, (byte) 0xAA, 0x6E, (byte) 0xC4, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java index 3baa4d65f..1b4a9ff23 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java @@ -37,6 +37,9 @@ */ package org.eclipse.jgit.lib; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; 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.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Test; public class DirCacheCheckoutTest extends ReadTreeTest { private DirCacheCheckout dco; @@ -94,6 +98,7 @@ public class DirCacheCheckoutTest extends ReadTreeTest { return dco.getConflicts(); } + @Test public void testResetHard() throws IOException, NoFilepatternException, GitAPIException { Git git = new Git(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java index 773ebbff2..d98358746 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.lib; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; 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.DirCacheEntry; import org.eclipse.jgit.treewalk.FileTreeIterator; +import org.junit.Test; public class IndexDiffTest extends RepositoryTestCase { + @Test public void testAdded() throws IOException { GitIndex index = new GitIndex(db); writeTrashFile("file1", "file1"); @@ -76,6 +81,7 @@ public class IndexDiffTest extends RepositoryTestCase { assertEquals(0, diff.getRemoved().size()); } + @Test public void testRemoved() throws IOException { writeTrashFile("file2", "file2"); writeTrashFile("dir/file3", "dir/file3"); @@ -101,6 +107,7 @@ public class IndexDiffTest extends RepositoryTestCase { assertEquals(0, diff.getAdded().size()); } + @Test public void testModified() throws IOException { GitIndex index = new GitIndex(db); @@ -132,6 +139,7 @@ public class IndexDiffTest extends RepositoryTestCase { assertEquals(0, diff.getMissing().size()); } + @Test public void testUnchangedSimple() throws IOException { GitIndex index = new GitIndex(db); @@ -166,6 +174,7 @@ public class IndexDiffTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testUnchangedComplex() throws IOException { GitIndex index = new GitIndex(db); @@ -221,6 +230,7 @@ public class IndexDiffTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testRemovedUntracked() throws Exception{ Git git = new Git(db); String path = "file"; @@ -235,6 +245,7 @@ public class IndexDiffTest extends RepositoryTestCase { assertTrue(diff.getUntracked().contains(path)); } + @Test public void testAssumeUnchanged() throws Exception { Git git = new Git(db); String path = "file"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexTreeWalkerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexTreeWalkerTest.java index f93343aab..3f61698cf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexTreeWalkerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexTreeWalkerTest.java @@ -44,11 +44,16 @@ 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.IOException; import java.util.ArrayList; import org.eclipse.jgit.lib.GitIndex.Entry; +import org.junit.Test; public class IndexTreeWalkerTest extends RepositoryTestCase { private ArrayList treeOnlyEntriesVisited = new ArrayList(); @@ -74,6 +79,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase { * because I already */ + @Test public void testTreeOnlyOneLevel() throws IOException { GitIndex index = new GitIndex(db); Tree tree = new Tree(db); @@ -86,6 +92,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase { assertTrue(treeOnlyEntriesVisited.get(1).equals("foo")); } + @Test public void testIndexOnlyOneLevel() throws IOException { GitIndex index = new GitIndex(db); Tree tree = new Tree(db); @@ -98,6 +105,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase { assertTrue(indexOnlyEntriesVisited.get(1).equals("foo")); } + @Test public void testBoth() throws IOException { GitIndex index = new GitIndex(db); Tree tree = new Tree(db); @@ -114,6 +122,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase { } + @Test public void testIndexOnlySubDirs() throws IOException { GitIndex index = new GitIndex(db); Tree tree = new Tree(db); @@ -126,6 +135,7 @@ public class IndexTreeWalkerTest extends RepositoryTestCase { assertEquals("foo/bar/baz", indexOnlyEntriesVisited.get(1)); } + @Test public void testLeavingTree() throws IOException { GitIndex index = new GitIndex(db); index.add(trash, writeTrashFile("foo/bar", "foo/bar")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java index fbb792401..4e128e7f2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java @@ -42,17 +42,23 @@ */ package org.eclipse.jgit.lib; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import org.junit.Test; + public class MergeHeadMsgTest extends RepositoryTestCase { private static final String mergeMsg = "merge a and b"; private static final String sampleId = "1c6db447abdbb291b25f07be38ea0b1bf94947c5"; + @Test public void testReadWriteMergeHeads() throws IOException { assertEquals(db.readMergeHeads(), null); db.writeMergeHeads(Arrays.asList(ObjectId.zeroId(), @@ -86,6 +92,7 @@ public class MergeHeadMsgTest extends RepositoryTestCase { assertEquals(db.readMergeHeads().get(0), ObjectId.fromString(sampleId)); } + @Test public void testReadWriteMergeMsg() throws IOException { assertEquals(db.readMergeCommitMsg(), null); assertFalse(new File(db.getDirectory(), "MERGE_MSG").exists()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java index 387a38189..3813a80b2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java @@ -44,21 +44,25 @@ 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.errors.CorruptObjectException; +import org.junit.Before; +import org.junit.Test; -public class ObjectCheckerTest extends TestCase { +public class ObjectCheckerTest { private ObjectChecker checker; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { checker = new ObjectChecker(); } + @Test public void testInvalidType() { try { checker.check(Constants.OBJ_BAD, new byte[0]); @@ -69,6 +73,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testCheckBlob() throws CorruptObjectException { // Any blob should pass... checker.checkBlob(new byte[0]); @@ -78,6 +83,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_BLOB, new byte[1]); } + @Test public void testValidCommitNoParent() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -93,6 +99,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_COMMIT, data); } + @Test public void testValidCommitBlankAuthor() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -108,6 +115,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_COMMIT, data); } + @Test public void testValidCommit1Parent() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -127,6 +135,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_COMMIT, data); } + @Test public void testValidCommit2Parent() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -150,6 +159,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_COMMIT, data); } + @Test public void testValidCommit128Parent() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -171,6 +181,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_COMMIT, data); } + @Test public void testValidCommitNormalTime() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); final String when = "1222757360 -0730"; @@ -187,6 +198,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_COMMIT, data); } + @Test public void testInvalidCommitNoTree1() { final StringBuilder b = new StringBuilder(); @@ -203,6 +215,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitNoTree2() { final StringBuilder b = new StringBuilder(); @@ -219,6 +232,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitNoTree3() { final StringBuilder b = new StringBuilder(); @@ -235,6 +249,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitNoTree4() { final StringBuilder b = new StringBuilder(); @@ -251,6 +266,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidTree1() { final StringBuilder b = new StringBuilder(); @@ -267,6 +283,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidTree2() { final StringBuilder b = new StringBuilder(); @@ -283,6 +300,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidTree3() { final StringBuilder b = new StringBuilder(); @@ -299,6 +317,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidTree4() { final StringBuilder b = new StringBuilder(); @@ -315,6 +334,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidParent1() { final StringBuilder b = new StringBuilder(); @@ -334,6 +354,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidParent2() { final StringBuilder b = new StringBuilder(); @@ -354,6 +375,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidParent3() { final StringBuilder b = new StringBuilder(); @@ -374,6 +396,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidParent4() { final StringBuilder b = new StringBuilder(); @@ -394,6 +417,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidParent5() { final StringBuilder b = new StringBuilder(); @@ -416,6 +440,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitNoAuthor() { final StringBuilder b = new StringBuilder(); @@ -436,6 +461,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitNoCommitter1() { final StringBuilder b = new StringBuilder(); @@ -456,6 +482,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitNoCommitter2() { final StringBuilder b = new StringBuilder(); @@ -477,6 +504,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor1() { final StringBuilder b = new StringBuilder(); @@ -497,6 +525,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor2() { final StringBuilder b = new StringBuilder(); @@ -517,6 +546,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor3() { final StringBuilder b = new StringBuilder(); @@ -537,6 +567,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor4() { final StringBuilder b = new StringBuilder(); @@ -557,6 +588,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor5() { final StringBuilder b = new StringBuilder(); @@ -577,6 +609,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor6() { final StringBuilder b = new StringBuilder(); @@ -597,6 +630,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidAuthor7() { final StringBuilder b = new StringBuilder(); @@ -617,6 +651,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidCommitInvalidCommitter() { final StringBuilder b = new StringBuilder(); @@ -638,6 +673,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testValidTag() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -654,6 +690,7 @@ public class ObjectCheckerTest extends TestCase { checker.check(Constants.OBJ_TAG, data); } + @Test public void testInvalidTagNoObject1() { final StringBuilder b = new StringBuilder(); @@ -666,6 +703,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoObject2() { final StringBuilder b = new StringBuilder(); @@ -682,6 +720,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoObject3() { final StringBuilder b = new StringBuilder(); @@ -698,6 +737,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoObject4() { final StringBuilder b = new StringBuilder(); @@ -714,6 +754,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoObject5() { final StringBuilder b = new StringBuilder(); @@ -730,6 +771,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoObject6() { final StringBuilder b = new StringBuilder(); @@ -745,6 +787,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoType1() { final StringBuilder b = new StringBuilder(); @@ -761,6 +804,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoType2() { final StringBuilder b = new StringBuilder(); @@ -779,6 +823,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoType3() { final StringBuilder b = new StringBuilder(); @@ -797,6 +842,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoType4() { final StringBuilder b = new StringBuilder(); @@ -815,6 +861,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoTagHeader1() { final StringBuilder b = new StringBuilder(); @@ -833,6 +880,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoTagHeader2() { final StringBuilder b = new StringBuilder(); @@ -852,6 +900,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagNoTagHeader3() { final StringBuilder b = new StringBuilder(); @@ -871,6 +920,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testValidTagHasNoTaggerHeader() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -884,6 +934,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTag(Constants.encodeASCII(b.toString())); } + @Test public void testInvalidTagInvalidTaggerHeader1() { final StringBuilder b = new StringBuilder(); @@ -904,6 +955,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTagInvalidTaggerHeader3() { final StringBuilder b = new StringBuilder(); @@ -924,11 +976,13 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testValidEmptyTree() throws CorruptObjectException { checker.checkTree(new byte[0]); checker.check(Constants.OBJ_TREE, new byte[0]); } + @Test public void testValidTree1() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100644 regular-file"); @@ -936,6 +990,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTree2() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100755 executable"); @@ -943,6 +998,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTree3() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "40000 tree"); @@ -950,6 +1006,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTree4() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "120000 symlink"); @@ -957,6 +1014,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTree5() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "160000 git link"); @@ -964,6 +1022,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTree6() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100644 .a"); @@ -971,6 +1030,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting1() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100644 fooaaa"); @@ -979,6 +1039,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting2() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100755 fooaaa"); @@ -987,6 +1048,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting3() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "40000 a"); @@ -995,6 +1057,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting4() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100644 a"); @@ -1003,6 +1066,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting5() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100644 a.c"); @@ -1012,6 +1076,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting6() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "40000 a"); @@ -1020,6 +1085,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting7() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "40000 an orang"); @@ -1028,6 +1094,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testValidTreeSorting8() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); entry(b, "100644 a"); @@ -1037,6 +1104,7 @@ public class ObjectCheckerTest extends TestCase { checker.checkTree(data); } + @Test public void testInvalidTreeModeStartsWithZero1() { final StringBuilder b = new StringBuilder(); entry(b, "0 a"); @@ -1049,6 +1117,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeStartsWithZero2() { final StringBuilder b = new StringBuilder(); entry(b, "0100644 a"); @@ -1061,6 +1130,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeStartsWithZero3() { final StringBuilder b = new StringBuilder(); entry(b, "040000 a"); @@ -1073,6 +1143,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeNotOctal1() { final StringBuilder b = new StringBuilder(); entry(b, "8 a"); @@ -1085,6 +1156,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeNotOctal2() { final StringBuilder b = new StringBuilder(); entry(b, "Z a"); @@ -1097,6 +1169,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeNotSupportedMode1() { final StringBuilder b = new StringBuilder(); entry(b, "1 a"); @@ -1109,6 +1182,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeNotSupportedMode2() { final StringBuilder b = new StringBuilder(); entry(b, "170000 a"); @@ -1121,6 +1195,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeModeMissingName() { final StringBuilder b = new StringBuilder(); b.append("100644"); @@ -1133,6 +1208,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeNameContainsSlash() { final StringBuilder b = new StringBuilder(); entry(b, "100644 a/b"); @@ -1145,6 +1221,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeNameIsEmpty() { final StringBuilder b = new StringBuilder(); entry(b, "100644 "); @@ -1157,6 +1234,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeNameIsDot() { final StringBuilder b = new StringBuilder(); entry(b, "100644 ."); @@ -1169,6 +1247,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeNameIsDotDot() { final StringBuilder b = new StringBuilder(); entry(b, "100644 .."); @@ -1181,6 +1260,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeTruncatedInName() { final StringBuilder b = new StringBuilder(); b.append("100644 b"); @@ -1193,6 +1273,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeTruncatedInObjectId() { final StringBuilder b = new StringBuilder(); b.append("100644 b\0\1\2"); @@ -1205,6 +1286,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeBadSorting1() { final StringBuilder b = new StringBuilder(); entry(b, "100644 foobar"); @@ -1218,6 +1300,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeBadSorting2() { final StringBuilder b = new StringBuilder(); entry(b, "40000 a"); @@ -1231,6 +1314,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeBadSorting3() { final StringBuilder b = new StringBuilder(); entry(b, "100644 a0c"); @@ -1244,6 +1328,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeDuplicateNames1() { final StringBuilder b = new StringBuilder(); entry(b, "100644 a"); @@ -1257,6 +1342,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeDuplicateNames2() { final StringBuilder b = new StringBuilder(); entry(b, "100644 a"); @@ -1270,6 +1356,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeDuplicateNames3() { final StringBuilder b = new StringBuilder(); entry(b, "100644 a"); @@ -1283,6 +1370,7 @@ public class ObjectCheckerTest extends TestCase { } } + @Test public void testInvalidTreeDuplicateNames4() { final StringBuilder b = new StringBuilder(); entry(b, "100644 a"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdRefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdRefTest.java index 1774a428d..fb16c6bac 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdRefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdRefTest.java @@ -43,9 +43,15 @@ 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 .fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed"); @@ -54,6 +60,7 @@ public class ObjectIdRefTest extends TestCase { private static final String name = "refs/heads/a.test.ref"; + @Test public void testConstructor_PeeledStatusNotKnown() { ObjectIdRef r; @@ -84,6 +91,7 @@ public class ObjectIdRefTest extends TestCase { assertFalse("not symbolic", r.isSymbolic()); } + @Test public void testConstructor_Peeled() { ObjectIdRef r; @@ -106,6 +114,7 @@ public class ObjectIdRefTest extends TestCase { assertSame(ID_B, r.getPeeledObjectId()); } + @Test public void testToString() { ObjectIdRef r; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java index e5faff15e..cdcb43322 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java @@ -45,21 +45,28 @@ 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() { final String x = "def4c620bc3713bb1bb26b808ec9312548e73946"; final ObjectId oid = ObjectId.fromString(x); assertEquals(x, oid.name()); } + @Test public void test002_toString() { final String x = "ff00eedd003713bb1bb26b808ec9312548e73946"; final ObjectId oid = ObjectId.fromString(x); assertEquals(x, oid.name()); } + @Test public void test003_equals() { final String x = "def4c620bc3713bb1bb26b808ec9312548e73946"; final ObjectId a = ObjectId.fromString(x); @@ -68,47 +75,56 @@ public class ObjectIdTest extends TestCase { assertTrue("a and b are same", a.equals(b)); } + @Test public void test004_isId() { assertTrue("valid id", ObjectId .isId("def4c620bc3713bb1bb26b808ec9312548e73946")); } + @Test public void test005_notIsId() { assertFalse("bob is not an id", ObjectId.isId("bob")); } + @Test public void test006_notIsId() { assertFalse("39 digits is not an id", ObjectId .isId("def4c620bc3713bb1bb26b808ec9312548e7394")); } + @Test public void test007_isId() { assertTrue("uppercase is accepted", ObjectId .isId("Def4c620bc3713bb1bb26b808ec9312548e73946")); } + @Test public void test008_notIsId() { assertFalse("g is not a valid hex digit", ObjectId .isId("gef4c620bc3713bb1bb26b808ec9312548e73946")); } + @Test public void test009_toString() { final String x = "ff00eedd003713bb1bb26b808ec9312548e73946"; final ObjectId oid = ObjectId.fromString(x); assertEquals(x, ObjectId.toString(oid)); } + @Test public void test010_toString() { final String x = "0000000000000000000000000000000000000000"; assertEquals(x, ObjectId.toString(null)); } + @Test public void test011_toString() { final String x = "0123456789ABCDEFabcdef1234567890abcdefAB"; final ObjectId oid = ObjectId.fromString(x); assertEquals(x.toLowerCase(), oid.name()); } + @Test public void testGetByte() { byte[] raw = new byte[20]; 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)); } + @Test public void testSetByte() { byte[] exp = new byte[20]; for (int i = 0; i < 20; i++) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectLoaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectLoaderTest.java index 0280b4a45..83e61d9ab 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectLoaderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectLoaderTest.java @@ -44,29 +44,38 @@ package org.eclipse.jgit.lib; 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.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; -import junit.framework.TestCase; - import org.eclipse.jgit.errors.LargeObjectException; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.TestRng; +import org.junit.Test; -public class ObjectLoaderTest extends TestCase { +public class ObjectLoaderTest { private TestRng rng; - protected void setUp() throws Exception { - super.setUp(); - rng = new TestRng(getName()); + private TestRng getRng() { + if (rng == null) + rng = new TestRng(JGitTestUtil.getName()); + return rng; } + @Test public void testSmallObjectLoader() throws MissingObjectException, IOException { - final byte[] act = rng.nextBytes(512); + final byte[] act = getRng().nextBytes(512); final ObjectLoader ldr = new ObjectLoader.SmallObject(OBJ_BLOB, act); assertEquals(OBJ_BLOB, ldr.getType()); @@ -106,9 +115,10 @@ public class ObjectLoaderTest extends TestCase { assertTrue("same content", Arrays.equals(act, tmp.toByteArray())); } + @Test public void testLargeObjectLoader() throws MissingObjectException, IOException { - final byte[] act = rng.nextBytes(512); + final byte[] act = getRng().nextBytes(512); final ObjectLoader ldr = new ObjectLoader() { @Override public byte[] getCachedBytes() throws LargeObjectException { @@ -179,9 +189,10 @@ public class ObjectLoaderTest extends TestCase { assertTrue("same content", Arrays.equals(act, tmp.toByteArray())); } + @Test public void testLimitedGetCachedBytes() throws LargeObjectException, MissingObjectException, IOException { - byte[] act = rng.nextBytes(512); + byte[] act = getRng().nextBytes(512); ObjectLoader ldr = new ObjectLoader.SmallObject(OBJ_BLOB, act) { @Override public boolean isLarge() { @@ -206,6 +217,7 @@ public class ObjectLoaderTest extends TestCase { assertTrue("same content", Arrays.equals(act, copy)); } + @Test public void testLimitedGetCachedBytesExceedsJavaLimits() throws LargeObjectException, MissingObjectException, IOException { ObjectLoader ldr = new ObjectLoader() { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java index bf86ef458..80b853ee7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java @@ -42,6 +42,9 @@ */ package org.eclipse.jgit.lib; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java index 2bf81e16f..7473db932 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java @@ -45,6 +45,12 @@ */ 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.FileInputStream; import java.io.IOException; @@ -58,6 +64,7 @@ import org.eclipse.jgit.errors.CheckoutConflictException; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Test; public abstract class ReadTreeTest extends RepositoryTestCase { protected Tree theHead; @@ -66,6 +73,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { // Each of these rules are from the read-tree manpage // go there to see what they mean. // Rule 0 is left out for obvious reasons :) + @Test public void testRules1thru3_NoIndexEntry() throws IOException { Tree head = new Tree(db); head = buildTree(mk("foo")); @@ -154,6 +162,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { // for these rules, they all have clean yes/no options // but it doesn't matter if the entry is clean or not // so we can just ignore the state in the filesystem entirely + @Test public void testRules4thru13_IndexEntryNotInHead() throws IOException { // rules 4 and 5 HashMap idxMap; @@ -251,6 +260,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertTrue(getConflicts().isEmpty()); } + @Test public void testDirectoryFileSimple() throws IOException { Tree treeDF = buildTree(mkmap("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 */ + @Test public void testDirectoryFileConflicts_1() throws Exception { // 1 doit(mk("DF/DF"), mk("DF"), mk("DF/DF")); @@ -308,6 +319,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertRemoved("DF/DF"); } + @Test public void testDirectoryFileConflicts_2() throws Exception { // 2 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 { // 3 - the first to break! doit(mk("DF/DF"), mk("DF/DF"), mk("DF")); @@ -324,6 +337,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertRemoved("DF"); } + @Test public void testDirectoryFileConflicts_4() throws Exception { // 4 (basically same as 3, just with H and M different) 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 { // 5 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 { // 6 setupCase(mk("DF/DF"), mk("DF"), mk("DF")); @@ -347,6 +363,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertRemoved("DF/DF"); } + @Test public void testDirectoryFileConflicts_7() throws Exception { // 7 doit(mk("DF"), mk("DF"), mk("DF/DF")); @@ -375,6 +392,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { // This test would fail in DirCacheCheckoutTests. } + @Test public void testDirectoryFileConflicts_8() throws Exception { // 8 setupCase(mk("DF"), mk("DF"), mk("DF/DF")); @@ -384,6 +402,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertConflict("DF/DF"); } + @Test public void testDirectoryFileConflicts_9() throws Exception { // 9 doit(mk("DF"), mkmap("DF", "QP"), mk("DF/DF")); @@ -391,6 +410,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF"); } + @Test public void testDirectoryFileConflicts_10() throws Exception { // 10 cleanUpDF(); @@ -398,12 +418,14 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertNoConflicts(); } + @Test public void testDirectoryFileConflicts_11() throws Exception { // 11 doit(mk("DF"), mk("DF/DF"), mkmap("DF/DF", "asdf")); assertConflict("DF/DF"); } + @Test public void testDirectoryFileConflicts_12() throws Exception { // 12 cleanUpDF(); @@ -412,6 +434,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF/DF"); } + @Test public void testDirectoryFileConflicts_13() throws Exception { // 13 cleanUpDF(); @@ -422,6 +445,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF/DF"); } + @Test public void testDirectoryFileConflicts_14() throws Exception { // 14 cleanUpDF(); @@ -430,6 +454,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF/DF"); } + @Test public void testDirectoryFileConflicts_15() throws Exception { // 15 doit(mkmap(), mk("DF/DF"), mk("DF")); @@ -441,6 +466,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF/DF"); } + @Test public void testDirectoryFileConflicts_15b() throws Exception { // 15, take 2, just to check multi-leveled doit(mkmap(), mk("DF/DF/DF/DF"), mk("DF")); @@ -453,6 +479,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF/DF/DF/DF"); } + @Test public void testDirectoryFileConflicts_16() throws Exception { // 16 cleanUpDF(); @@ -461,6 +488,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF"); } + @Test public void testDirectoryFileConflicts_17() throws Exception { // 17 cleanUpDF(); @@ -476,6 +504,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { // assertUpdated("DF"); } + @Test public void testDirectoryFileConflicts_18() throws Exception { // 18 cleanUpDF(); @@ -484,6 +513,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertUpdated("DF/DF/DF/DF"); } + @Test public void testDirectoryFileConflicts_19() throws Exception { // 19 cleanUpDF(); @@ -536,6 +566,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { return map; } + @Test public void testUntrackedConflicts() throws IOException { setupCase(null, mk("foo"), null); writeTrashFile("foo", "foo"); @@ -574,6 +605,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertNoConflicts(); } + @Test 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") ); checkout(); @@ -585,6 +617,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertNoConflicts(); } + @Test 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") ); checkout(); @@ -596,6 +629,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertNoConflicts(); } + @Test public void testCheckoutHierarchy() throws IOException { setupCase( 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 { setupCase(mk("foo"), mk("foo/bar"), mk("foo")); checkout(); @@ -648,6 +683,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { } } + @Test public void testCheckoutUncachedChanges() throws IOException { setupCase(mk("foo"), mk("foo"), mk("foo")); writeTrashFile("foo", "otherData"); @@ -657,6 +693,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase { assertTrue(new File(trash, "foo").isFile()); } + @Test public void testDontOverwriteDirtyFile() throws IOException { setupCase(mk("foo"), mk("other"), mk("foo")); writeTrashFile("foo", "different"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java index 100b758e6..48140161d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java @@ -45,6 +45,14 @@ 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.FileOutputStream; import java.io.IOException; @@ -52,6 +60,7 @@ import java.util.Map; import org.eclipse.jgit.lib.Ref.Storage; 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 @@ -71,6 +80,7 @@ public class RefTest extends SampleDataRepositoryTestCase { } } + @Test public void testReadAllIncludingSymrefs() throws Exception { ObjectId masterId = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/remotes/origin/master"); @@ -96,6 +106,7 @@ public class RefTest extends SampleDataRepositoryTestCase { assertNull(refmaster.getPeeledObjectId()); } + @Test public void testReadSymRefToPacked() throws IOException { writeSymref("HEAD", "refs/heads/b"); Ref ref = db.getRef("HEAD"); @@ -106,6 +117,7 @@ public class RefTest extends SampleDataRepositoryTestCase { assertEquals(Ref.Storage.PACKED, ref.getStorage()); } + @Test public void testReadSymRefToLoosePacked() throws IOException { ObjectId pid = db.resolve("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()); } + @Test public void testReadLooseRef() throws IOException { RefUpdate updateRef = db.updateRef("ref/heads/new"); updateRef.setNewObjectId(db.resolve("refs/heads/master")); @@ -137,6 +150,7 @@ public class RefTest extends SampleDataRepositoryTestCase { * @throws IOException * @throws InterruptedException */ + @Test public void testReadLoosePackedRef() throws IOException, InterruptedException { Ref ref = db.getRef("refs/heads/master"); @@ -157,6 +171,7 @@ public class RefTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testReadSimplePackedRefSameRepo() throws IOException { Ref ref = db.getRef("refs/heads/master"); ObjectId pid = db.resolve("refs/heads/master^"); @@ -171,11 +186,13 @@ public class RefTest extends SampleDataRepositoryTestCase { assertEquals(Storage.LOOSE, ref.getStorage()); } + @Test public void testResolvedNamesBranch() throws IOException { Ref ref = db.getRef("a"); assertEquals("refs/heads/a", ref.getName()); } + @Test public void testResolvedSymRef() throws IOException { Ref ref = db.getRef(Constants.HEAD); assertEquals(Constants.HEAD, ref.getName()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java index 089531dec..bfd8c9ffd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java @@ -45,11 +45,17 @@ 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 org.eclipse.jgit.storage.file.FileBasedConfig; +import org.junit.Test; public class ReflogConfigTest extends RepositoryTestCase { + @Test public void testlogAllRefUpdates() throws Exception { long commitTime = 1154236443000L; int tz = -4 * 60; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java index cab3cba37..b399bf0b3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java @@ -43,13 +43,23 @@ 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.IOException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.RepositoryCache.FileKey; +import org.junit.Test; public class RepositoryCacheTest extends RepositoryTestCase { + @Test public void testNonBareFileKey() { File gitdir = db.getDirectory(); File parent = gitdir.getParentFile(); @@ -63,6 +73,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { assertEquals(other, FileKey.lenient(other, db.getFS()).getFile()); } + @Test public void testBareFileKey() throws IOException { Repository bare = createBareRepository(); File gitdir = bare.getDirectory(); @@ -77,6 +88,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { assertEquals(gitdir, FileKey.lenient(new File(parent, name), db.getFS()).getFile()); } + @Test public void testFileKeyOpenExisting() throws IOException { Repository r; @@ -91,6 +103,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { r.close(); } + @Test public void testFileKeyOpenNew() throws IOException { final Repository n = createBareRepository(); final File gitdir = n.getDirectory(); @@ -111,6 +124,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { assertFalse(gitdir.exists()); } + @Test public void testCacheRegisterOpen() throws Exception { final File dir = db.getDirectory(); RepositoryCache.register(db); @@ -121,6 +135,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { assertSame(db, RepositoryCache.open(FileKey.lenient(parent, db.getFS()))); } + @Test public void testCacheOpen() throws Exception { final FileKey loc = FileKey.exact(db.getDirectory(), db.getFS()); final Repository d2 = RepositoryCache.open(loc); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java index 0aa8db474..5ad913c56 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java @@ -46,38 +46,49 @@ 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 org.eclipse.jgit.errors.IncorrectObjectTypeException; +import org.junit.Test; public class RepositoryResolveTest extends SampleDataRepositoryTestCase { + @Test public void testObjectId_existing() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0").name()); } + @Test public void testObjectId_nonexisting() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c1",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c1").name()); } + @Test public void testObjectId_objectid_implicit_firstparent() throws IOException { assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^").name()); assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^^").name()); } + @Test public void testObjectId_objectid_self() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0^0").name()); assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^0^0^0").name()); } + @Test public void testObjectId_objectid_explicit_firstparent() throws IOException { assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1").name()); assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1^1").name()); assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1^1^1").name()); } + @Test public void testObjectId_objectid_explicit_otherparents() throws IOException { assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^1").name()); assertEquals("f73b95671f326616d66b2afb3bdfcdbbce110b44",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^2").name()); @@ -85,12 +96,14 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { assertEquals("d0114ab8ac326bab30e3a657a0397578c5a1af88",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^03").name()); } + @Test public void testRef_refname() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("master^0").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("master^").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("refs/heads/master^1").name()); } + @Test public void testDistance() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~0").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~1").name()); @@ -99,15 +112,18 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { assertEquals("bab66b48f836ed950c99134ef666436fb07a09a0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~03").name()); } + @Test public void testTree() throws IOException { assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{tree}").name()); assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^{tree}").name()); } + @Test public void testHEAD() throws IOException { assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("HEAD^{tree}").name()); } + @Test public void testDerefCommit() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{}").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()); } + @Test public void testDerefTag() throws IOException { assertEquals("17768080a2318cd89bba4c8b87834401e2095703",db.resolve("refs/tags/B").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()); } + @Test public void testDerefBlob() throws IOException { assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("spearce-gpg-pub^{}").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()); } + @Test public void testDerefTree() throws IOException { assertEquals("032c063ce34486359e3ee3d4f9e5c225b9e1a4c2",db.resolve("refs/tags/B10th").name()); assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("032c063ce34486359e3ee3d4f9e5c225b9e1a4c2^{tree}").name()); assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("refs/tags/B10th^{tree}").name()); } + @Test public void testParseGitDescribeOutput() throws IOException { ObjectId exp = db.resolve("b"); 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")); } + @Test public void testParseLookupPath() throws IOException { ObjectId b2_txt = id("10da5895682013006950e7da534b705252b03be6"); ObjectId b3_b2_txt = id("e6bfff5c1d0f0ecd501552b43a1e13d8008abc31"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java index 2e850ce9f..3a50bca5f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java @@ -46,6 +46,8 @@ package org.eclipse.jgit.lib; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.FileInputStream; 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.treewalk.FileTreeIterator; import org.eclipse.jgit.util.FileUtils; +import org.junit.Before; /** * Base class for most JGit unit tests. @@ -122,7 +125,8 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { protected File trash; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); db = createWorkRepository(); trash = db.getWorkTree(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java index 7bc9bb22e..b3b6691d4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java +++ b/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 org.eclipse.jgit.util.JGitTestUtil; +import org.eclipse.jgit.junit.JGitTestUtil; /** Test case which includes C Git generated pack files for testing. */ public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase { @Override - protected void setUp() throws Exception { + public void setUp() throws Exception { super.setUp(); final String[] packs = { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SymbolicRefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SymbolicRefTest.java index bff4fc34f..1342253c0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SymbolicRefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SymbolicRefTest.java @@ -43,9 +43,15 @@ 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 .fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed"); @@ -56,6 +62,7 @@ public class SymbolicRefTest extends TestCase { private static final String name = "refs/remotes/origin/HEAD"; + @Test public void testConstructor() { Ref t; SymbolicRef r; @@ -83,6 +90,7 @@ public class SymbolicRefTest extends TestCase { assertTrue("is symbolic", r.isSymbolic()); } + @Test public void testLeaf() { Ref a; SymbolicRef b, c, d; @@ -114,6 +122,7 @@ public class SymbolicRefTest extends TestCase { assertSame(ID_B, b.getPeeledObjectId()); } + @Test public void testToString() { Ref a; SymbolicRef b, c, d; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java similarity index 95% rename from org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java rename to org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java index b3aeb81b1..34a557bd9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java @@ -43,12 +43,16 @@ package org.eclipse.jgit.lib; +import static org.junit.Assert.assertEquals; + import java.util.Date; 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() { final PersonIdent p = new PersonIdent("A U Thor", "author@example.com", new Date(1142878501000L), TimeZone.getTimeZone("EST")); @@ -59,6 +63,7 @@ public class T0001_PersonIdent extends TestCase { p.toExternalString()); } + @Test public void test002_NewIdent() { final PersonIdent p = new PersonIdent("A U Thor", "author@example.com", new Date(1142878501000L), TimeZone.getTimeZone("GMT+0230")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java similarity index 96% rename from org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java rename to org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java index 7731880fd..99b79ce9a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java @@ -44,12 +44,20 @@ 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.UnsupportedEncodingException; import java.util.ArrayList; 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( "0123456789abcdef0123456789abcdef01234567"); @@ -71,13 +79,18 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { return Tree.compareNames(abytes, bbytes, lasta, lastb); } + @Test public void test000_sort_01() throws UnsupportedEncodingException { assertEquals(0, compareNamesUsingSpecialCompare("a","a")); } + + @Test public void test000_sort_02() throws UnsupportedEncodingException { assertEquals(-1, compareNamesUsingSpecialCompare("a","b")); assertEquals(1, compareNamesUsingSpecialCompare("b","a")); } + + @Test public void test000_sort_03() throws UnsupportedEncodingException { 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:")); } + + @Test public void test000_sort_04() throws UnsupportedEncodingException { assertEquals(-1, compareNamesUsingSpecialCompare("a.a","a/a")); assertEquals(1, compareNamesUsingSpecialCompare("a/a","a.a")); } + + @Test public void test000_sort_05() throws UnsupportedEncodingException { assertEquals(-1, compareNamesUsingSpecialCompare("a.","a/")); assertEquals(1, compareNamesUsingSpecialCompare("a/","a.")); } + @Test public void test001_createEmpty() throws IOException { final Tree t = new Tree(db); assertTrue("isLoaded", t.isLoaded()); @@ -114,6 +132,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { assertTrue("no foo child", t.findBlobMember("foo") == null); } + @Test public void test002_addFile() throws IOException { final Tree t = new Tree(db); t.setId(SOME_FAKE_ID); @@ -139,6 +158,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { assertTrue("iterator is empty", i != null && i.length == 1); } + @Test public void test004_addTree() throws IOException { final Tree t = new Tree(db); t.setId(SOME_FAKE_ID); @@ -169,6 +189,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { assertTrue("iterator is empty", i.length == 1); } + @Test public void test005_addRecursiveFile() throws IOException { final Tree t = new Tree(db); final FileTreeEntry f = t.addFile("a/b/c"); @@ -180,6 +201,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { .getParent()); } + @Test public void test005_addRecursiveTree() throws IOException { final Tree t = new Tree(db); final Tree f = t.addTree("a/b/c"); @@ -191,6 +213,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { .getParent()); } + @Test public void test006_addDeepTree() throws IOException { final Tree t = new Tree(db); @@ -240,6 +263,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { assertTrue("t no id", t.getId() == null); } + @Test public void test007_manyFileLookup() throws IOException { final Tree t = new Tree(db); final List files = new ArrayList(26 * 26); @@ -262,6 +286,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { } } + @Test public void test008_SubtreeInternalSorting() throws IOException { final Tree t = new Tree(db); final FileTreeEntry e0 = t.addFile("a-b"); @@ -278,6 +303,7 @@ public class T0002_Tree extends SampleDataRepositoryTestCase { assertSame(e2, ents[4]); } + @Test public void test009_SymlinkAndGitlink() throws IOException { final Tree symlinkTree = db.mapTree("symlink"); assertTrue("Symlink entry exists", symlinkTree.existsBlob("symlink.txt")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java index 6839f8d3c..b44970e35 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java @@ -43,12 +43,19 @@ 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.TimeUnit; -import junit.framework.TestCase; +import org.junit.Test; -public class ThreadSafeProgressMonitorTest extends TestCase { +public class ThreadSafeProgressMonitorTest { + @Test public void testFailsMethodsOnBackgroundThread() throws InterruptedException { final MockProgressMonitor mock = new MockProgressMonitor(); @@ -84,6 +91,7 @@ public class ThreadSafeProgressMonitorTest extends TestCase { assertEquals(0, mock.value); } + @Test public void testMethodsOkOnMainThread() { final MockProgressMonitor mock = new MockProgressMonitor(); final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock); @@ -106,6 +114,7 @@ public class ThreadSafeProgressMonitorTest extends TestCase { assertEquals(0, mock.value); } + @Test public void testUpdateOnBackgroundThreads() throws InterruptedException { final MockProgressMonitor mock = new MockProgressMonitor(); final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorLeafOnlyTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorLeafOnlyTest.java index 0b7e60c5c..4f88b5a3b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorLeafOnlyTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorLeafOnlyTest.java @@ -44,11 +44,18 @@ 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 org.junit.Test; + public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { /** Empty tree */ + @Test public void testEmpty() { Tree tree = new Tree(db); TreeIterator i = makeIterator(tree); @@ -60,6 +67,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleF1() throws IOException { Tree tree = new Tree(db); tree.addFile("x"); @@ -73,6 +81,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleF2() throws IOException { Tree tree = new Tree(db); tree.addFile("a"); @@ -88,6 +97,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleT() throws IOException { Tree tree = new Tree(db); tree.addTree("a"); @@ -95,6 +105,7 @@ public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { assertFalse(i.hasNext()); } + @Test public void testTricky() throws IOException { Tree tree = new Tree(db); tree.addFile("a.b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPostOrderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPostOrderTest.java index 459570430..a0cf12fa3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPostOrderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPostOrderTest.java @@ -44,11 +44,18 @@ 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 org.junit.Test; + public class TreeIteratorPostOrderTest extends RepositoryTestCase { /** Empty tree */ + @Test public void testEmpty() { Tree tree = new Tree(db); TreeIterator i = makeIterator(tree); @@ -62,6 +69,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleF1() throws IOException { Tree tree = new Tree(db); tree.addFile("x"); @@ -78,6 +86,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleF2() throws IOException { Tree tree = new Tree(db); tree.addFile("a"); @@ -96,6 +105,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleT() throws IOException { Tree tree = new Tree(db); tree.addTree("a"); @@ -107,6 +117,7 @@ public class TreeIteratorPostOrderTest extends RepositoryTestCase { assertFalse(i.hasNext()); } + @Test public void testTricky() throws IOException { Tree tree = new Tree(db); tree.addFile("a.b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPreOrderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPreOrderTest.java index 79d090d8a..c68a042ab 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPreOrderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TreeIteratorPreOrderTest.java @@ -44,11 +44,18 @@ 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 org.junit.Test; + public class TreeIteratorPreOrderTest extends RepositoryTestCase { /** Empty tree */ + @Test public void testEmpty() { Tree tree = new Tree(db); TreeIterator i = makeIterator(tree); @@ -62,6 +69,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleF1() throws IOException { Tree tree = new Tree(db); tree.addFile("x"); @@ -78,6 +86,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleF2() throws IOException { Tree tree = new Tree(db); tree.addFile("a"); @@ -96,6 +105,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void testSimpleT() throws IOException { Tree tree = new Tree(db); tree.addTree("a"); @@ -107,6 +117,7 @@ public class TreeIteratorPreOrderTest extends RepositoryTestCase { assertFalse(i.hasNext()); } + @Test public void testTricky() throws IOException { Tree tree = new Tree(db); tree.addFile("a.b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java index 79e2eba70..36d6e3999 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java @@ -43,23 +43,28 @@ 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) { assertEquals("\"" + name + "\"", exp, Repository.isValidRefName(name)); } + @Test public void testEmptyString() { assertValid(false, ""); assertValid(false, "/"); } + @Test public void testMustHaveTwoComponents() { assertValid(false, "master"); assertValid(true, "heads/master"); } + @Test public void testValidHead() { assertValid(true, "refs/heads/master"); assertValid(true, "refs/heads/pu"); @@ -67,27 +72,33 @@ public class ValidRefNameTest extends TestCase { assertValid(true, "refs/heads/FoO"); } + @Test public void testValidTag() { assertValid(true, "refs/tags/v1.0"); } + @Test public void testNoLockSuffix() { assertValid(false, "refs/heads/master.lock"); } + @Test public void testNoDirectorySuffix() { assertValid(false, "refs/heads/master/"); } + @Test public void testNoSpace() { assertValid(false, "refs/heads/i haz space"); } + @Test public void testNoAsciiControlCharacters() { for (char c = '\0'; c < ' '; c++) assertValid(false, "refs/heads/mast" + c + "er"); } + @Test public void testNoBareDot() { assertValid(false, "refs/heads/."); assertValid(false, "refs/heads/.."); @@ -95,6 +106,7 @@ public class ValidRefNameTest extends TestCase { assertValid(false, "refs/heads/../master"); } + @Test public void testNoLeadingOrTrailingDot() { assertValid(false, "."); assertValid(false, "refs/heads/.bar"); @@ -102,11 +114,13 @@ public class ValidRefNameTest extends TestCase { assertValid(false, "refs/heads/bar."); } + @Test public void testContainsDot() { assertValid(true, "refs/heads/m.a.s.t.e.r"); assertValid(false, "refs/heads/master..pu"); } + @Test public void testNoMagicRefCharacters() { assertValid(false, "refs/heads/master^"); assertValid(false, "refs/heads/^master"); @@ -121,6 +135,7 @@ public class ValidRefNameTest extends TestCase { assertValid(false, ":refs/heads/master"); } + @Test public void testShellGlob() { assertValid(false, "refs/heads/master?"); assertValid(false, "refs/heads/?master"); @@ -135,6 +150,7 @@ public class ValidRefNameTest extends TestCase { assertValid(false, "*refs/heads/master"); } + @Test public void testValidSpecialCharacters() { assertValid(true, "refs/heads/!"); assertValid(true, "refs/heads/\""); @@ -166,10 +182,12 @@ public class ValidRefNameTest extends TestCase { assertValid(false, "refs/heads/\\"); } + @Test public void testUnicodeNames() { assertValid(true, "refs/heads/\u00e5ngstr\u00f6m"); } + @Test public void testRefLogQueryIsValidRef() { assertValid(false, "refs/heads/master@{1}"); assertValid(false, "refs/heads/master@{1.hour.ago}"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckoutTest.java index 2599468fa..1136d6a2c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckoutTest.java @@ -44,13 +44,21 @@ 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.IOException; import java.util.ArrayList; import org.eclipse.jgit.errors.CheckoutConflictException; +import org.junit.Test; public class WorkDirCheckoutTest extends RepositoryTestCase { + @Test public void testFindingConflicts() throws IOException { GitIndex index = new GitIndex(db); index.add(trash, writeTrashFile("bar", "bar")); @@ -86,6 +94,7 @@ public class WorkDirCheckoutTest extends RepositoryTestCase { assertTrue(removedEntries.contains("foo")); } + @Test public void testCheckingOutWithConflicts() throws IOException { GitIndex index = new GitIndex(db); index.add(trash, writeTrashFile("bar", "bar")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java index 12fdec2b6..0ac42af52 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.merge; 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.DirCacheBuilder; @@ -57,8 +60,10 @@ import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Test; public class CherryPickTest extends RepositoryTestCase { + @Test public void testPick() throws Exception { // B---O // \----P---T diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java index 06d4c58e3..aa8f8281e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java @@ -43,16 +43,17 @@ package org.eclipse.jgit.merge; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.TestCase; - import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawTextComparator; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class MergeAlgorithmTest extends TestCase { +public class MergeAlgorithmTest { MergeFormatter fmt=new MergeFormatter(); /** @@ -61,6 +62,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testTwoConflictingModifications() throws IOException { assertEquals(t("aZdefghij"), merge("abcdefghij", "abZdefghij", "aZZdefghij")); @@ -73,6 +75,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testOneAgainstTwoConflictingModifications() throws IOException { assertEquals(t("aZZefghij"), merge("abcdefghij", "aZZZefghij", "aZcZefghij")); @@ -84,6 +87,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testNoAgainstOneModification() throws IOException { assertEquals(t("aZcZefghij"), merge("abcdefghij", "abcdefghij", "aZcZefghij")); @@ -95,6 +99,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testTwoNonConflictingModifications() throws IOException { assertEquals(t("YbZdefghij"), merge("abcdefghij", "abZdefghij", "Ybcdefghij")); @@ -106,6 +111,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testTwoComplicatedModifications() throws IOException { assertEquals(t("a"), merge("abcdefghij", "aZZZZfZhZj", "abYdYYYYiY")); @@ -116,6 +122,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testConflictAtStart() throws IOException { assertEquals(t("bcdefghij"), merge("abcdefghij", "Zbcdefghij", "Ybcdefghij")); @@ -126,6 +133,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testConflictAtEnd() throws IOException { assertEquals(t("abcdefghi"), merge("abcdefghij", "abcdefghiZ", "abcdefghiY")); @@ -137,6 +145,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testSameModification() throws IOException { assertEquals(t("abZdefghij"), merge("abcdefghij", "abZdefghij", "abZdefghij")); @@ -148,19 +157,23 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testDeleteVsModify() throws IOException { assertEquals(t("ab<=Z>defghij"), merge("abcdefghij", "abdefghij", "abZdefghij")); } + @Test public void testInsertVsModify() throws IOException { assertEquals(t("a"), merge("ab", "abZ", "aXY")); } + @Test public void testAdjacentModifications() throws IOException { assertEquals(t("ad"), merge("abcd", "aZcd", "abYd")); } + @Test public void testSeperateModifications() throws IOException { assertEquals(t("aZcYe"), merge("abcde", "aZcde", "abcYe")); } @@ -172,6 +185,7 @@ public class MergeAlgorithmTest extends TestCase { * * @throws IOException */ + @Test public void testTwoSimilarModsAndOneInsert() throws IOException { assertEquals(t("IAAJ"), merge("iA", "IA", "IAAJ")); assertEquals(t("aBcDde"), merge("abcde", "aBcde", "aBcDde")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java index 9f7bc40b9..2fbcd093d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java @@ -42,15 +42,19 @@ */ package org.eclipse.jgit.merge; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.util.Arrays; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.lib.RefUpdate; 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}. @@ -60,7 +64,8 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { private MergeMessageFormatter formatter; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); RefUpdate createRemoteRefA = db @@ -76,6 +81,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { formatter = new MergeMessageFormatter(); } + @Test public void testOneBranch() throws IOException { Ref a = db.getRef("refs/heads/a"); Ref master = db.getRef("refs/heads/master"); @@ -83,6 +89,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { assertEquals("Merge branch 'a'", message); } + @Test public void testTwoBranches() throws IOException { Ref a = db.getRef("refs/heads/a"); Ref b = db.getRef("refs/heads/b"); @@ -91,6 +98,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { assertEquals("Merge branches 'a' and 'b'", message); } + @Test public void testThreeBranches() throws IOException { Ref c = db.getRef("refs/heads/c"); Ref b = db.getRef("refs/heads/b"); @@ -100,6 +108,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { assertEquals("Merge branches 'c', 'b' and 'a'", message); } + @Test public void testRemoteBranch() throws Exception { Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); Ref master = db.getRef("refs/heads/master"); @@ -107,6 +116,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { assertEquals("Merge remote branch 'origin/remote-a'", message); } + @Test public void testMixed() throws IOException { Ref c = db.getRef("refs/heads/c"); Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); @@ -116,6 +126,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { message); } + @Test public void testTag() throws IOException { Ref tagA = db.getRef("refs/tags/A"); Ref master = db.getRef("refs/heads/master"); @@ -123,6 +134,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { assertEquals("Merge tag 'A'", message); } + @Test public void testCommit() throws IOException { ObjectId objectId = ObjectId .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4"); @@ -134,6 +146,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { message); } + @Test public void testPullWithUri() throws IOException { String name = "branch 'test' of http://egit.eclipse.org/jgit.git"; ObjectId objectId = ObjectId @@ -146,6 +159,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { message); } + @Test public void testIntoOtherThanMaster() throws IOException { Ref a = db.getRef("refs/heads/a"); Ref b = db.getRef("refs/heads/b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java index 659c9e3b2..dbf536165 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.merge; 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; @@ -59,9 +62,11 @@ import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Test; public class SimpleMergeTest extends SampleDataRepositoryTestCase { + @Test public void testOurs() throws IOException { Merger ourMerger = MergeStrategy.OURS.newMerger(db); 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()); } + @Test public void testTheirs() throws IOException { Merger ourMerger = MergeStrategy.THEIRS.newMerger(db); 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()); } + @Test public void testTrivialTwoWay() throws IOException { Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); 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()); } + @Test public void testTrivialTwoWay_disjointhistories() throws IOException { Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); 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()); } + @Test public void testTrivialTwoWay_ok() throws IOException { 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") }); @@ -97,12 +106,14 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertEquals(db.mapTree("a^0^0").getId(), ourMerger.getResultTreeId()); } + @Test public void testTrivialTwoWay_conflict() throws IOException { Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db); boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("f"), db.resolve("g") }); assertFalse(merge); } + @Test public void testTrivialTwoWay_validSubtreeSort() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); @@ -155,6 +166,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertFalse(tw.next()); } + @Test public void testTrivialTwoWay_concurrentSubtreeChange() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); @@ -202,6 +214,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertFalse(tw.next()); } + @Test public void testTrivialTwoWay_conflictSubtreeChange() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); @@ -235,6 +248,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertFalse(merge); } + @Test public void testTrivialTwoWay_leftDFconflict1() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); @@ -267,6 +281,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertFalse(merge); } + @Test public void testTrivialTwoWay_rightDFconflict1() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); @@ -299,6 +314,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertFalse(merge); } + @Test public void testTrivialTwoWay_leftDFconflict2() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); @@ -329,6 +345,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { assertFalse(merge); } + @Test public void testTrivialTwoWay_rightDFconflict2() throws Exception { final DirCache treeB = db.readDirCache(); final DirCache treeO = db.readDirCache(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/NonTranslatedBundle.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/NonTranslatedBundle.java index 9251af280..5fbc8fce3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/NonTranslatedBundle.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/NonTranslatedBundle.java @@ -43,9 +43,6 @@ package org.eclipse.jgit.nls; -import org.eclipse.jgit.nls.NLS; -import org.eclipse.jgit.nls.TranslationBundle; - public class NonTranslatedBundle extends TranslationBundle { public static NonTranslatedBundle get() { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestNLS.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestNLS.java index 8b02f2f5e..0ce73c354 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestNLS.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestNLS.java @@ -43,14 +43,15 @@ package org.eclipse.jgit.nls; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import java.util.Locale; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; -import junit.framework.TestCase; - - -public class TestNLS extends TestCase { +public class TestNLS { public void testNLSLocale() { NLS.setLocale(NLS.ROOT_LOCALE); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestTranslationBundle.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestTranslationBundle.java index 0b21bdbe0..8f8235de8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestTranslationBundle.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestTranslationBundle.java @@ -43,15 +43,18 @@ package org.eclipse.jgit.nls; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.util.Locale; import org.eclipse.jgit.errors.TranslationBundleLoadingException; import org.eclipse.jgit.errors.TranslationStringMissingException; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestTranslationBundle extends TestCase { +public class TestTranslationBundle { + @Test public void testMissingPropertiesFile() { try { new NoPropertiesBundle().load(NLS.ROOT_LOCALE); @@ -63,6 +66,7 @@ public class TestTranslationBundle extends TestCase { } } + @Test public void testMissingString() { try { new MissingPropertyBundle().load(NLS.ROOT_LOCALE); @@ -75,6 +79,7 @@ public class TestTranslationBundle extends TestCase { } } + @Test public void testNonTranslatedBundle() { NonTranslatedBundle bundle = new NonTranslatedBundle(); @@ -91,6 +96,7 @@ public class TestTranslationBundle extends TestCase { assertEquals("Good morning {0}", bundle.goodMorning); } + @Test public void testGermanTranslation() { GermanTranslatedBundle bundle = new GermanTranslatedBundle(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/LeafBucketTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/LeafBucketTest.java index 68b0e2b5e..7c4069553 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/LeafBucketTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/LeafBucketTest.java @@ -43,14 +43,18 @@ package org.eclipse.jgit.notes; -import java.io.IOException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; -import junit.framework.TestCase; +import java.io.IOException; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.MutableObjectId; +import org.junit.Test; -public class LeafBucketTest extends TestCase { +public class LeafBucketTest { + @Test public void testEmpty() { LeafBucket b = new LeafBucket(0); assertNull(b.get(id(0x00), null)); @@ -58,6 +62,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0xfe), null)); } + @Test public void testParseFive() { LeafBucket b = new LeafBucket(0); @@ -76,6 +81,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testSetFive_InOrder() throws IOException { LeafBucket b = new LeafBucket(0); @@ -94,6 +100,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testSetFive_ReverseOrder() throws IOException { LeafBucket b = new LeafBucket(0); @@ -112,6 +119,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testSetFive_MixedOrder() throws IOException { LeafBucket b = new LeafBucket(0); @@ -131,6 +139,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testSet_Replace() throws IOException { LeafBucket b = new LeafBucket(0); @@ -141,6 +150,7 @@ public class LeafBucketTest extends TestCase { assertEquals(id(0x01), b.get(id(0x11), null)); } + @Test public void testRemoveMissingNote() throws IOException { LeafBucket b = new LeafBucket(0); assertNull(b.get(id(0x11), null)); @@ -148,6 +158,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x11), null)); } + @Test public void testRemoveFirst() throws IOException { LeafBucket b = new LeafBucket(0); @@ -168,6 +179,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testRemoveMiddle() throws IOException { LeafBucket b = new LeafBucket(0); @@ -188,6 +200,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testRemoveLast() throws IOException { LeafBucket b = new LeafBucket(0); @@ -208,6 +221,7 @@ public class LeafBucketTest extends TestCase { assertNull(b.get(id(0x66), null)); } + @Test public void testRemoveMakesEmpty() throws IOException { LeafBucket b = new LeafBucket(0); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java index d740ffaf1..6c65b5364 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java @@ -43,6 +43,14 @@ package org.eclipse.jgit.notes; +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 static org.junit.Assert.assertTrue; + import java.io.IOException; import org.eclipse.jgit.junit.TestRepository; @@ -58,6 +66,9 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.util.RawParseUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class NoteMapTest extends RepositoryTestCase { private TestRepository tr; @@ -67,7 +78,8 @@ public class NoteMapTest extends RepositoryTestCase { private ObjectInserter inserter; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); tr = new TestRepository(db); @@ -76,12 +88,14 @@ public class NoteMapTest extends RepositoryTestCase { } @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { reader.release(); inserter.release(); super.tearDown(); } + @Test public void testReadFlatTwoNotes() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -106,6 +120,7 @@ public class NoteMapTest extends RepositoryTestCase { assertNull("no note for data1", map.get(data1)); } + @Test public void testReadFanout2_38() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -130,6 +145,7 @@ public class NoteMapTest extends RepositoryTestCase { assertNull("no note for data1", map.get(data1)); } + @Test public void testReadFanout2_2_36() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -154,6 +170,7 @@ public class NoteMapTest extends RepositoryTestCase { assertNull("no note for data1", map.get(data1)); } + @Test public void testReadFullyFannedOut() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -178,6 +195,7 @@ public class NoteMapTest extends RepositoryTestCase { assertNull("no note for data1", map.get(data1)); } + @Test public void testGetCachedBytes() throws Exception { final String exp = "this is test data"; RevBlob a = tr.blob("a"); @@ -194,6 +212,7 @@ public class NoteMapTest extends RepositoryTestCase { assertEquals(exp, RawParseUtils.decode(act)); } + @Test public void testWriteUnchangedFlat() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -217,6 +236,7 @@ public class NoteMapTest extends RepositoryTestCase { assertSame("same tree", r.getTree(), n.getTree()); } + @Test public void testWriteUnchangedFanout2_38() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -247,6 +267,7 @@ public class NoteMapTest extends RepositoryTestCase { assertSame("same tree", r.getTree(), n.getTree()); } + @Test public void testCreateFromEmpty() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -276,6 +297,7 @@ public class NoteMapTest extends RepositoryTestCase { assertFalse("no a", map.contains(a)); } + @Test public void testEditFlat() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -322,6 +344,7 @@ public class NoteMapTest extends RepositoryTestCase { .forPath(reader, "zoo-animals.txt", n.getTree()).getObjectId(0)); } + @Test public void testEditFanout2_38() throws Exception { RevBlob a = tr.blob("a"); RevBlob b = tr.blob("b"); @@ -362,6 +385,7 @@ public class NoteMapTest extends RepositoryTestCase { .forPath(reader, "zoo-animals.txt", n.getTree()).getObjectId(0)); } + @Test public void testLeafSplitsWhenFull() throws Exception { RevBlob data1 = tr.blob("data1"); MutableObjectId idBuf = new MutableObjectId(); @@ -402,6 +426,7 @@ public class NoteMapTest extends RepositoryTestCase { assertNotNull("has " + path, tw); } + @Test public void testRemoveDeletesTreeFanout2_38() throws Exception { RevBlob a = tr.blob("a"); RevBlob data1 = tr.blob("data1"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java index c265bc097..61bd8cf9c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/EditListTest.java @@ -43,15 +43,18 @@ package org.eclipse.jgit.patch; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.InputStream; -import junit.framework.TestCase; - import org.eclipse.jgit.diff.Edit; import org.eclipse.jgit.diff.EditList; +import org.junit.Test; -public class EditListTest extends TestCase { +public class EditListTest { + @Test public void testHunkHeader() throws IOException { final Patch p = parseTestPatchFile("testGetText_BothISO88591.patch"); final FileHeader fh = p.getFiles().get(0); @@ -65,6 +68,7 @@ public class EditListTest extends TestCase { assertEquals(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), list1.get(0)); } + @Test public void testFileHeader() throws IOException { final Patch p = parseTestPatchFile("testGetText_BothISO88591.patch"); final FileHeader fh = p.getFiles().get(0); @@ -74,6 +78,7 @@ public class EditListTest extends TestCase { assertEquals(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), e.get(1)); } + @Test public void testTypes() throws IOException { final Patch p = parseTestPatchFile("testEditList_Types.patch"); final FileHeader fh = p.getFiles().get(0); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java index 813a701ea..7b4e01444 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/FileHeaderTest.java @@ -43,14 +43,21 @@ package org.eclipse.jgit.patch; -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.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; +import org.junit.Test; -public class FileHeaderTest extends TestCase { +public class FileHeaderTest { + @Test public void testParseGitFileName_Empty() { final FileHeader fh = data(""); assertEquals(-1, fh.parseGitFileName(0, fh.buf.length)); @@ -59,21 +66,25 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_NoLF() { final FileHeader fh = data("a/ b/"); assertEquals(-1, fh.parseGitFileName(0, fh.buf.length)); } + @Test public void testParseGitFileName_NoSecondLine() { final FileHeader fh = data("\n"); assertEquals(-1, fh.parseGitFileName(0, fh.buf.length)); } + @Test public void testParseGitFileName_EmptyHeader() { final FileHeader fh = data("\n\n"); assertEquals(1, fh.parseGitFileName(0, fh.buf.length)); } + @Test public void testParseGitFileName_Foo() { final String name = "foo"; final FileHeader fh = header(name); @@ -84,6 +95,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_FailFooBar() { final FileHeader fh = data("a/foo b/bar\n-"); assertTrue(fh.parseGitFileName(0, fh.buf.length) > 0); @@ -92,6 +104,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_FooSpBar() { final String name = "foo bar"; final FileHeader fh = header(name); @@ -102,6 +115,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_DqFooTabBar() { final String name = "foo\tbar"; final String dqName = "foo\\tbar"; @@ -113,6 +127,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_DqFooSpLfNulBar() { final String name = "foo \n\0bar"; final String dqName = "foo \\n\\0bar"; @@ -124,6 +139,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_SrcFooC() { final String name = "src/foo/bar/argh/code.c"; final FileHeader fh = header(name); @@ -134,6 +150,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseGitFileName_SrcFooCNonStandardPrefix() { final String name = "src/foo/bar/argh/code.c"; final String header = "project-v-1.0/" + name + " mydev/" + name + "\n"; @@ -144,6 +161,7 @@ public class FileHeaderTest extends TestCase { assertFalse(fh.hasMetaDataChanges()); } + @Test public void testParseUnicodeName_NewFile() { final FileHeader fh = data("diff --git \"a/\\303\\205ngstr\\303\\266m\" \"b/\\303\\205ngstr\\303\\266m\"\n" + "new file mode 100644\n" @@ -169,6 +187,7 @@ public class FileHeaderTest extends TestCase { assertEquals(0, fh.getScore()); } + @Test public void testParseUnicodeName_DeleteFile() { final FileHeader fh = data("diff --git \"a/\\303\\205ngstr\\303\\266m\" \"b/\\303\\205ngstr\\303\\266m\"\n" + "deleted file mode 100644\n" @@ -194,6 +213,7 @@ public class FileHeaderTest extends TestCase { assertEquals(0, fh.getScore()); } + @Test public void testParseModeChange() { final FileHeader fh = data("diff --git a/a b b/a b\n" + "old mode 100644\n" + "new mode 100755\n"); @@ -213,6 +233,7 @@ public class FileHeaderTest extends TestCase { assertEquals(0, fh.getScore()); } + @Test public void testParseRename100_NewStyle() { final FileHeader fh = data("diff --git a/a b/ c/\\303\\205ngstr\\303\\266m\n" + "similarity index 100%\n" @@ -242,6 +263,7 @@ public class FileHeaderTest extends TestCase { assertEquals(100, fh.getScore()); } + @Test public void testParseRename100_OldStyle() { final FileHeader fh = data("diff --git a/a b/ c/\\303\\205ngstr\\303\\266m\n" + "similarity index 100%\n" @@ -271,6 +293,7 @@ public class FileHeaderTest extends TestCase { assertEquals(100, fh.getScore()); } + @Test public void testParseCopy100() { final FileHeader fh = data("diff --git a/a b/ c/\\303\\205ngstr\\303\\266m\n" + "similarity index 100%\n" @@ -300,6 +323,7 @@ public class FileHeaderTest extends TestCase { assertEquals(100, fh.getScore()); } + @Test public void testParseFullIndexLine_WithMode() { final String oid = "78981922613b2afb6025042ff6bd878ac1994e85"; final String nid = "61780798228d17af2d34fce4cfbdf35556832472"; @@ -324,6 +348,7 @@ public class FileHeaderTest extends TestCase { assertEquals(ObjectId.fromString(nid), fh.getNewId().toObjectId()); } + @Test public void testParseFullIndexLine_NoMode() { final String oid = "78981922613b2afb6025042ff6bd878ac1994e85"; final String nid = "61780798228d17af2d34fce4cfbdf35556832472"; @@ -348,6 +373,7 @@ public class FileHeaderTest extends TestCase { assertEquals(ObjectId.fromString(nid), fh.getNewId().toObjectId()); } + @Test public void testParseAbbrIndexLine_WithMode() { final int a = 7; final String oid = "78981922613b2afb6025042ff6bd878ac1994e85"; @@ -377,6 +403,7 @@ public class FileHeaderTest extends TestCase { assertTrue(ObjectId.fromString(nid).startsWith(fh.getNewId())); } + @Test public void testParseAbbrIndexLine_NoMode() { final int a = 7; final String oid = "78981922613b2afb6025042ff6bd878ac1994e85"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java index 8d06987fd..2aaf6afbe 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java @@ -43,14 +43,20 @@ package org.eclipse.jgit.patch; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; -import junit.framework.TestCase; +import org.eclipse.jgit.junit.JGitTestUtil; +import org.junit.Test; -public class GetTextTest extends TestCase { +public class GetTextTest { + @Test public void testGetText_BothISO88591() throws IOException { final Charset cs = Charset.forName("ISO-8859-1"); final Patch p = parseTestPatchFile(); @@ -61,6 +67,7 @@ public class GetTextTest extends TestCase { assertEquals(readTestPatchFile(cs), fh.getScriptText(cs, cs)); } + @Test public void testGetText_NoBinary() throws IOException { final Charset cs = Charset.forName("ISO-8859-1"); final Patch p = parseTestPatchFile(); @@ -71,6 +78,7 @@ public class GetTextTest extends TestCase { assertEquals(readTestPatchFile(cs), fh.getScriptText(cs, cs)); } + @Test public void testGetText_Convert() throws IOException { final Charset csOld = Charset.forName("ISO-8859-1"); final Charset csNew = Charset.forName("UTF-8"); @@ -90,6 +98,7 @@ public class GetTextTest extends TestCase { assertEquals(exp, fh.getScriptText(csOld, csNew)); } + @Test public void testGetText_DiffCc() throws IOException { final Charset csOld = Charset.forName("ISO-8859-1"); final Charset csNew = Charset.forName("UTF-8"); @@ -111,7 +120,7 @@ public class GetTextTest extends TestCase { } private Patch parseTestPatchFile() throws IOException { - final String patchFile = getName() + ".patch"; + final String patchFile = JGitTestUtil.getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); @@ -127,7 +136,7 @@ public class GetTextTest extends TestCase { } private String readTestPatchFile(final Charset cs) throws IOException { - final String patchFile = getName() + ".patch"; + final String patchFile = JGitTestUtil.getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java index 87bd9d386..1f9d5335f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java @@ -43,15 +43,21 @@ package org.eclipse.jgit.patch; +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.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import org.eclipse.jgit.JGitText; +import org.eclipse.jgit.junit.JGitTestUtil; +import org.junit.Test; -import junit.framework.TestCase; - -public class PatchCcErrorTest extends TestCase { +public class PatchCcErrorTest { + @Test public void testError_CcTruncatedOld() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -88,7 +94,7 @@ public class PatchCcErrorTest extends TestCase { } private Patch parseTestPatchFile() throws IOException { - final String patchFile = getName() + ".patch"; + final String patchFile = JGitTestUtil.getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java index cef13f5f1..837414b05 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java @@ -43,15 +43,21 @@ package org.eclipse.jgit.patch; +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.io.IOException; import java.io.InputStream; -import junit.framework.TestCase; - import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.FileMode; +import org.junit.Test; -public class PatchCcTest extends TestCase { +public class PatchCcTest { + @Test public void testParse_OneFileCc() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -107,6 +113,7 @@ public class PatchCcTest extends TestCase { } } + @Test public void testParse_CcNewFile() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -161,6 +168,7 @@ public class PatchCcTest extends TestCase { } } + @Test public void testParse_CcDeleteFile() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -190,7 +198,7 @@ public class PatchCcTest extends TestCase { } private Patch parseTestPatchFile() throws IOException { - final String patchFile = getName() + ".patch"; + final String patchFile = JGitTestUtil.getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java index 67b3f5c58..52e3874b6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java @@ -43,12 +43,20 @@ package org.eclipse.jgit.patch; +import static org.junit.Assert.assertEquals; +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.IOException; import java.io.InputStream; -import junit.framework.TestCase; +import org.eclipse.jgit.junit.JGitTestUtil; +import org.junit.Test; -public class PatchErrorTest extends TestCase { +public class PatchErrorTest { + @Test public void testError_DisconnectedHunk() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -68,6 +76,7 @@ public class PatchErrorTest extends TestCase { assertTrue(e.getLineText().startsWith("@@ -109,4 +109,11 @@ assert")); } + @Test public void testError_TruncatedOld() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -81,6 +90,7 @@ public class PatchErrorTest extends TestCase { assertTrue(e.getLineText().startsWith("@@ -236,9 +236,9 @@ protected ")); } + @Test public void testError_TruncatedNew() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -94,6 +104,7 @@ public class PatchErrorTest extends TestCase { assertTrue(e.getLineText().startsWith("@@ -236,9 +236,9 @@ protected ")); } + @Test public void testError_BodyTooLong() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -107,6 +118,7 @@ public class PatchErrorTest extends TestCase { assertTrue(e.getLineText().startsWith("@@ -109,4 +109,11 @@ assert")); } + @Test public void testError_GarbageBetweenFiles() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(2, p.getFiles().size()); @@ -133,6 +145,7 @@ public class PatchErrorTest extends TestCase { assertEquals("I AM NOT HERE\n", e.getLineText()); } + @Test public void testError_GitBinaryNoForwardHunk() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(2, p.getFiles().size()); @@ -163,7 +176,7 @@ public class PatchErrorTest extends TestCase { } private Patch parseTestPatchFile() throws IOException { - final String patchFile = getName() + ".patch"; + final String patchFile = JGitTestUtil.getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java index dd7625138..9f57ab98c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java @@ -43,21 +43,31 @@ package org.eclipse.jgit.patch; +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.IOException; import java.io.InputStream; -import junit.framework.TestCase; - +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; +import org.junit.Test; -public class PatchTest extends TestCase { +public class PatchTest { + @Test public void testEmpty() { final Patch p = new Patch(); assertTrue(p.getFiles().isEmpty()); assertTrue(p.getErrors().isEmpty()); } + @Test public void testParse_ConfigCaseInsensitive() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(2, p.getFiles().size()); @@ -155,6 +165,7 @@ public class PatchTest extends TestCase { } } + @Test public void testParse_NoBinary() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(5, p.getFiles().size()); @@ -190,6 +201,7 @@ public class PatchTest extends TestCase { assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } + @Test public void testParse_GitBinaryLiteral() throws IOException { final Patch p = parseTestPatchFile(); final int[] binsizes = { 359, 393, 372, 404 }; @@ -235,6 +247,7 @@ public class PatchTest extends TestCase { assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } + @Test public void testParse_GitBinaryDelta() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -272,6 +285,7 @@ public class PatchTest extends TestCase { assertEquals(496, fh.endOffset); } + @Test public void testParse_FixNoNewline() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -306,6 +320,7 @@ public class PatchTest extends TestCase { } } + @Test public void testParse_AddNoNewline() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); @@ -341,7 +356,7 @@ public class PatchTest extends TestCase { } private Patch parseTestPatchFile() throws IOException { - final String patchFile = getName() + ".patch"; + final String patchFile = JGitTestUtil.getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revplot/PlotCommitListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revplot/PlotCommitListTest.java index b8e1df788..e2dab2989 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revplot/PlotCommitListTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revplot/PlotCommitListTest.java @@ -42,8 +42,12 @@ */ package org.eclipse.jgit.revplot; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalkTestCase; +import org.junit.Test; public class PlotCommitListTest extends RevWalkTestCase { @@ -88,6 +92,7 @@ public class PlotCommitListTest extends RevWalkTestCase { } @SuppressWarnings("boxing") + @Test public void testLinear() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -108,6 +113,7 @@ public class PlotCommitListTest extends RevWalkTestCase { } @SuppressWarnings("boxing") + @Test public void testMerged() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -130,6 +136,7 @@ public class PlotCommitListTest extends RevWalkTestCase { } @SuppressWarnings("boxing") + @Test public void testSideBranch() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -151,6 +158,7 @@ public class PlotCommitListTest extends RevWalkTestCase { } @SuppressWarnings("boxing") + @Test public void test2SideBranches() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -175,6 +183,7 @@ public class PlotCommitListTest extends RevWalkTestCase { } @SuppressWarnings("boxing") + @Test public void testBug300282_1() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -212,6 +221,7 @@ public class PlotCommitListTest extends RevWalkTestCase { } // test the history of the egit project between 9fdaf3c1 and e76ad9170f + @Test public void testEgitHistory() throws Exception { final RevCommit merge_fix = commit(); final RevCommit add_simple = commit(merge_fix); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/AlwaysEmptyRevQueueTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/AlwaysEmptyRevQueueTest.java index d752501c1..366e0ccec 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/AlwaysEmptyRevQueueTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/AlwaysEmptyRevQueueTest.java @@ -43,9 +43,18 @@ package org.eclipse.jgit.revwalk; +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 org.junit.Test; + public class AlwaysEmptyRevQueueTest extends RevWalkTestCase { private final AbstractRevQueue q = AbstractRevQueue.EMPTY_QUEUE; + @Test public void testEmpty() throws Exception { assertNull(q.next()); assertTrue(q.everbodyHasFlag(RevWalk.UNINTERESTING)); @@ -53,11 +62,13 @@ public class AlwaysEmptyRevQueueTest extends RevWalkTestCase { assertEquals(0, q.outputType()); } + @Test public void testClear() throws Exception { q.clear(); testEmpty(); } + @Test public void testAddFails() throws Exception { try { q.add(commit()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java index ee9c81cbd..766a27986 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java @@ -43,22 +43,31 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + public class DateRevQueueTest extends RevQueueTestCase { protected DateRevQueue create() { return new DateRevQueue(); } + @Test public void testEmpty() throws Exception { super.testEmpty(); assertNull(q.peek()); assertEquals(Generator.SORT_COMMIT_TIME_DESC, q.outputType()); } + @Test public void testCloneEmpty() throws Exception { q = new DateRevQueue(AbstractRevQueue.EMPTY_QUEUE); assertNull(q.next()); } + @Test public void testInsertOutOfOrder() throws Exception { final RevCommit a = parseBody(commit()); final RevCommit b = parseBody(commit(10, a)); @@ -77,6 +86,7 @@ public class DateRevQueueTest extends RevQueueTestCase { assertNull(q.next()); } + @Test public void testInsertTie() throws Exception { final RevCommit a = parseBody(commit()); final RevCommit b = parseBody(commit(0, a)); @@ -100,6 +110,7 @@ public class DateRevQueueTest extends RevQueueTestCase { } } + @Test public void testCloneFIFO() throws Exception { final RevCommit a = parseBody(commit()); final RevCommit b = parseBody(commit(200, a)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FIFORevQueueTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FIFORevQueueTest.java index 3f4daab9f..8877c380d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FIFORevQueueTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FIFORevQueueTest.java @@ -43,23 +43,32 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import java.util.ArrayList; +import org.junit.Test; + public class FIFORevQueueTest extends RevQueueTestCase { protected FIFORevQueue create() { return new FIFORevQueue(); } + @Test public void testEmpty() throws Exception { super.testEmpty(); assertEquals(0, q.outputType()); } + @Test public void testCloneEmpty() throws Exception { q = new FIFORevQueue(AbstractRevQueue.EMPTY_QUEUE); assertNull(q.next()); } + @Test public void testAddLargeBlocks() throws Exception { final ArrayList lst = new ArrayList(); for (int i = 0; i < 3 * BlockRevQueue.Block.BLOCK_SIZE; i++) { @@ -71,6 +80,7 @@ public class FIFORevQueueTest extends RevQueueTestCase { assertSame(lst.get(i), q.next()); } + @Test public void testUnpopAtFront() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java index 9538a06b4..7f440df22 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FooterLineTest.java @@ -43,13 +43,21 @@ package org.eclipse.jgit.revwalk; +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 java.util.List; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class FooterLineTest extends RepositoryTestCase { + @Test public void testNoFooters_EmptyBody() { final RevCommit commit = parse(""); final List footers = commit.getFooterLines(); @@ -57,6 +65,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testNoFooters_NewlineOnlyBody1() { final RevCommit commit = parse("\n"); final List footers = commit.getFooterLines(); @@ -64,6 +73,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testNoFooters_NewlineOnlyBody5() { final RevCommit commit = parse("\n\n\n\n\n"); final List footers = commit.getFooterLines(); @@ -71,6 +81,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testNoFooters_OneLineBodyNoLF() { final RevCommit commit = parse("this is a commit"); final List footers = commit.getFooterLines(); @@ -78,6 +89,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testNoFooters_OneLineBodyWithLF() { final RevCommit commit = parse("this is a commit\n"); final List footers = commit.getFooterLines(); @@ -85,6 +97,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testNoFooters_ShortBodyNoLF() { final RevCommit commit = parse("subject\n\nbody of commit"); final List footers = commit.getFooterLines(); @@ -92,6 +105,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testNoFooters_ShortBodyWithLF() { final RevCommit commit = parse("subject\n\nbody of commit\n"); final List footers = commit.getFooterLines(); @@ -99,6 +113,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals(0, footers.size()); } + @Test public void testSignedOffBy_OneUserNoLF() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by: A. U. Thor "); @@ -114,6 +129,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("a@example.com", f.getEmailAddress()); } + @Test public void testSignedOffBy_OneUserWithLF() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by: A. U. Thor \n"); @@ -129,6 +145,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("a@example.com", f.getEmailAddress()); } + @Test public void testSignedOffBy_IgnoreWhitespace() { // We only ignore leading whitespace on the value, trailing // is assumed part of the value. @@ -147,6 +164,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("a@example.com", f.getEmailAddress()); } + @Test public void testEmptyValueNoLF() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by:"); @@ -162,6 +180,7 @@ public class FooterLineTest extends RepositoryTestCase { assertNull(f.getEmailAddress()); } + @Test public void testEmptyValueWithLF() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Signed-off-by:\n"); @@ -177,6 +196,7 @@ public class FooterLineTest extends RepositoryTestCase { assertNull(f.getEmailAddress()); } + @Test public void testShortKey() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "K:V\n"); @@ -192,6 +212,7 @@ public class FooterLineTest extends RepositoryTestCase { assertNull(f.getEmailAddress()); } + @Test public void testNonDelimtedEmail() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Acked-by: re@example.com\n"); @@ -207,6 +228,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("re@example.com", f.getEmailAddress()); } + @Test public void testNotEmail() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n" + "Acked-by: Main Tain Er\n"); @@ -222,6 +244,7 @@ public class FooterLineTest extends RepositoryTestCase { assertNull(f.getEmailAddress()); } + @Test public void testSignedOffBy_ManyUsers() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "Not-A-Footer-Line: this line must not be read as a footer\n" @@ -257,6 +280,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("mte@example.com", f.getEmailAddress()); } + @Test public void testSignedOffBy_SkipNonFooter() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "Not-A-Footer-Line: this line must not be read as a footer\n" @@ -289,6 +313,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("Main Tain Er ", f.getValue()); } + @Test public void testFilterFootersIgnoreCase() { final RevCommit commit = parse("subject\n\nbody of commit\n" + "Not-A-Footer-Line: this line must not be read as a footer\n" @@ -306,6 +331,7 @@ public class FooterLineTest extends RepositoryTestCase { assertEquals("Main Tain Er ", footers.get(1)); } + @Test public void testMatchesBugId() { final RevCommit commit = parse("this is a commit subject for test\n" + "\n" // paragraph break, now footers appear in final block diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/LIFORevQueueTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/LIFORevQueueTest.java index 7676a7150..1b2c5e2f6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/LIFORevQueueTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/LIFORevQueueTest.java @@ -43,24 +43,33 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import java.util.ArrayList; import java.util.Collections; +import org.junit.Test; + public class LIFORevQueueTest extends RevQueueTestCase { protected LIFORevQueue create() { return new LIFORevQueue(); } + @Test public void testEmpty() throws Exception { super.testEmpty(); assertEquals(0, q.outputType()); } + @Test public void testCloneEmpty() throws Exception { q = new LIFORevQueue(AbstractRevQueue.EMPTY_QUEUE); assertNull(q.next()); } + @Test public void testAddLargeBlocks() throws Exception { final ArrayList lst = new ArrayList(); for (int i = 0; i < 3 * BlockRevQueue.Block.BLOCK_SIZE; i++) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java index 840bee846..f183e0298 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java @@ -43,11 +43,16 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileTreeEntry; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.Tree; +import org.junit.Test; public class ObjectWalkTest extends RevWalkTestCase { protected ObjectWalk objw; @@ -57,11 +62,13 @@ public class ObjectWalkTest extends RevWalkTestCase { return objw = new ObjectWalk(db); } + @Test public void testNoCommits() throws Exception { assertNull(objw.next()); assertNull(objw.nextObject()); } + @Test public void testTwoCommitsEmptyTree() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -75,6 +82,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertNull(objw.nextObject()); } + @Test public void testOneCommitOneTreeTwoBlob() throws Exception { final RevBlob f0 = blob("0"); final RevBlob f1 = blob("1"); @@ -91,6 +99,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertNull(objw.nextObject()); } + @Test public void testTwoCommitTwoTreeTwoBlob() throws Exception { final RevBlob f0 = blob("0"); final RevBlob f1 = blob("1"); @@ -115,6 +124,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertNull(objw.nextObject()); } + @Test public void testTwoCommitDeepTree1() throws Exception { final RevBlob f0 = blob("0"); final RevBlob f1 = blob("0v2"); @@ -141,6 +151,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertNull(objw.nextObject()); } + @Test public void testTwoCommitDeepTree2() throws Exception { final RevBlob f1 = blob("1"); final RevTree ta = tree(file("a/b/0", f1), file("a/c/q", f1)); @@ -166,6 +177,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertNull(objw.nextObject()); } + @Test public void testCull() throws Exception { final RevBlob f1 = blob("1"); final RevBlob f2 = blob("2"); @@ -201,6 +213,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertNull(objw.nextObject()); } + @Test public void testEmptyTreeCorruption() throws Exception { ObjectId bId = ObjectId .fromString("abbbfafe3129f85747aba7bfac992af77134c607"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java index 2f2784734..02a78a5ba 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java @@ -43,6 +43,11 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; import java.util.TimeZone; @@ -53,8 +58,10 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class RevCommitParseTest extends RepositoryTestCase { + @Test public void testParse_NoParents() throws Exception { final ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); final String authorName = "A U. Thor"; @@ -139,6 +146,7 @@ public class RevCommitParseTest extends RepositoryTestCase { return c; } + @Test public void testParse_WeirdHeaderOnlyCommit() throws Exception { final StringBuilder b = new StringBuilder(); b.append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); @@ -153,6 +161,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals("", c.getShortMessage()); } + @Test public void testParse_implicit_UTF8_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); @@ -172,6 +181,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); } + @Test public void testParse_implicit_mixed_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); @@ -196,6 +206,7 @@ public class RevCommitParseTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testParse_explicit_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("EUC-JP")); @@ -225,6 +236,7 @@ public class RevCommitParseTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testParse_explicit_bad_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); @@ -255,6 +267,7 @@ public class RevCommitParseTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testParse_explicit_bad_encoded2() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); @@ -275,6 +288,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage()); } + @Test public void testParse_NoMessage() throws Exception { final String msg = ""; final RevCommit c = create(msg); @@ -282,12 +296,14 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals(msg, c.getShortMessage()); } + @Test public void testParse_OnlyLFMessage() throws Exception { final RevCommit c = create("\n"); assertEquals("\n", c.getFullMessage()); assertEquals("", c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyNoLF() throws Exception { final String shortMsg = "This is a short message."; final RevCommit c = create(shortMsg); @@ -295,6 +311,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyEndLF() throws Exception { final String shortMsg = "This is a short message."; final String fullMsg = shortMsg + "\n"; @@ -303,6 +320,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyEmbeddedLF() throws Exception { final String fullMsg = "This is a\nshort message."; final String shortMsg = fullMsg.replace('\n', ' '); @@ -311,6 +329,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyEmbeddedAndEndingLF() throws Exception { final String fullMsg = "This is a\nshort message.\n"; final String shortMsg = "This is a short message."; @@ -319,6 +338,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_GitStyleMessage() throws Exception { final String shortMsg = "This fixes a bug."; final String body = "We do it with magic and pixie dust and stuff.\n" @@ -329,6 +349,7 @@ public class RevCommitParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_PublicParseMethod() throws UnsupportedEncodingException { ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevFlagSetTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevFlagSetTest.java index 13f1cfc4c..021795eef 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevFlagSetTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevFlagSetTest.java @@ -43,10 +43,19 @@ package org.eclipse.jgit.revwalk; +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.Arrays; import java.util.Iterator; +import org.junit.Test; + public class RevFlagSetTest extends RevWalkTestCase { + @Test public void testEmpty() { final RevFlagSet set = new RevFlagSet(); assertEquals(0, set.mask); @@ -55,6 +64,7 @@ public class RevFlagSetTest extends RevWalkTestCase { assertFalse(set.iterator().hasNext()); } + @Test public void testAddOne() { final String flagName = "flag"; final RevFlag flag = rw.newFlag(flagName); @@ -72,6 +82,7 @@ public class RevFlagSetTest extends RevWalkTestCase { assertFalse(i.hasNext()); } + @Test public void testAddTwo() { final RevFlag flag1 = rw.newFlag("flag_1"); final RevFlag flag2 = rw.newFlag("flag_2"); @@ -84,6 +95,7 @@ public class RevFlagSetTest extends RevWalkTestCase { assertEquals(2, set.size()); } + @Test public void testContainsAll() { final RevFlag flag1 = rw.newFlag("flag_1"); final RevFlag flag2 = rw.newFlag("flag_2"); @@ -100,6 +112,7 @@ public class RevFlagSetTest extends RevWalkTestCase { assertFalse(set1.containsAll(set2)); } + @Test public void testEquals() { final RevFlag flag1 = rw.newFlag("flag_1"); final RevFlag flag2 = rw.newFlag("flag_2"); @@ -112,6 +125,7 @@ public class RevFlagSetTest extends RevWalkTestCase { .equals(set)); } + @Test public void testRemove() { final RevFlag flag1 = rw.newFlag("flag_1"); final RevFlag flag2 = rw.newFlag("flag_2"); @@ -125,6 +139,7 @@ public class RevFlagSetTest extends RevWalkTestCase { assertFalse(set.contains(flag1)); } + @Test public void testContains() { final RevFlag flag1 = rw.newFlag("flag_1"); final RevFlag flag2 = rw.newFlag("flag_2"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java index 052d39003..a768bef19 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java @@ -43,15 +43,24 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; public class RevObjectTest extends RevWalkTestCase { + @Test public void testId() throws Exception { final RevCommit a = commit(); assertSame(a, a.getId()); } + @Test public void testEquals() throws Exception { final RevCommit a1 = commit(); final RevCommit b1 = commit(); @@ -80,6 +89,7 @@ public class RevObjectTest extends RevWalkTestCase { assertTrue(AnyObjectId.equals(b1, b2)); } + @Test public void testRevObjectTypes() throws Exception { assertEquals(Constants.OBJ_TREE, tree().getType()); assertEquals(Constants.OBJ_COMMIT, commit().getType()); @@ -87,6 +97,7 @@ public class RevObjectTest extends RevWalkTestCase { assertEquals(Constants.OBJ_TAG, tag("emptyTree", tree()).getType()); } + @Test public void testHasRevFlag() throws Exception { final RevCommit a = commit(); assertFalse(a.has(RevFlag.UNINTERESTING)); @@ -94,6 +105,7 @@ public class RevObjectTest extends RevWalkTestCase { assertTrue(a.has(RevFlag.UNINTERESTING)); } + @Test public void testHasAnyFlag() throws Exception { final RevCommit a = commit(); final RevFlag flag1 = rw.newFlag("flag1"); @@ -107,6 +119,7 @@ public class RevObjectTest extends RevWalkTestCase { assertTrue(a.hasAny(s)); } + @Test public void testHasAllFlag() throws Exception { final RevCommit a = commit(); final RevFlag flag1 = rw.newFlag("flag1"); @@ -122,6 +135,7 @@ public class RevObjectTest extends RevWalkTestCase { assertTrue(a.hasAll(s)); } + @Test public void testAddRevFlag() throws Exception { final RevCommit a = commit(); final RevFlag flag1 = rw.newFlag("flag1"); @@ -135,6 +149,7 @@ public class RevObjectTest extends RevWalkTestCase { assertEquals(flag1.mask | flag2.mask, a.flags); } + @Test public void testAddRevFlagSet() throws Exception { final RevCommit a = commit(); final RevFlag flag1 = rw.newFlag("flag1"); @@ -149,6 +164,7 @@ public class RevObjectTest extends RevWalkTestCase { assertEquals(flag1.mask | flag2.mask, a.flags); } + @Test public void testRemoveRevFlag() throws Exception { final RevCommit a = commit(); final RevFlag flag1 = rw.newFlag("flag1"); @@ -160,6 +176,7 @@ public class RevObjectTest extends RevWalkTestCase { assertEquals(flag1.mask, a.flags); } + @Test public void testRemoveRevFlagSet() throws Exception { final RevCommit a = commit(); final RevFlag flag1 = rw.newFlag("flag1"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java index c549054cb..51cf2f1b3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java @@ -43,6 +43,12 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + public abstract class RevQueueTestCase extends RevWalkTestCase { protected T q; @@ -54,12 +60,14 @@ public abstract class RevQueueTestCase extends protected abstract T create(); + @Test public void testEmpty() throws Exception { assertNull(q.next()); assertTrue(q.everbodyHasFlag(RevWalk.UNINTERESTING)); assertFalse(q.anybodyHasFlag(RevWalk.UNINTERESTING)); } + @Test public void testClear() throws Exception { final RevCommit a = parseBody(commit()); final RevCommit b = parseBody(commit(a)); @@ -70,6 +78,7 @@ public abstract class RevQueueTestCase extends assertNull(q.next()); } + @Test public void testHasFlags() throws Exception { final RevCommit a = parseBody(commit()); final RevCommit b = parseBody(commit(a)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java index 9300ae2e1..c89a2873a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java @@ -43,6 +43,11 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + import java.io.ByteArrayOutputStream; import org.eclipse.jgit.errors.CorruptObjectException; @@ -52,20 +57,25 @@ import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.TagBuilder; +import org.junit.Test; public class RevTagParseTest extends RepositoryTestCase { + @Test public void testTagBlob() throws Exception { testOneType(Constants.OBJ_BLOB); } + @Test public void testTagTree() throws Exception { testOneType(Constants.OBJ_TREE); } + @Test public void testTagCommit() throws Exception { testOneType(Constants.OBJ_COMMIT); } + @Test public void testTagTag() throws Exception { testOneType(Constants.OBJ_TAG); } @@ -92,6 +102,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertSame(rw.lookupAny(id, typeCode), c.getObject()); } + @Test public void testParseAllFields() throws Exception { final ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); final String name = "v1.2.3.4.5"; @@ -143,6 +154,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(taggerEmail, cTagger.getEmailAddress()); } + @Test public void testParseOldStyleNoTagger() throws Exception { final ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); final String name = "v1.2.3.4.5"; @@ -203,6 +215,7 @@ public class RevTagParseTest extends RepositoryTestCase { return c; } + @Test public void testParse_implicit_UTF8_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" @@ -227,6 +240,7 @@ public class RevTagParseTest extends RepositoryTestCase { .getFullMessage()); } + @Test public void testParse_implicit_mixed_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" @@ -255,6 +269,7 @@ public class RevTagParseTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testParse_explicit_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" @@ -287,6 +302,7 @@ public class RevTagParseTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testParse_explicit_bad_encoded() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" @@ -321,6 +337,7 @@ public class RevTagParseTest extends RepositoryTestCase { * * @throws Exception */ + @Test public void testParse_explicit_bad_encoded2() throws Exception { final ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" @@ -344,6 +361,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage()); } + @Test public void testParse_NoMessage() throws Exception { final String msg = ""; final RevTag c = create(msg); @@ -351,12 +369,14 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(msg, c.getShortMessage()); } + @Test public void testParse_OnlyLFMessage() throws Exception { final RevTag c = create("\n"); assertEquals("\n", c.getFullMessage()); assertEquals("", c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyNoLF() throws Exception { final String shortMsg = "This is a short message."; final RevTag c = create(shortMsg); @@ -364,6 +384,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyEndLF() throws Exception { final String shortMsg = "This is a short message."; final String fullMsg = shortMsg + "\n"; @@ -372,6 +393,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyEmbeddedLF() throws Exception { final String fullMsg = "This is a\nshort message."; final String shortMsg = fullMsg.replace('\n', ' '); @@ -380,6 +402,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_ShortLineOnlyEmbeddedAndEndingLF() throws Exception { final String fullMsg = "This is a\nshort message.\n"; final String shortMsg = "This is a short message."; @@ -388,6 +411,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_GitStyleMessage() throws Exception { final String shortMsg = "This fixes a bug."; final String body = "We do it with magic and pixie dust and stuff.\n" @@ -398,6 +422,7 @@ public class RevTagParseTest extends RepositoryTestCase { assertEquals(shortMsg, c.getShortMessage()); } + @Test public void testParse_PublicParseMethod() throws CorruptObjectException { ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); TagBuilder src = new TagBuilder(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java index 9e879c5f0..fb52828c5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java @@ -43,7 +43,12 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + public class RevWalkCullTest extends RevWalkTestCase { + @Test public void testProperlyCullAllAncestors1() throws Exception { // Credit goes to Junio C Hamano for this // test case in git-core (t/t6009-rev-list-parent.sh) @@ -60,6 +65,7 @@ public class RevWalkCullTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testProperlyCullAllAncestors2() throws Exception { // Despite clock skew on c1 being very old it should not // produce, neither should a or b, or any part of that chain. @@ -77,6 +83,7 @@ public class RevWalkCullTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testProperlyCullAllAncestors_LongHistory() throws Exception { final RevCommit a = commit(); RevCommit b = commit(a); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java index a6421c41d..dd67a9833 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java @@ -43,6 +43,9 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.io.IOException; import java.util.Date; @@ -54,10 +57,12 @@ import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter; import org.eclipse.jgit.revwalk.filter.NotRevFilter; import org.eclipse.jgit.revwalk.filter.OrRevFilter; import org.eclipse.jgit.revwalk.filter.RevFilter; +import org.junit.Test; public class RevWalkFilterTest extends RevWalkTestCase { private static final MyAll MY_ALL = new MyAll(); + @Test public void testFilter_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -71,6 +76,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_Negate_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -81,6 +87,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NOT_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -91,6 +98,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NONE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -101,6 +109,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NOT_NONE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -114,6 +123,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_ALL_And_NONE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -124,6 +134,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NONE_And_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -134,6 +145,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_ALL_Or_NONE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -147,6 +159,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NONE_Or_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -160,6 +173,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_MY_ALL_And_NONE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -170,6 +184,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NONE_And_MY_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -180,6 +195,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_MY_ALL_Or_NONE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -193,6 +209,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NONE_Or_MY_ALL() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -206,6 +223,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testFilter_NO_MERGES() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -224,6 +242,7 @@ public class RevWalkFilterTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testCommitTimeRevFilter() throws Exception { final RevCommit a = commit(); tick(100); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergeBaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergeBaseTest.java index 10c9f9b12..b5d4909f3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergeBaseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergeBaseTest.java @@ -43,10 +43,15 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import org.eclipse.jgit.revwalk.filter.RevFilter; import org.eclipse.jgit.treewalk.filter.TreeFilter; +import org.junit.Test; public class RevWalkMergeBaseTest extends RevWalkTestCase { + @Test public void testNone() throws Exception { final RevCommit c1 = commit(commit(commit())); final RevCommit c2 = commit(commit(commit())); @@ -57,6 +62,7 @@ public class RevWalkMergeBaseTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testDisallowTreeFilter() throws Exception { final RevCommit c1 = commit(); final RevCommit c2 = commit(); @@ -73,6 +79,7 @@ public class RevWalkMergeBaseTest extends RevWalkTestCase { } } + @Test public void testSimple() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -86,6 +93,7 @@ public class RevWalkMergeBaseTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testMultipleHeads_SameBase1() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -101,6 +109,7 @@ public class RevWalkMergeBaseTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testMultipleHeads_SameBase2() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -117,6 +126,7 @@ public class RevWalkMergeBaseTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testCrissCross() throws Exception { // See http://marc.info/?l=git&m=111463358500362&w=2 for a nice // description of what this test is creating. We don't have a diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java index 986a88656..d2083e6b5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java @@ -43,11 +43,15 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.util.Collections; import org.eclipse.jgit.treewalk.filter.AndTreeFilter; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.TreeFilter; +import org.junit.Test; public class RevWalkPathFilter1Test extends RevWalkTestCase { protected void filter(final String path) { @@ -56,6 +60,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { TreeFilter.ANY_DIFF)); } + @Test public void testEmpty_EmptyTree() throws Exception { final RevCommit a = commit(); filter("a"); @@ -63,6 +68,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testEmpty_NoMatch() throws Exception { final RevCommit a = commit(tree(file("0", blob("0")))); filter("a"); @@ -70,6 +76,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSimple1() throws Exception { final RevCommit a = commit(tree(file("0", blob("0")))); filter("0"); @@ -78,6 +85,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testEdits_MatchNone() throws Exception { final RevCommit a = commit(tree(file("0", blob("a")))); final RevCommit b = commit(tree(file("0", blob("b"))), a); @@ -88,6 +96,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testEdits_MatchAll() throws Exception { final RevCommit a = commit(tree(file("0", blob("a")))); final RevCommit b = commit(tree(file("0", blob("b"))), a); @@ -102,6 +111,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testStringOfPearls_FilePath1() throws Exception { final RevCommit a = commit(tree(file("d/f", blob("a")))); final RevCommit b = commit(tree(file("d/f", blob("a"))), a); @@ -118,6 +128,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testStringOfPearls_FilePath2() throws Exception { final RevCommit a = commit(tree(file("d/f", blob("a")))); final RevCommit b = commit(tree(file("d/f", blob("a"))), a); @@ -136,6 +147,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testStringOfPearls_DirPath2() throws Exception { final RevCommit a = commit(tree(file("d/f", blob("a")))); final RevCommit b = commit(tree(file("d/f", blob("a"))), a); @@ -154,6 +166,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testStringOfPearls_FilePath3() throws Exception { final RevCommit a = commit(tree(file("d/f", blob("a")))); final RevCommit b = commit(tree(file("d/f", blob("a"))), a); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java index c4bfbf881..db19f004d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java @@ -43,6 +43,9 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.lang.reflect.Field; import java.util.Collections; import java.util.HashMap; @@ -50,6 +53,8 @@ import java.util.HashMap; import org.eclipse.jgit.treewalk.filter.AndTreeFilter; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.TreeFilter; +import org.junit.Before; +import org.junit.Test; // Note: Much of this test case is broken as it depends upon // the graph applying topological sorting *before* doing merge @@ -64,6 +69,7 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { private HashMap byName; + @Before public void setUp() throws Exception { super.setUp(); @@ -120,11 +126,13 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { TreeFilter.ANY_DIFF)); } + @Test public void test1() throws Exception { // TODO --full-history check(i, h, g, f, e, d, c, b, a); } + @Test public void test2() throws Exception { // TODO --full-history filter(pF); @@ -132,6 +140,7 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { // check(i, h, e, c, b, a); } + @Test public void test3() throws Exception { // TODO --full-history rw.sort(RevSort.TOPO); @@ -140,6 +149,7 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { // check(i, h, e, c, b, a); } + @Test public void test4() throws Exception { // TODO --full-history rw.sort(RevSort.COMMIT_TIME_DESC); @@ -148,6 +158,7 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { // check(i, h, e, c, b, a); } + @Test public void test5() throws Exception { // TODO --simplify-merges filter(pF); @@ -155,11 +166,13 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { // check(i, e, c, b, a); } + @Test public void test6() throws Exception { filter(pF); check(i, b, a); } + @Test public void test7() throws Exception { rw.sort(RevSort.TOPO); filter(pF); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java index 65ed873bf..5a1f5a721 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java @@ -43,7 +43,13 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + public class RevWalkSortTest extends RevWalkTestCase { + @Test public void testSort_Default() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(1, a); @@ -58,6 +64,7 @@ public class RevWalkSortTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSort_COMMIT_TIME_DESC() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -73,6 +80,7 @@ public class RevWalkSortTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSort_REVERSE() throws Exception { final RevCommit a = commit(); final RevCommit b = commit(a); @@ -88,6 +96,7 @@ public class RevWalkSortTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSort_COMMIT_TIME_DESC_OutOfOrder1() throws Exception { // Despite being out of order time-wise, a strand-of-pearls must // still maintain topological order. @@ -108,6 +117,7 @@ public class RevWalkSortTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSort_COMMIT_TIME_DESC_OutOfOrder2() throws Exception { // c1 is back dated before its parent. // @@ -127,6 +137,7 @@ public class RevWalkSortTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSort_TOPO() throws Exception { // c1 is back dated before its parent. // @@ -146,6 +157,7 @@ public class RevWalkSortTest extends RevWalkTestCase { assertNull(rw.next()); } + @Test public void testSort_TOPO_REVERSE() throws Exception { // c1 is back dated before its parent. // diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java index 9473fe631..1e05e53cb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.revwalk; +import static org.junit.Assert.assertSame; + import java.util.Date; import org.eclipse.jgit.dircache.DirCacheEntry; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java index 25e7aa3a1..2f989e32c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java @@ -45,6 +45,10 @@ package org.eclipse.jgit.storage.file; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; +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.BufferedOutputStream; import java.io.ByteArrayOutputStream; @@ -64,6 +68,9 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.transport.PackedObjectInfo; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class AbbreviationTest extends LocalDiskRepositoryTestCase { private FileRepository db; @@ -72,6 +79,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase { private TestRepository test; + @Before public void setUp() throws Exception { super.setUp(); db = createBareRepository(); @@ -79,11 +87,13 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase { test = new TestRepository(db); } + @After public void tearDown() throws Exception { if (reader != null) reader.release(); } + @Test public void testAbbreviateOnEmptyRepository() throws IOException { ObjectId id = id("9d5b926ed164e8ee88d3b8b1e525d699adda01ba"); @@ -108,6 +118,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase { assertEquals(id, matches.iterator().next()); } + @Test public void testAbbreviateLooseBlob() throws Exception { ObjectId id = test.blob("test"); @@ -125,6 +136,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase { assertEquals(id, db.resolve(reader.abbreviate(id, 8).name())); } + @Test public void testAbbreviatePackedBlob() throws Exception { RevBlob id = test.blob("test"); test.branch("master").commit().add("test", id).child(); @@ -144,6 +156,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase { assertEquals(id, db.resolve(reader.abbreviate(id, 8).name())); } + @Test public void testAbbreviateIsActuallyUnique() throws Exception { // This test is far more difficult. We have to manually craft // an input that contains collisions at a particular prefix, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java index 66b02cb46..ba9aa2499 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java @@ -44,6 +44,13 @@ package org.eclipse.jgit.storage.file; +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.assertTrue; +import static org.junit.Assert.fail; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -65,8 +72,12 @@ import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.pack.PackWriter; import org.eclipse.jgit.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class ConcurrentRepackTest extends RepositoryTestCase { + @Before public void setUp() throws Exception { WindowCacheConfig windowCacheConfig = new WindowCacheConfig(); windowCacheConfig.setPackedGitOpenFiles(1); @@ -74,12 +85,14 @@ public class ConcurrentRepackTest extends RepositoryTestCase { super.setUp(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { super.tearDown(); WindowCacheConfig windowCacheConfig = new WindowCacheConfig(); WindowCache.reconfigure(windowCacheConfig); } + @Test public void testObjectInNewPack() throws IncorrectObjectTypeException, IOException { // Create a new object in a new pack, and test that it is present. @@ -90,6 +103,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { assertEquals(o1.name(), parse(o1).name()); } + @Test public void testObjectMovedToNewPack1() throws IncorrectObjectTypeException, IOException { // Create an object and pack it. Then remove that pack and put the @@ -116,6 +130,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { assertEquals(o1.name(), parse(o1).name()); } + @Test public void testObjectMovedWithinPack() throws IncorrectObjectTypeException, IOException { // Create an object and pack it. @@ -148,6 +163,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { assertEquals(o2.name(), parse(o2).name()); } + @Test public void testObjectMovedToNewPack2() throws IncorrectObjectTypeException, IOException { // Create an object and pack it. Then remove that pack and put the diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java index 7504d7ce3..385c8531c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java @@ -43,11 +43,15 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; + import java.io.File; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; +import org.junit.Test; public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase { + @Test public void testShouldAutomagicallyDetectGitDirectory() throws Exception { FileRepository r = createWorkRepository(); File d = new File(r.getDirectory(), "sub-dir"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileSnapshotTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileSnapshotTest.java index f90c447ef..99d859384 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileSnapshotTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileSnapshotTest.java @@ -42,6 +42,9 @@ */ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -49,9 +52,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.util.FileUtils; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; public class FileSnapshotTest { @@ -60,6 +63,7 @@ public class FileSnapshotTest { private final File trash = new File(new File("target"), "trash"); @Before + @After public void tearDown() throws Exception { FileUtils.delete(trash, FileUtils.RECURSIVE | FileUtils.SKIP_MISSING); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackFileTest.java index 74c9f0655..8cb8e4336 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackFileTest.java @@ -43,6 +43,12 @@ package org.eclipse.jgit.storage.file; +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.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -53,6 +59,7 @@ import java.util.zip.Deflater; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.LargeObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRng; @@ -68,6 +75,9 @@ import org.eclipse.jgit.transport.IndexPack; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.TemporaryBuffer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class PackFileTest extends LocalDiskRepositoryTestCase { private int streamThreshold = 16 * 1024; @@ -80,29 +90,37 @@ public class PackFileTest extends LocalDiskRepositoryTestCase { private WindowCursor wc; - protected void setUp() throws Exception { + private TestRng getRng() { + if (rng == null) + rng = new TestRng(JGitTestUtil.getName()); + return rng; + } + + @Before + public void setUp() throws Exception { super.setUp(); WindowCacheConfig cfg = new WindowCacheConfig(); cfg.setStreamFileThreshold(streamThreshold); WindowCache.reconfigure(cfg); - rng = new TestRng(getName()); repo = createBareRepository(); tr = new TestRepository(repo); wc = (WindowCursor) repo.newObjectReader(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (wc != null) wc.release(); WindowCache.reconfigure(new WindowCacheConfig()); super.tearDown(); } + @Test public void testWhole_SmallObject() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); RevBlob id = tr.blob(data); tr.branch("master").commit().add("A", id).create(); tr.packAndPrune(); @@ -126,9 +144,10 @@ public class PackFileTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testWhole_LargeObject() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(streamThreshold + 5); + byte[] data = getRng().nextBytes(streamThreshold + 5); RevBlob id = tr.blob(data); tr.branch("master").commit().add("A", id).create(); tr.packAndPrune(); @@ -159,6 +178,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testDelta_SmallObjectChain() throws Exception { ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); byte[] data0 = new byte[512]; @@ -219,6 +239,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testDelta_LargeObjectChain() throws Exception { ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); byte[] data0 = new byte[streamThreshold + 5]; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexTestCase.java index 9884142e5..caeeb9fde 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexTestCase.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + import java.io.File; import java.util.Iterator; import java.util.NoSuchElementException; @@ -50,6 +54,7 @@ import java.util.NoSuchElementException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.storage.file.PackIndex.MutableEntry; +import org.junit.Test; public abstract class PackIndexTestCase extends RepositoryTestCase { @@ -90,6 +95,7 @@ public abstract class PackIndexTestCase extends RepositoryTestCase { * Test contracts of Iterator methods and this implementation remove() * limitations. */ + @Test public void testIteratorMethodsContract() { Iterator iter = smallIdx.iterator(); while (iter.hasNext()) { @@ -115,6 +121,7 @@ public abstract class PackIndexTestCase extends RepositoryTestCase { * Test results of iterator comparing to content of well-known (prepared) * small index. */ + @Test public void testIteratorReturnedValues1() { Iterator iter = smallIdx.iterator(); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next() @@ -139,6 +146,7 @@ public abstract class PackIndexTestCase extends RepositoryTestCase { /** * Compare offset from iterator entries with output of findOffset() method. */ + @Test public void testCompareEntriesOffsetsWithFindOffsets() { for (MutableEntry me : smallIdx) { assertEquals(smallIdx.findOffset(me.toObjectId()), me.getOffset()); @@ -152,6 +160,7 @@ public abstract class PackIndexTestCase extends RepositoryTestCase { * Test partial results of iterator comparing to content of well-known * (prepared) dense index, that may need multi-level indexing. */ + @Test public void testIteratorReturnedValues2() { Iterator iter = denseIdx.iterator(); while (!iter.next().name().equals( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV1Test.java index 303eeff72..823195835 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV1Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV1Test.java @@ -45,11 +45,15 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + import java.io.File; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.Test; public class PackIndexV1Test extends PackIndexTestCase { @Override @@ -70,6 +74,7 @@ public class PackIndexV1Test extends PackIndexTestCase { * @throws MissingObjectException */ @Override + @Test public void testCRC32() throws MissingObjectException { assertFalse(smallIdx.hasCRC32Support()); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV2Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV2Test.java index 0ed336da3..039cd6f3d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV2Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV2Test.java @@ -45,11 +45,15 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.Test; public class PackIndexV2Test extends PackIndexTestCase { @Override @@ -71,6 +75,7 @@ public class PackIndexV2Test extends PackIndexTestCase { * @throws MissingObjectException */ @Override + @Test public void testCRC32() throws MissingObjectException, UnsupportedOperationException { assertTrue(smallIdx.hasCRC32Support()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackReverseIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackReverseIndexTest.java index 07a40a425..b16c6f28d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackReverseIndexTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackReverseIndexTest.java @@ -44,10 +44,17 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.storage.file.PackIndex.MutableEntry; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.Before; +import org.junit.Test; public class PackReverseIndexTest extends RepositoryTestCase { @@ -58,6 +65,7 @@ public class PackReverseIndexTest extends RepositoryTestCase { /** * Set up tested class instance, test constructor by the way. */ + @Before public void setUp() throws Exception { super.setUp(); // index with both small (< 2^31) and big offsets @@ -69,6 +77,7 @@ public class PackReverseIndexTest extends RepositoryTestCase { /** * Test findObject() for all index entries. */ + @Test public void testFindObject() { for (MutableEntry me : idx) assertEquals(me.toObjectId(), reverseIdx.findObject(me.getOffset())); @@ -77,6 +86,7 @@ public class PackReverseIndexTest extends RepositoryTestCase { /** * Test findObject() with illegal argument. */ + @Test public void testFindObjectWrongOffset() { assertNull(reverseIdx.findObject(0)); } @@ -86,6 +96,7 @@ public class PackReverseIndexTest extends RepositoryTestCase { * * @throws CorruptObjectException */ + @Test public void testFindNextOffset() throws CorruptObjectException { long offset = findFirstOffset(); assertTrue(offset > 0); @@ -104,6 +115,7 @@ public class PackReverseIndexTest extends RepositoryTestCase { /** * Test findNextOffset() with wrong illegal argument as offset. */ + @Test public void testFindNextOffsetWrongOffset() { try { reverseIdx.findNextOffset(0, Long.MAX_VALUE); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java index 5685ccac6..0751f8b5c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -59,6 +63,7 @@ import java.util.LinkedList; import java.util.List; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; @@ -69,7 +74,9 @@ import org.eclipse.jgit.storage.file.PackIndex.MutableEntry; import org.eclipse.jgit.storage.pack.PackConfig; import org.eclipse.jgit.storage.pack.PackWriter; import org.eclipse.jgit.transport.IndexPack; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class PackWriterTest extends SampleDataRepositoryTestCase { @@ -93,6 +100,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { private PackFile pack; + @Before public void setUp() throws Exception { super.setUp(); os = new ByteArrayOutputStream(); @@ -102,6 +110,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { config = new PackConfig(db); } + @After public void tearDown() throws Exception { if (writer != null) writer.release(); @@ -111,6 +120,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { /** * Test constructor for exceptions, default settings, initialization. */ + @Test public void testContructor() { writer = new PackWriter(config, db.newObjectReader()); assertEquals(false, writer.isDeltaBaseAsOffset()); @@ -122,6 +132,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { /** * Change default settings and verify them. */ + @Test public void testModifySettings() { config.setReuseDeltas(false); config.setReuseObjects(false); @@ -142,6 +153,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWriteEmptyPack1() throws IOException { createVerifyOpenPack(EMPTY_LIST_OBJECT, EMPTY_LIST_OBJECT, false, false); @@ -157,6 +169,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWriteEmptyPack2() throws IOException { createVerifyOpenPack(EMPTY_LIST_REVS.iterator()); @@ -170,6 +183,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testNotIgnoreNonExistingObjects() throws IOException { final ObjectId nonExisting = ObjectId .fromString("0000000000000000000000000000000000000001"); @@ -187,6 +201,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testIgnoreNonExistingObjects() throws IOException { final ObjectId nonExisting = ObjectId .fromString("0000000000000000000000000000000000000001"); @@ -201,6 +216,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack1() throws IOException { config.setReuseDeltas(false); writeVerifyPack1(); @@ -212,6 +228,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack1NoObjectReuse() throws IOException { config.setReuseDeltas(false); config.setReuseObjects(false); @@ -224,6 +241,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack2() throws IOException { writeVerifyPack2(false); } @@ -234,6 +252,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack2DeltasReuseRefs() throws IOException { writeVerifyPack2(true); } @@ -244,6 +263,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack2DeltasReuseOffsets() throws IOException { config.setDeltaBaseAsOffset(true); writeVerifyPack2(true); @@ -256,6 +276,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack2DeltasCRC32Copy() throws IOException { final File packDir = new File(db.getObjectDatabase().getDirectory(), "pack"); final File crc32Pack = new File(packDir, @@ -278,6 +299,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * @throws MissingObjectException * */ + @Test public void testWritePack3() throws MissingObjectException, IOException { config.setReuseDeltas(false); final ObjectId forcedOrder[] = new ObjectId[] { @@ -307,6 +329,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack4() throws IOException { writeVerifyPack4(false); } @@ -317,6 +340,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testWritePack4ThinPack() throws IOException { writeVerifyPack4(true); } @@ -328,6 +352,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testWritePack2SizeDeltasVsNoDeltas() throws Exception { testWritePack2(); final long sizePack2NoDeltas = os.size(); @@ -347,6 +372,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testWritePack2SizeOffsetsVsRefs() throws Exception { testWritePack2DeltasReuseRefs(); final long sizePack2DeltasRefs = os.size(); @@ -365,6 +391,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testWritePack4SizeThinVsNoThin() throws Exception { testWritePack4(); final long sizePack4 = os.size(); @@ -376,6 +403,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { assertTrue(sizePack4 > sizePack4Thin); } + @Test public void testWriteIndex() throws Exception { config.setIndexVersion(2); writeVerifyPack4(false); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java index 6e9854160..2a1302232 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java @@ -48,6 +48,14 @@ import static org.eclipse.jgit.lib.Constants.R_HEADS; import static org.eclipse.jgit.lib.Constants.R_TAGS; import static org.eclipse.jgit.lib.Ref.Storage.LOOSE; import static org.eclipse.jgit.lib.Ref.Storage.NEW; +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 static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; @@ -61,6 +69,8 @@ import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTag; +import org.junit.Before; +import org.junit.Test; public class RefDirectoryTest extends LocalDiskRepositoryTestCase { private Repository diskRepo; @@ -75,7 +85,8 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { private RevTag v1_0; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); diskRepo = createBareRepository(); @@ -88,6 +99,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { repo.getRevWalk().parseBody(v1_0); } + @Test public void testCreate() throws IOException { // setUp above created the directory. We just have to test it. File d = diskRepo.getDirectory(); @@ -111,6 +123,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals("ref: refs/heads/master\n", read(new File(d, HEAD))); } + @Test public void testGetRefs_EmptyDatabase() throws IOException { Map all; @@ -124,6 +137,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue("no references", all.isEmpty()); } + @Test public void testGetRefs_HeadOnOneBranch() throws IOException { Map all; Ref head, master; @@ -149,6 +163,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, master.getObjectId()); } + @Test public void testGetRefs_DeatchedHead1() throws IOException { Map all; Ref head; @@ -168,6 +183,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, head.getObjectId()); } + @Test public void testGetRefs_DeatchedHead2() throws IOException { Map all; Ref head, master; @@ -193,6 +209,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, master.getObjectId()); } + @Test public void testGetRefs_DeeplyNestedBranch() throws IOException { String name = "refs/heads/a/b/c/d/e/f/g/h/i/j/k"; Map all; @@ -210,6 +227,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, r.getObjectId()); } + @Test public void testGetRefs_HeadBranchNotBorn() throws IOException { Map all; Ref a, b; @@ -231,6 +249,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals("refs/heads/B", b.getName()); } + @Test public void testGetRefs_LooseOverridesPacked() throws IOException { Map heads; Ref a; @@ -246,6 +265,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, a.getObjectId()); } + @Test public void testGetRefs_IgnoresGarbageRef1() throws IOException { Map heads; Ref a; @@ -261,6 +281,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, a.getObjectId()); } + @Test public void testGetRefs_IgnoresGarbageRef2() throws IOException { Map heads; Ref a; @@ -276,6 +297,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, a.getObjectId()); } + @Test public void testGetRefs_IgnoresGarbageRef3() throws IOException { Map heads; Ref a; @@ -291,6 +313,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, a.getObjectId()); } + @Test public void testGetRefs_IgnoresGarbageRef4() throws IOException { Map heads; Ref a, b, c; @@ -323,6 +346,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, c.getObjectId()); } + @Test public void testGetRefs_InvalidName() throws IOException { writeLooseRef("refs/heads/A", A); @@ -331,6 +355,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue("empty objects/", refdir.getRefs("objects/").isEmpty()); } + @Test public void testGetRefs_HeadsOnly_AllLoose() throws IOException { Map heads; Ref a, b; @@ -352,6 +377,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, b.getObjectId()); } + @Test public void testGetRefs_HeadsOnly_AllPacked1() throws IOException { Map heads; Ref a; @@ -368,6 +394,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(A, a.getObjectId()); } + @Test public void testGetRefs_HeadsOnly_SymrefToPacked() throws IOException { Map heads; Ref master, other; @@ -389,6 +416,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertSame(master, other.getTarget()); } + @Test public void testGetRefs_HeadsOnly_Mixed() throws IOException { Map heads; Ref a, b; @@ -410,6 +438,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, b.getObjectId()); } + @Test public void testGetRefs_TagsOnly_AllLoose() throws IOException { Map tags; Ref a; @@ -426,6 +455,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(v1_0, a.getObjectId()); } + @Test public void testGetRefs_TagsOnly_AllPacked() throws IOException { Map tags; Ref a; @@ -442,6 +472,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(v1_0, a.getObjectId()); } + @Test public void testGetRefs_DiscoversNewLoose1() throws IOException { Map orig, next; Ref orig_r, next_r; @@ -470,6 +501,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, next_r.getObjectId()); } + @Test public void testGetRefs_DiscoversNewLoose2() throws IOException { Map orig, next, news; @@ -493,6 +525,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue(news.containsKey("B")); } + @Test public void testGetRefs_DiscoversModifiedLoose() throws IOException { Map all; @@ -506,6 +539,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, all.get(HEAD).getObjectId()); } + @Test public void testGetRef_DiscoversModifiedLoose() throws IOException { Map all; @@ -520,6 +554,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, master.getObjectId()); } + @Test public void testGetRefs_DiscoversDeletedLoose1() throws IOException { Map orig, next; Ref orig_r, next_r; @@ -549,6 +584,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(B, orig_r.getObjectId()); } + @Test public void testGetRef_DiscoversDeletedLoose() throws IOException { Map all; @@ -561,6 +597,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue(refdir.getRefs(RefDatabase.ALL).isEmpty()); } + @Test public void testGetRefs_DiscoversDeletedLoose2() throws IOException { Map orig, next; @@ -578,6 +615,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertFalse(next.containsKey("refs/heads/pu")); } + @Test public void testGetRefs_DiscoversDeletedLoose3() throws IOException { Map orig, next; @@ -600,6 +638,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertFalse(next.containsKey("refs/heads/next")); } + @Test public void testGetRefs_DiscoversDeletedLoose4() throws IOException { Map orig, next; Ref orig_r, next_r; @@ -625,6 +664,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertSame("uses cached instance", orig_r, next_r); } + @Test public void testGetRefs_DiscoversDeletedLoose5() throws IOException { Map orig, next; @@ -645,6 +685,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue(next.containsKey("refs/tags/v1.0")); } + @Test public void testGetRefs_SkipsLockFiles() throws IOException { Map all; @@ -659,6 +700,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertFalse(all.containsKey("refs/heads/pu.lock")); } + @Test public void testGetRefs_CycleInSymbolicRef() throws IOException { Map all; Ref r; @@ -711,6 +753,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertNull("mising 1 due to cycle", r); } + @Test public void testGetRefs_PackedNotPeeled_Sorted() throws IOException { Map all; @@ -744,6 +787,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertNull(tag.getPeeledObjectId()); } + @Test public void testGetRef_PackedNotPeeled_WrongSort() throws IOException { writePackedRefs("" + // v1_0.name() + " refs/tags/v1.0\n" + // @@ -773,6 +817,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertNull(tag.getPeeledObjectId()); } + @Test public void testGetRefs_PackedWithPeeled() throws IOException { Map all; @@ -807,6 +852,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertEquals(v1_0.getObject(), tag.getPeeledObjectId()); } + @Test public void testGetRef_EmptyDatabase() throws IOException { Ref r; @@ -825,6 +871,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertNull(refdir.getRef("v1.0")); } + @Test public void testGetRef_FetchHead() throws IOException { // This is an odd special case where we need to make sure we read // exactly the first 40 bytes of the file and nothing further on @@ -841,6 +888,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertNull(r.getPeeledObjectId()); } + @Test public void testGetRef_AnyHeadWithGarbage() throws IOException { write(new File(diskRepo.getDirectory(), "refs/heads/A"), A.name() + "012345 . this is not a standard reference\n" @@ -854,12 +902,14 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertNull(r.getPeeledObjectId()); } + @Test public void testGetRefs_CorruptSymbolicReference() throws IOException { String name = "refs/heads/A"; writeLooseRef(name, "ref: \n"); assertTrue(refdir.getRefs(RefDatabase.ALL).isEmpty()); } + @Test public void testGetRef_CorruptSymbolicReference() throws IOException { String name = "refs/heads/A"; writeLooseRef(name, "ref: \n"); @@ -872,6 +922,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testGetRefs_CorruptObjectIdReference() throws IOException { String name = "refs/heads/A"; String content = "zoo" + A.name(); @@ -879,6 +930,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue(refdir.getRefs(RefDatabase.ALL).isEmpty()); } + @Test public void testGetRef_CorruptObjectIdReference() throws IOException { String name = "refs/heads/A"; String content = "zoo" + A.name(); @@ -892,6 +944,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { } } + @Test public void testIsNameConflicting() throws IOException { writeLooseRef("refs/heads/a/b", A); writePackedRef("refs/heads/q", B); @@ -913,6 +966,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertTrue(refdir.isNameConflicting("refs/heads/q/master")); } + @Test public void testPeelLooseTag() throws IOException { writeLooseRef("refs/tags/v1_0", v1_0); writeLooseRef("refs/tags/current", "ref: refs/tags/v1_0\n"); @@ -961,6 +1015,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { assertSame(tag_p2, refdir.peel(tag_p2)); } + @Test public void testPeelCommit() throws IOException { writeLooseRef("refs/heads/master", A); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java index 4e2e14a6f..fe8bdeb42 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java @@ -45,6 +45,15 @@ package org.eclipse.jgit.storage.file; +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 static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.IOException; import java.util.List; @@ -63,6 +72,7 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Test; public class RefUpdateTest extends SampleDataRepositoryTestCase { @@ -96,6 +106,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(!removed, db.getAllRefs().containsKey(ref.getName())); } + @Test public void testNoCacheObjectIdSubclass() throws IOException { final String newRef = "refs/heads/abc"; final RefUpdate ru = updateRef(newRef); @@ -121,6 +132,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(0, reverseEntries2.size()); } + @Test public void testNewNamespaceConflictWithLoosePrefixNameExists() throws IOException { final String newRef = "refs/heads/z"; @@ -136,6 +148,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(0, db.getReflogReader("HEAD").getReverseEntries().size()); } + @Test public void testNewNamespaceConflictWithPackedPrefixNameExists() throws IOException { final String newRef = "refs/heads/master/x"; @@ -146,6 +159,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(0, db.getReflogReader("HEAD").getReverseEntries().size()); } + @Test public void testNewNamespaceConflictWithLoosePrefixOfExisting() throws IOException { final String newRef = "refs/heads/z/a"; @@ -162,6 +176,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(0, db.getReflogReader("HEAD").getReverseEntries().size()); } + @Test public void testNewNamespaceConflictWithPackedPrefixOfExisting() throws IOException { final String newRef = "refs/heads/prefix"; @@ -177,6 +192,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testDeleteHEADreferencedRef() throws IOException { ObjectId pid = db.resolve("refs/heads/master^"); RefUpdate updateRef = db.updateRef("refs/heads/master"); @@ -193,6 +209,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(0,db.getReflogReader("HEAD").getReverseEntries().size()); } + @Test public void testLooseDelete() throws IOException { final String newRef = "refs/heads/abc"; RefUpdate ref = updateRef(newRef); @@ -202,6 +219,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertNull(db.getReflogReader("refs/heads/abc")); } + @Test public void testDeleteHead() throws IOException { final RefUpdate ref = updateRef(Constants.HEAD); delete(ref, Result.REJECTED_CURRENT_BRANCH, true, false); @@ -215,6 +233,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testDeleteLooseAndItsDirectory() throws IOException { ObjectId pid = db.resolve("refs/heads/c^"); RefUpdate updateRef = db.updateRef("refs/heads/z/c"); @@ -238,16 +257,19 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertFalse(new File(db.getDirectory(), "logs/refs/heads/z").exists()); } + @Test public void testDeleteNotFound() throws IOException { final RefUpdate ref = updateRef("refs/heads/xyz"); delete(ref, Result.NEW, false, true); } + @Test public void testDeleteFastForward() throws IOException { final RefUpdate ref = updateRef("refs/heads/a"); delete(ref, Result.FAST_FORWARD); } + @Test public void testDeleteForce() throws IOException { final RefUpdate ref = db.updateRef("refs/heads/b"); ref.setNewObjectId(db.resolve("refs/heads/a")); @@ -256,6 +278,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { delete(ref, Result.FORCED); } + @Test public void testRefKeySameAsName() { Map allRefs = db.getAllRefs(); for (Entry e : allRefs.entrySet()) { @@ -269,6 +292,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRefForward() throws IOException { ObjectId ppid = db.resolve("refs/heads/master^"); ObjectId pid = db.resolve("refs/heads/master"); @@ -293,6 +317,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testUpdateRefDetached() throws Exception { ObjectId pid = db.resolve("refs/heads/master"); ObjectId ppid = db.resolve("refs/heads/master^"); @@ -322,6 +347,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testUpdateRefDetachedUnbornHead() throws Exception { ObjectId ppid = db.resolve("refs/heads/master^"); writeSymref("HEAD", "refs/heads/unborn"); @@ -352,6 +378,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testDeleteLoosePacked() throws IOException { ObjectId pid = db.resolve("refs/heads/c^"); RefUpdate updateRef = db.updateRef("refs/heads/c"); @@ -373,6 +400,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRefNoChange() throws IOException { ObjectId pid = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master"); @@ -392,6 +420,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testRefsCacheAfterUpdate() throws Exception { // Do not use the defalt repo for this case. Map allRefs = db.getAllRefs(); @@ -429,6 +458,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testRefsCacheAfterUpdateLooseOnly() throws Exception { // Do not use the defalt repo for this case. Map allRefs = db.getAllRefs(); @@ -454,6 +484,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRefLockFailureWrongOldValue() throws IOException { ObjectId pid = db.resolve("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master"); @@ -469,6 +500,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRefForwardWithCheck1() throws IOException { ObjectId ppid = db.resolve("refs/heads/master^"); ObjectId pid = db.resolve("refs/heads/master"); @@ -494,6 +526,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRefForwardWithCheck2() throws IOException { ObjectId ppid = db.resolve("refs/heads/master^"); ObjectId pid = db.resolve("refs/heads/master"); @@ -520,6 +553,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRefLockFailureLocked() throws IOException { ObjectId opid = db.resolve("refs/heads/master"); ObjectId pid = db.resolve("refs/heads/master^"); @@ -545,6 +579,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testDeleteLoosePackedRejected() throws IOException { ObjectId pid = db.resolve("refs/heads/c^"); ObjectId oldpid = db.resolve("refs/heads/c"); @@ -555,6 +590,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(oldpid, db.resolve("refs/heads/c")); } + @Test public void testRenameBranchNoPreviousLog() throws IOException { assertFalse("precondition, no log on old branchg", new File(db .getDirectory(), "logs/refs/heads/b").exists()); @@ -574,6 +610,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(oldHead, db.resolve(Constants.HEAD)); // unchanged } + @Test public void testRenameBranchHasPreviousLog() throws IOException { ObjectId rb = db.resolve("refs/heads/b"); ObjectId oldHead = db.resolve(Constants.HEAD); @@ -597,6 +634,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals(oldHead, db.resolve(Constants.HEAD)); // unchanged } + @Test public void testRenameCurrentBranch() throws IOException { ObjectId rb = db.resolve("refs/heads/b"); writeSymref(Constants.HEAD, "refs/heads/b"); @@ -620,6 +658,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { assertEquals("Just a message", db.getReflogReader("new/name").getReverseEntries().get(1).getComment()); } + @Test public void testRenameBranchAlsoInPack() throws IOException { ObjectId rb = db.resolve("refs/heads/b"); ObjectId rb2 = db.resolve("refs/heads/b~1"); @@ -707,48 +746,56 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { positive, new File(db.getDirectory(), toName).exists()); } + @Test public void testRenameBranchCannotLockAFileHEADisFromLockHEAD() throws IOException { tryRenameWhenLocked("HEAD", "refs/heads/b", "refs/heads/new/name", "refs/heads/b"); } + @Test public void testRenameBranchCannotLockAFileHEADisFromLockFrom() throws IOException { tryRenameWhenLocked("refs/heads/b", "refs/heads/b", "refs/heads/new/name", "refs/heads/b"); } + @Test public void testRenameBranchCannotLockAFileHEADisFromLockTo() throws IOException { tryRenameWhenLocked("refs/heads/new/name", "refs/heads/b", "refs/heads/new/name", "refs/heads/b"); } + @Test public void testRenameBranchCannotLockAFileHEADisToLockFrom() throws IOException { tryRenameWhenLocked("refs/heads/b", "refs/heads/b", "refs/heads/new/name", "refs/heads/new/name"); } + @Test public void testRenameBranchCannotLockAFileHEADisToLockTo() throws IOException { tryRenameWhenLocked("refs/heads/new/name", "refs/heads/b", "refs/heads/new/name", "refs/heads/new/name"); } + @Test public void testRenameBranchCannotLockAFileHEADisOtherLockFrom() throws IOException { tryRenameWhenLocked("refs/heads/b", "refs/heads/b", "refs/heads/new/name", "refs/heads/a"); } + @Test public void testRenameBranchCannotLockAFileHEADisOtherLockTo() throws IOException { tryRenameWhenLocked("refs/heads/new/name", "refs/heads/b", "refs/heads/new/name", "refs/heads/a"); } + @Test public void testRenameRefNameColission1avoided() throws IOException { // setup ObjectId rb = db.resolve("refs/heads/b"); @@ -781,6 +828,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { .getReverseEntries().get(0).getComment()); } + @Test public void testRenameRefNameColission2avoided() throws IOException { // setup ObjectId rb = db.resolve("refs/heads/b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java index 1d268a474..64333fc75 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java @@ -44,6 +44,9 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -55,6 +58,7 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.storage.file.ReflogReader.Entry; +import org.junit.Test; public class ReflogReaderTest extends SampleDataRepositoryTestCase { @@ -79,6 +83,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase { static byte[] headLine = "3333333333333333333333333333333333333333 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor 1243028201 -0100\tbranch: change to HEAD\n" .getBytes(); + @Test public void testReadOneLine() throws Exception { setupReflog("logs/refs/heads/master", oneLine); @@ -105,6 +110,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase { return fmt.format(id.getWhen()); } + @Test public void testReadTwoLine() throws Exception { setupReflog("logs/refs/heads/master", twoLine); @@ -140,6 +146,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase { assertEquals("branch: Created from rr/renamebranchv4", e.getComment()); } + @Test public void testReadWhileAppendIsInProgress() throws Exception { setupReflog("logs/refs/heads/master", twoLineWithAppendInProgress); ReflogReader reader = new ReflogReader(db, "refs/heads/master"); @@ -164,6 +171,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase { } + @Test public void testReadRightLog() throws Exception { setupReflog("logs/refs/heads/a", aLine); setupReflog("logs/refs/heads/master", masterLine); @@ -176,6 +184,7 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase { .getLastEntry().getComment()); } + @Test public void testNoLog() throws Exception { assertEquals(0, db.getReflogReader("master").getReverseEntries().size()); assertNull(db.getReflogReader("master").getLastEntry()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java index d28dd399b..99d99a5e5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java @@ -44,6 +44,11 @@ package org.eclipse.jgit.storage.file; +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.IOException; @@ -54,18 +59,21 @@ import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.util.FS; +import org.junit.Test; /** * Tests for setting up the working directory when creating a Repository */ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { + @Test public void testIsBare_CreateRepositoryFromArbitraryGitDir() throws Exception { File gitDir = getFile("workdir"); assertTrue(new FileRepository(gitDir).isBare()); } + @Test public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception { File gitDir = getFile("workdir", Constants.DOT_GIT); Repository repo = new FileRepository(gitDir); @@ -74,6 +82,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertGitdirPath(repo, "workdir", Constants.DOT_GIT); } + @Test public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir() throws Exception { File gitDir = getFile("workdir", Constants.DOT_GIT); @@ -82,6 +91,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertEquals(workdir, "workdir"); } + @Test public void testNotBare_CreateRepositoryFromWorkDirOnly() throws Exception { File workdir = getFile("workdir", "repo"); FileRepository repo = new FileRepositoryBuilder().setWorkTree(workdir).build(); @@ -90,6 +100,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT); } + @Test public void testWorkdirIsDotGit_CreateRepositoryFromWorkDirOnly() throws Exception { File workdir = getFile("workdir", "repo"); @@ -97,6 +108,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT); } + @Test public void testNotBare_CreateRepositoryFromGitDirOnlyWithWorktreeConfig() throws Exception { File gitDir = getFile("workdir", "repoWithConfig"); @@ -108,6 +120,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertGitdirPath(repo, "workdir", "repoWithConfig"); } + @Test public void testBare_CreateRepositoryFromGitDirOnlyWithBareConfigTrue() throws Exception { File gitDir = getFile("workdir", "repoWithConfig"); @@ -116,6 +129,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertTrue(repo.isBare()); } + @Test public void testWorkdirIsParent_CreateRepositoryFromGitDirOnlyWithBareConfigFalse() throws Exception { File gitDir = getFile("workdir", "repoWithBareConfigTrue", "child"); @@ -124,6 +138,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertWorkdirPath(repo, "workdir", "repoWithBareConfigTrue"); } + @Test public void testNotBare_CreateRepositoryFromGitDirOnlyWithBareConfigFalse() throws Exception { File gitDir = getFile("workdir", "repoWithBareConfigFalse", "child"); @@ -134,6 +149,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { assertGitdirPath(repo, "workdir", "repoWithBareConfigFalse", "child"); } + @Test public void testExceptionThrown_BareRepoGetWorkDir() throws Exception { File gitDir = getFile("workdir"); try { @@ -144,6 +160,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { } } + @Test public void testExceptionThrown_BareRepoGetIndex() throws Exception { File gitDir = getFile("workdir"); try { @@ -154,6 +171,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { } } + @Test public void testExceptionThrown_BareRepoGetIndexFile() throws Exception { File gitDir = getFile("workdir"); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java similarity index 98% rename from org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java rename to org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java index 757af2eb1..7f0436b83 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java @@ -46,6 +46,13 @@ package org.eclipse.jgit.storage.file; +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.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileInputStream; import java.io.FileReader; @@ -74,8 +81,11 @@ import org.eclipse.jgit.lib.TreeFormatter; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Test; + +public class T0003_BasicTest extends SampleDataRepositoryTestCase { -public class T0003_Basic extends SampleDataRepositoryTestCase { + @Test public void test001_Initalize() { final File gitdir = new File(trash, Constants.DOT_GIT); final File objects = new File(gitdir, "objects"); @@ -90,7 +100,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertTrue("Exists " + objects, objects.isDirectory()); assertTrue("Exists " + objects_pack, objects_pack.isDirectory()); assertTrue("Exists " + objects_info, objects_info.isDirectory()); - assertEquals(2, objects.listFiles().length); + assertEquals(2L, objects.listFiles().length); assertTrue("Exists " + refs, refs.isDirectory()); assertTrue("Exists " + refs_heads, refs_heads.isDirectory()); assertTrue("Exists " + refs_tags, refs_tags.isDirectory()); @@ -98,6 +108,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(23, HEAD.length()); } + @Test public void test000_openRepoBadArgs() throws IOException { try { new FileRepositoryBuilder().build(); @@ -114,6 +125,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void test000_openrepo_default_gitDirSet() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); Repository repo1initial = new FileRepository(new File(repo1Parent, @@ -137,6 +149,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); @@ -161,6 +174,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void test000_openrepo_default_workDirSet() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); Repository repo1initial = new FileRepository(new File(repo1Parent, @@ -183,6 +197,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void test000_openrepo_default_absolute_workdirconfig() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); @@ -211,6 +226,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void test000_openrepo_default_relative_workdirconfig() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); @@ -240,6 +256,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void test000_openrepo_alternate_index_file_and_objdirs() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); @@ -273,6 +290,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(expected.getCanonicalPath(), actual.getCanonicalPath()); } + @Test public void test002_WriteEmptyTree() throws IOException { // One of our test packs contains the empty tree object. If the pack is // open when we create it we won't write the object file out as a loose @@ -290,6 +308,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertTrue("Read-only " + o, !o.canWrite()); } + @Test public void test002_WriteEmptyTree2() throws IOException { // File shouldn't exist as it is in a test pack. // @@ -301,6 +320,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertFalse("Exists " + o, o.isFile()); } + @Test public void test006_ReadUglyConfig() throws IOException, ConfigInvalidException { final File cfg = new File(db.getDirectory(), "config"); @@ -327,6 +347,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(configStr, new String(cbuf)); } + @Test public void test007_Open() throws IOException { final FileRepository db2 = new FileRepository(db.getDirectory()); assertEquals(db.getDirectory(), db2.getDirectory()); @@ -335,6 +356,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertNotSame(db.getConfig(), db2.getConfig()); } + @Test public void test008_FailOnWrongVersion() throws IOException { final File cfg = new File(db.getDirectory(), "config"); final String badvers = "ihopethisisneveraversion"; @@ -351,6 +373,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { } } + @Test public void test009_CreateCommitOldFormat() throws IOException { final ObjectId treeId = insertTree(new TreeFormatter()); final CommitBuilder c = new CommitBuilder(); @@ -388,6 +411,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(c.getCommitter(), c2.getCommitterIdent()); } + @Test public void test012_SubtreeExternalSorting() throws IOException { final ObjectId emptyBlob = insertEmptyBlob(); final Tree t = new Tree(db); @@ -410,6 +434,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { insertTree(t)); } + @Test public void test020_createBlobTag() throws IOException { final ObjectId emptyId = insertEmptyBlob(); final TagBuilder t = new TagBuilder(); @@ -429,6 +454,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { .getObject().getId().name()); } + @Test public void test021_createTreeTag() throws IOException { final ObjectId emptyId = insertEmptyBlob(); final Tree almostEmptyTree = new Tree(db); @@ -452,6 +478,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { .getObject().getId().name()); } + @Test public void test022_createCommitTag() throws IOException { final ObjectId emptyId = insertEmptyBlob(); final Tree almostEmptyTree = new Tree(db); @@ -483,6 +510,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { .getObject().getId().name()); } + @Test public void test023_createCommitNonAnullii() throws IOException { final ObjectId emptyId = insertEmptyBlob(); final Tree almostEmptyTree = new Tree(db); @@ -504,6 +532,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(commit.getMessage(), loadedCommit.getFullMessage()); } + @Test public void test024_createCommitNonAscii() throws IOException { final ObjectId emptyId = insertEmptyBlob(); final Tree almostEmptyTree = new Tree(db); @@ -522,6 +551,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.name()); } + @Test public void test025_computeSha1NoStore() throws IOException { byte[] data = "test025 some data, more than 16 bytes to get good coverage" .getBytes("ISO-8859-1"); @@ -530,6 +560,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name()); } + @Test public void test026_CreateCommitMultipleparents() throws IOException { final ObjectId treeId; final ObjectInserter oi = db.newObjectInserter(); @@ -628,6 +659,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(actid3, rm4.getParent(2)); } + @Test public void test027_UnpackedRefHigherPriorityThanPacked() throws IOException { String unpackedId = "7f822839a2fe9760f386cbbbcb3f92c5fe81def7"; @@ -637,6 +669,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(unpackedId, resolved.name()); } + @Test public void test028_LockPackedRef() throws IOException { writeTrashFile(".git/packed-refs", "7f822839a2fe9760f386cbbbcb3f92c5fe81def7 refs/heads/foobar"); @@ -667,6 +700,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { assertEquals(newId2, db.resolve("refs/heads/foobar")); } + @Test public void test30_stripWorkDir() { File relCwd = new File("."); File absCwd = relCwd.getAbsoluteFile(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReader.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java similarity index 93% rename from org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReader.java rename to org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java index 472d6956e..bdc9edbe3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReader.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReaderTest.java @@ -46,20 +46,25 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.File; import java.io.IOException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; -import org.eclipse.jgit.util.JGitTestUtil; +import org.junit.Test; -public class T0004_PackReader extends SampleDataRepositoryTestCase { +public class T0004_PackReaderTest extends SampleDataRepositoryTestCase { private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); + @Test public void test003_lookupCompressedObject() throws IOException { final PackFile pr; final ObjectId id; @@ -74,6 +79,7 @@ public class T0004_PackReader extends SampleDataRepositoryTestCase { pr.close(); } + @Test public void test004_lookupDeltifiedObject() throws IOException { final ObjectId id; final ObjectLoader or; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java index 547565ea8..c6199c342 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java @@ -43,6 +43,12 @@ package org.eclipse.jgit.storage.file; +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.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -57,6 +63,7 @@ import java.util.zip.DeflaterOutputStream; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.LargeObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.lib.Constants; @@ -65,6 +72,9 @@ import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectStream; import org.eclipse.jgit.util.IO; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { private int streamThreshold = 16 * 1024; @@ -75,28 +85,36 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { private WindowCursor wc; - protected void setUp() throws Exception { + private TestRng getRng() { + if (rng == null) + rng = new TestRng(JGitTestUtil.getName()); + return rng; + } + + @Before + public void setUp() throws Exception { super.setUp(); WindowCacheConfig cfg = new WindowCacheConfig(); cfg.setStreamFileThreshold(streamThreshold); WindowCache.reconfigure(cfg); - rng = new TestRng(getName()); repo = createBareRepository(); wc = (WindowCursor) repo.newObjectReader(); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (wc != null) wc.release(); WindowCache.reconfigure(new WindowCacheConfig()); super.tearDown(); } + @Test public void testStandardFormat_SmallObject() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); byte[] gz = compressStandardFormat(type, data); ObjectId id = ObjectId.zeroId(); @@ -119,9 +137,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testStandardFormat_LargeObject() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(streamThreshold + 5); + byte[] data = getRng().nextBytes(streamThreshold + 5); ObjectId id = new ObjectInserter.Formatter().idFor(type, data); write(id, compressStandardFormat(type, data)); @@ -159,9 +178,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testStandardFormat_NegativeSize() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressStandardFormat("blob", "-1", data); @@ -174,9 +194,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_InvalidType() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressStandardFormat("not.a.type", "1", data); @@ -189,6 +210,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_NoHeader() throws Exception { ObjectId id = ObjectId.zeroId(); byte[] data = {}; @@ -204,9 +226,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_GarbageAfterSize() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressStandardFormat("blob", "1foo", data); @@ -219,10 +242,11 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_SmallObject_CorruptZLibStream() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data); @@ -237,10 +261,11 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_SmallObject_TruncatedZLibStream() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data); @@ -255,10 +280,11 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_SmallObject_TrailingGarbage() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data); @@ -273,10 +299,11 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_LargeObject_CorruptZLibStream() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(streamThreshold + 5); + byte[] data = getRng().nextBytes(streamThreshold + 5); ObjectId id = new ObjectInserter.Formatter().idFor(type, data); byte[] gz = compressStandardFormat(type, data); gz[gz.length - 1] = 0; @@ -310,10 +337,11 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_LargeObject_TruncatedZLibStream() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(streamThreshold + 5); + byte[] data = getRng().nextBytes(streamThreshold + 5); ObjectId id = new ObjectInserter.Formatter().idFor(type, data); byte[] gz = compressStandardFormat(type, data); byte[] tr = new byte[gz.length - 1]; @@ -344,10 +372,11 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testStandardFormat_LargeObject_TrailingGarbage() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(streamThreshold + 5); + byte[] data = getRng().nextBytes(streamThreshold + 5); ObjectId id = new ObjectInserter.Formatter().idFor(type, data); byte[] gz = compressStandardFormat(type, data); byte[] tr = new byte[gz.length + 1]; @@ -378,9 +407,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { } } + @Test public void testPackFormat_SmallObject() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); byte[] gz = compressPackFormat(type, data); ObjectId id = ObjectId.zeroId(); @@ -402,9 +432,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testPackFormat_LargeObject() throws Exception { final int type = Constants.OBJ_BLOB; - byte[] data = rng.nextBytes(streamThreshold + 5); + byte[] data = getRng().nextBytes(streamThreshold + 5); ObjectId id = new ObjectInserter.Formatter().idFor(type, data); write(id, compressPackFormat(type, data)); @@ -442,9 +473,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { in.close(); } + @Test public void testPackFormat_DeltaNotAllowed() throws Exception { ObjectId id = ObjectId.zeroId(); - byte[] data = rng.nextBytes(300); + byte[] data = getRng().nextBytes(300); try { byte[] gz = compressPackFormat(Constants.OBJ_OFS_DELTA, data); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java index d8c682999..88600cefe 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; @@ -51,17 +55,20 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; -import org.eclipse.jgit.util.JGitTestUtil; import org.eclipse.jgit.util.MutableInteger; +import org.junit.Before; +import org.junit.Test; public class WindowCacheGetTest extends SampleDataRepositoryTestCase { private List toLoad; @Override + @Before public void setUp() throws Exception { super.setUp(); @@ -88,6 +95,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase { assertEquals(96, toLoad.size()); } + @Test public void testCache_Defaults() throws IOException { final WindowCacheConfig cfg = new WindowCacheConfig(); WindowCache.reconfigure(cfg); @@ -99,6 +107,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase { assertEquals(17346, cache.getOpenBytes()); } + @Test public void testCache_TooFewFiles() throws IOException { final WindowCacheConfig cfg = new WindowCacheConfig(); cfg.setPackedGitOpenFiles(2); @@ -107,6 +116,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase { checkLimits(cfg); } + @Test public void testCache_TooSmallLimit() throws IOException { final WindowCacheConfig cfg = new WindowCacheConfig(); cfg.setPackedGitWindowSize(4096); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheReconfigureTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheReconfigureTest.java index e52b19d92..384363bb9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheReconfigureTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheReconfigureTest.java @@ -43,9 +43,14 @@ package org.eclipse.jgit.storage.file; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class WindowCacheReconfigureTest extends RepositoryTestCase { + @Test public void testConfigureCache_PackedGitLimit_0() { try { final WindowCacheConfig cfg = new WindowCacheConfig(); @@ -57,6 +62,7 @@ public class WindowCacheReconfigureTest extends RepositoryTestCase { } } + @Test public void testConfigureCache_PackedGitWindowSize_0() { try { final WindowCacheConfig cfg = new WindowCacheConfig(); @@ -68,6 +74,7 @@ public class WindowCacheReconfigureTest extends RepositoryTestCase { } } + @Test public void testConfigureCache_PackedGitWindowSize_512() { try { final WindowCacheConfig cfg = new WindowCacheConfig(); @@ -79,6 +86,7 @@ public class WindowCacheReconfigureTest extends RepositoryTestCase { } } + @Test public void testConfigureCache_PackedGitWindowSize_4097() { try { final WindowCacheConfig cfg = new WindowCacheConfig(); @@ -90,6 +98,7 @@ public class WindowCacheReconfigureTest extends RepositoryTestCase { } } + @Test public void testConfigureCache_PackedGitOpenFiles_0() { try { final WindowCacheConfig cfg = new WindowCacheConfig(); @@ -101,6 +110,7 @@ public class WindowCacheReconfigureTest extends RepositoryTestCase { } } + @Test public void testConfigureCache_PackedGitWindowSizeAbovePackedGitLimit() { try { final WindowCacheConfig cfg = new WindowCacheConfig(); @@ -113,6 +123,7 @@ public class WindowCacheReconfigureTest extends RepositoryTestCase { } } + @Test public void testConfigureCache_Limits1() { // This test is just to force coverage over some lower bounds for // the table. We don't want the table to wind up with too small diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaIndexTest.java index 868ef8825..5da56ae3d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaIndexTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaIndexTest.java @@ -43,16 +43,21 @@ package org.eclipse.jgit.storage.pack; +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.IOException; import java.util.Arrays; -import junit.framework.TestCase; - +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.lib.Constants; +import org.junit.Before; +import org.junit.Test; -public class DeltaIndexTest extends TestCase { +public class DeltaIndexTest { private TestRng rng; private ByteArrayOutputStream actDeltaBuf; @@ -67,33 +72,42 @@ public class DeltaIndexTest extends TestCase { private ByteArrayOutputStream dstBuf; - protected void setUp() throws Exception { - super.setUp(); - rng = new TestRng(getName()); + private TestRng getRng() { + if (rng == null) + rng = new TestRng(JGitTestUtil.getName()); + return rng; + } + + @Before + public void setUp() throws Exception { actDeltaBuf = new ByteArrayOutputStream(); expDeltaBuf = new ByteArrayOutputStream(); expDeltaEnc = new DeltaEncoder(expDeltaBuf, 0, 0); dstBuf = new ByteArrayOutputStream(); } + @Test public void testInsertWholeObject_Length12() throws IOException { - src = rng.nextBytes(12); + src = getRng().nextBytes(12); insert(src); doTest(); } + @Test public void testCopyWholeObject_Length128() throws IOException { - src = rng.nextBytes(128); + src = getRng().nextBytes(128); copy(0, 128); doTest(); } + @Test public void testCopyWholeObject_Length123() throws IOException { - src = rng.nextBytes(123); + src = getRng().nextBytes(123); copy(0, 123); doTest(); } + @Test public void testCopyZeros_Length128() throws IOException { src = new byte[2048]; copy(0, src.length); @@ -106,15 +120,17 @@ public class DeltaIndexTest extends TestCase { assertEquals(2636, new DeltaIndex(src).getIndexSize()); } + @Test public void testShuffleSegments() throws IOException { - src = rng.nextBytes(128); + src = getRng().nextBytes(128); copy(64, 64); copy(0, 64); doTest(); } + @Test public void testInsertHeadMiddle() throws IOException { - src = rng.nextBytes(1024); + src = getRng().nextBytes(1024); insert("foo"); copy(0, 512); insert("yet more fooery"); @@ -122,38 +138,43 @@ public class DeltaIndexTest extends TestCase { doTest(); } + @Test public void testInsertTail() throws IOException { - src = rng.nextBytes(1024); + src = getRng().nextBytes(1024); copy(0, 512); insert("bar"); doTest(); } + @Test public void testIndexSize() { - src = rng.nextBytes(1024); + src = getRng().nextBytes(1024); DeltaIndex di = new DeltaIndex(src); assertEquals(1860, di.getIndexSize()); assertEquals("DeltaIndex[2 KiB]", di.toString()); } + @Test public void testLimitObjectSize_Length12InsertFails() throws IOException { - src = rng.nextBytes(12); + src = getRng().nextBytes(12); dst = src; DeltaIndex di = new DeltaIndex(src); assertFalse(di.encode(actDeltaBuf, dst, src.length)); } + @Test public void testLimitObjectSize_Length130InsertFails() throws IOException { - src = rng.nextBytes(130); - dst = rng.nextBytes(130); + src = getRng().nextBytes(130); + dst = getRng().nextBytes(130); DeltaIndex di = new DeltaIndex(src); assertFalse(di.encode(actDeltaBuf, dst, src.length)); } + @Test public void testLimitObjectSize_Length130CopyOk() throws IOException { - src = rng.nextBytes(130); + src = getRng().nextBytes(130); copy(0, 130); dst = dstBuf.toByteArray(); @@ -167,8 +188,9 @@ public class DeltaIndexTest extends TestCase { BinaryDelta.format(actDelta, false)); } + @Test public void testLimitObjectSize_Length130CopyFails() throws IOException { - src = rng.nextBytes(130); + src = getRng().nextBytes(130); copy(0, 130); dst = dstBuf.toByteArray(); @@ -180,8 +202,9 @@ public class DeltaIndexTest extends TestCase { assertEquals(4, actDeltaBuf.size()); } + @Test public void testLimitObjectSize_InsertFrontFails() throws IOException { - src = rng.nextBytes(130); + src = getRng().nextBytes(130); insert("eight"); copy(0, 130); dst = dstBuf.toByteArray(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaStreamTest.java index 3f3038b42..1d21739e0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaStreamTest.java @@ -43,21 +43,27 @@ package org.eclipse.jgit.storage.pack; +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.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import junit.framework.TestCase; - import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.IO; +import org.junit.Before; +import org.junit.Test; -public class DeltaStreamTest extends TestCase { +public class DeltaStreamTest { private TestRng rng; private ByteArrayOutputStream deltaBuf; @@ -72,18 +78,25 @@ public class DeltaStreamTest extends TestCase { private byte[] delta; - protected void setUp() throws Exception { - super.setUp(); - rng = new TestRng(getName()); + private TestRng getRng() { + if (rng == null) + rng = new TestRng(JGitTestUtil.getName()); + return rng; + } + + @Before + public void setUp() throws Exception { deltaBuf = new ByteArrayOutputStream(); } + @Test public void testCopy_SingleOp() throws IOException { init((1 << 16) + 1, (1 << 8) + 1); copy(0, data.length); assertValidState(); } + @Test public void testCopy_MaxSize() throws IOException { int max = (0xff << 16) + (0xff << 8) + 0xff; init(1 + max, max); @@ -91,6 +104,7 @@ public class DeltaStreamTest extends TestCase { assertValidState(); } + @Test public void testCopy_64k() throws IOException { init(0x10000 + 2, 0x10000 + 1); copy(1, 0x10000); @@ -98,6 +112,7 @@ public class DeltaStreamTest extends TestCase { assertValidState(); } + @Test public void testCopy_Gap() throws IOException { init(256, 8); copy(4, 4); @@ -105,6 +120,7 @@ public class DeltaStreamTest extends TestCase { assertValidState(); } + @Test public void testCopy_OutOfOrder() throws IOException { init((1 << 16) + 1, (1 << 16) + 1); copy(1 << 8, 1 << 8); @@ -112,12 +128,14 @@ public class DeltaStreamTest extends TestCase { assertValidState(); } + @Test public void testInsert_SingleOp() throws IOException { init((1 << 16) + 1, 2); insert("hi"); assertValidState(); } + @Test public void testInsertAndCopy() throws IOException { init(8, 512); insert(new byte[127]); @@ -128,6 +146,7 @@ public class DeltaStreamTest extends TestCase { assertValidState(); } + @Test public void testSkip() throws IOException { init(32, 15); copy(2, 2); @@ -175,6 +194,7 @@ public class DeltaStreamTest extends TestCase { assertTrue("now open", opened[0]); } + @Test public void testIncorrectBaseSize() throws IOException { init(4, 4); copy(0, 4); @@ -218,7 +238,7 @@ public class DeltaStreamTest extends TestCase { } private void init(int baseSize, int dataSize) throws IOException { - base = rng.nextBytes(baseSize); + base = getRng().nextBytes(baseSize); data = new byte[dataSize]; deltaEnc = new DeltaEncoder(deltaBuf, baseSize, dataSize); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/stringext/TestStringExternalization.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/stringext/TestStringExternalization.java index 8c4bc229a..cd2d63046 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/stringext/TestStringExternalization.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/stringext/TestStringExternalization.java @@ -43,8 +43,6 @@ package org.eclipse.jgit.stringext; -import junit.framework.TestCase; - import org.eclipse.jgit.JGitText; import org.eclipse.jgit.awtui.UIText; import org.eclipse.jgit.console.ConsoleText; @@ -53,7 +51,7 @@ import org.eclipse.jgit.iplog.IpLogText; import org.eclipse.jgit.nls.NLS; import org.eclipse.jgit.pgm.CLIText; -public class TestStringExternalization extends TestCase { +public class TestStringExternalization { private static Class[] translationBundleClasses = new Class[] { ConsoleText.class, HttpServerText.class, IpLogText.class, CLIText.class, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index cc7056225..332d802cb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -45,6 +45,11 @@ package org.eclipse.jgit.transport; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; @@ -63,9 +68,11 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.junit.Test; public class BundleWriterTest extends SampleDataRepositoryTestCase { + @Test public void testWrite0() throws Exception { // Create a tiny bundle, (well one of) the first commits only final byte[] bundle = makeBundle("refs/heads/firstcommit", @@ -92,6 +99,7 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase { * * @throws Exception */ + @Test public void testWrite1() throws Exception { byte[] bundle; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/IndexPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/IndexPackTest.java index 65929059a..c75474550 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/IndexPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/IndexPackTest.java @@ -46,6 +46,8 @@ package org.eclipse.jgit.transport; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -54,6 +56,7 @@ import java.io.InputStream; import java.security.MessageDigest; import java.util.zip.Deflater; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; @@ -63,9 +66,9 @@ import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.storage.file.PackFile; -import org.eclipse.jgit.util.JGitTestUtil; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.TemporaryBuffer; +import org.junit.Test; /** * Test indexing of git packs. A pack is read from a stream, copied @@ -80,6 +83,7 @@ public class IndexPackTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void test1() throws IOException { File packFile = JGitTestUtil.getTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"); final InputStream is = new FileInputStream(packFile); @@ -106,6 +110,7 @@ public class IndexPackTest extends RepositoryTestCase { * * @throws IOException */ + @Test public void test2() throws IOException { File packFile = JGitTestUtil.getTestResourceFile("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack"); final InputStream is = new FileInputStream(packFile); @@ -131,6 +136,7 @@ public class IndexPackTest extends RepositoryTestCase { } } + @Test public void testTinyThinPack() throws Exception { TestRepository d = new TestRepository(db); RevBlob a = d.blob("a"); @@ -152,6 +158,7 @@ public class IndexPackTest extends RepositoryTestCase { ip.renameAndOpenPack(); } + @Test public void testPackWithDuplicateBlob() throws Exception { final byte[] data = Constants.encode("0123456789abcdefg"); TestRepository d = new TestRepository(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java index abb6fe0db..3e427e5df 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java @@ -43,16 +43,24 @@ package org.eclipse.jgit.transport; -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 LongMapTest extends TestCase { +import org.junit.Before; +import org.junit.Test; + +public class LongMapTest { private LongMap map; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { map = new LongMap(); } + @Test public void testEmptyMap() { assertFalse(map.containsKey(0)); assertFalse(map.containsKey(1)); @@ -64,6 +72,7 @@ public class LongMapTest extends TestCase { assertNull(map.remove(1)); } + @Test public void testInsertMinValue() { final Long min = Long.valueOf(Long.MIN_VALUE); assertNull(map.put(Long.MIN_VALUE, min)); @@ -72,6 +81,7 @@ public class LongMapTest extends TestCase { assertFalse(map.containsKey(Integer.MIN_VALUE)); } + @Test public void testReplaceMaxValue() { final Long min = Long.valueOf(Long.MAX_VALUE); final Long one = Long.valueOf(1); @@ -81,6 +91,7 @@ public class LongMapTest extends TestCase { assertSame(one, map.get(Long.MAX_VALUE)); } + @Test public void testRemoveOne() { final long start = 1; assertNull(map.put(start, Long.valueOf(start))); @@ -88,6 +99,7 @@ public class LongMapTest extends TestCase { assertFalse(map.containsKey(start)); } + @Test public void testRemoveCollision1() { // This test relies upon the fact that we always >>> 1 the value // to derive an unsigned hash code. Thus, 0 and 1 fall into the @@ -103,6 +115,7 @@ public class LongMapTest extends TestCase { assertTrue(map.containsKey(1)); } + @Test public void testRemoveCollision2() { // This test relies upon the fact that we always >>> 1 the value // to derive an unsigned hash code. Thus, 0 and 1 fall into the @@ -118,6 +131,7 @@ public class LongMapTest extends TestCase { assertFalse(map.containsKey(1)); } + @Test public void testSmallMap() { final long start = 12; final long n = 8; @@ -127,6 +141,7 @@ public class LongMapTest extends TestCase { assertEquals(Long.valueOf(i), map.get(i)); } + @Test public void testLargeMap() { final long start = Integer.MAX_VALUE; final long n = 100000; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java index f66e2fd33..966cd9812 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.transport; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -50,6 +54,8 @@ import java.io.OutputStreamWriter; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.transport.OpenSshConfig.Host; +import org.junit.Before; +import org.junit.Test; public class OpenSshConfigTest extends RepositoryTestCase { private File home; @@ -58,6 +64,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { private OpenSshConfig osc; + @Before public void setUp() throws Exception { super.setUp(); @@ -78,6 +85,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { fw.close(); } + @Test public void testNoConfig() { final Host h = osc.lookup("repo.or.cz"); assertNotNull(h); @@ -87,6 +95,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertNull(h.getIdentityFile()); } + @Test public void testSeparatorParsing() throws Exception { config("Host\tfirst\n" + "\tHostName\tfirst.tld\n" + @@ -111,6 +120,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals("last.tld", osc.lookup("last").getHostName()); } + @Test public void testQuoteParsing() throws Exception { config("Host \"good\"\n" + " HostName=\"good.tld\"\n" + @@ -137,6 +147,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals("bad.tld\"", osc.lookup("bad").getHostName()); } + @Test public void testAlias_DoesNotMatch() throws Exception { config("Host orcz\n" + "\tHostName repo.or.cz\n"); final Host h = osc.lookup("repo.or.cz"); @@ -147,6 +158,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertNull(h.getIdentityFile()); } + @Test public void testAlias_OptionsSet() throws Exception { config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\tPort 2222\n" + "\tUser jex\n" + "\tIdentityFile .ssh/id_jex\n" @@ -159,6 +171,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals(new File(home, ".ssh/id_jex"), h.getIdentityFile()); } + @Test public void testAlias_OptionsKeywordCaseInsensitive() throws Exception { config("hOsT orcz\n" + "\thOsTnAmE repo.or.cz\n" + "\tPORT 2222\n" + "\tuser jex\n" + "\tidentityfile .ssh/id_jex\n" @@ -171,6 +184,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals(new File(home, ".ssh/id_jex"), h.getIdentityFile()); } + @Test public void testAlias_OptionsInherit() throws Exception { config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + "\tHostName not.a.host.example.com\n" + "\tPort 2222\n" @@ -184,12 +198,14 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals(new File(home, ".ssh/id_jex"), h.getIdentityFile()); } + @Test public void testAlias_PreferredAuthenticationsDefault() throws Exception { final Host h = osc.lookup("orcz"); assertNotNull(h); assertNull(h.getPreferredAuthentications()); } + @Test public void testAlias_PreferredAuthentications() throws Exception { config("Host orcz\n" + "\tPreferredAuthentications publickey\n"); final Host h = osc.lookup("orcz"); @@ -197,6 +213,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals("publickey", h.getPreferredAuthentications()); } + @Test public void testAlias_InheritPreferredAuthentications() throws Exception { config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + "\tPreferredAuthentications publickey, hostbased\n"); @@ -205,12 +222,14 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals("publickey,hostbased", h.getPreferredAuthentications()); } + @Test public void testAlias_BatchModeDefault() throws Exception { final Host h = osc.lookup("orcz"); assertNotNull(h); assertEquals(false, h.isBatchMode()); } + @Test public void testAlias_BatchModeYes() throws Exception { config("Host orcz\n" + "\tBatchMode yes\n"); final Host h = osc.lookup("orcz"); @@ -218,6 +237,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { assertEquals(true, h.isBatchMode()); } + @Test public void testAlias_InheritBatchMode() throws Exception { config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + "\tBatchMode yes\n"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java index 851dcc07b..59b019e6a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java @@ -43,26 +43,32 @@ package org.eclipse.jgit.transport; +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 static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.IOException; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.ObjectId; +import org.junit.Test; // Note, test vectors created with: // // perl -e 'printf "%4.4x%s\n", 4+length($ARGV[0]),$ARGV[0]' -public class PacketLineInTest extends TestCase { +public class PacketLineInTest { private ByteArrayInputStream rawIn; private PacketLineIn in; // readString + @Test public void testReadString1() throws IOException { init("0006a\n0007bc\n"); assertEquals("a", in.readString()); @@ -70,6 +76,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadString2() throws IOException { init("0032want fcfcfb1fd94829c1a1704f894fc111d14770d34e\n"); final String act = in.readString(); @@ -77,6 +84,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadString4() throws IOException { init("0005a0006bc"); assertEquals("a", in.readString()); @@ -84,6 +92,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadString5() throws IOException { // accept both upper and lower case init("000Fhi i am a s"); @@ -95,6 +104,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadString_LenHELO() { init("HELO"); try { @@ -105,6 +115,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadString_Len0001() { init("0001"); try { @@ -115,6 +126,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadString_Len0002() { init("0002"); try { @@ -125,6 +137,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadString_Len0003() { init("0003"); try { @@ -135,6 +148,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadString_Len0004() throws IOException { init("0004"); final String act = in.readString(); @@ -143,6 +157,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadString_End() throws IOException { init("0000"); assertSame(PacketLineIn.END, in.readString()); @@ -151,6 +166,7 @@ public class PacketLineInTest extends TestCase { // readStringNoLF + @Test public void testReadStringRaw1() throws IOException { init("0005a0006bc"); assertEquals("a", in.readStringRaw()); @@ -158,6 +174,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadStringRaw2() throws IOException { init("0031want fcfcfb1fd94829c1a1704f894fc111d14770d34e"); final String act = in.readStringRaw(); @@ -165,6 +182,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadStringRaw3() throws IOException { init("0004"); final String act = in.readStringRaw(); @@ -173,12 +191,14 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadStringRaw_End() throws IOException { init("0000"); assertSame(PacketLineIn.END, in.readStringRaw()); assertEOF(); } + @Test public void testReadStringRaw4() { init("HELO"); try { @@ -191,6 +211,7 @@ public class PacketLineInTest extends TestCase { // readACK + @Test public void testReadACK_NAK() throws IOException { final ObjectId expid = ObjectId .fromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e"); @@ -203,6 +224,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadACK_ACK1() throws IOException { final ObjectId expid = ObjectId .fromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e"); @@ -214,6 +236,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadACK_ACKcontinue1() throws IOException { final ObjectId expid = ObjectId .fromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e"); @@ -225,6 +248,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadACK_ACKcommon1() throws IOException { final ObjectId expid = ObjectId .fromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e"); @@ -236,6 +260,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadACK_ACKready1() throws IOException { final ObjectId expid = ObjectId .fromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e"); @@ -247,6 +272,7 @@ public class PacketLineInTest extends TestCase { assertEOF(); } + @Test public void testReadACK_Invalid1() { init("HELO"); try { @@ -257,6 +283,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadACK_Invalid2() { init("0009HELO\n"); try { @@ -267,6 +294,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadACK_Invalid3() { String s = "ACK fcfcfb1fd94829c1a1704f894fc111d14770d34e neverhappen"; init("003d" + s + "\n"); @@ -278,6 +306,7 @@ public class PacketLineInTest extends TestCase { } } + @Test public void testReadACK_Invalid4() { init("0000"); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java index c66d4d52a..eca54756b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java @@ -43,43 +43,49 @@ package org.eclipse.jgit.transport; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.Constants; +import org.junit.Before; +import org.junit.Test; // Note, test vectors created with: // // perl -e 'printf "%4.4x%s\n", 4+length($ARGV[0]),$ARGV[0]' -public class PacketLineOutTest extends TestCase { +public class PacketLineOutTest { private ByteArrayOutputStream rawOut; private PacketLineOut out; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { rawOut = new ByteArrayOutputStream(); out = new PacketLineOut(rawOut); } // writeString + @Test public void testWriteString1() throws IOException { out.writeString("a"); out.writeString("bc"); assertBuffer("0005a0006bc"); } + @Test public void testWriteString2() throws IOException { out.writeString("a\n"); out.writeString("bc\n"); assertBuffer("0006a\n0007bc\n"); } + @Test public void testWriteString3() throws IOException { out.writeString(""); assertBuffer("0004"); @@ -87,6 +93,7 @@ public class PacketLineOutTest extends TestCase { // end + @Test public void testWriteEnd() throws IOException { final int[] flushCnt = new int[1]; final OutputStream mockout = new OutputStream() { @@ -108,16 +115,19 @@ public class PacketLineOutTest extends TestCase { // writePacket + @Test public void testWritePacket1() throws IOException { out.writePacket(new byte[] { 'a' }); assertBuffer("0005a"); } + @Test public void testWritePacket2() throws IOException { out.writePacket(new byte[] { 'a', 'b', 'c', 'd' }); assertBuffer("0008abcd"); } + @Test public void testWritePacket3() throws IOException { final int buflen = SideBandOutputStream.MAX_BUF - 5; final byte[] buf = new byte[buflen]; @@ -138,6 +148,7 @@ public class PacketLineOutTest extends TestCase { // flush + @Test public void testFlush() throws IOException { final int[] flushCnt = new int[1]; final OutputStream mockout = new OutputStream() { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java index 99edbd98c..bb009e913 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.transport; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.HashMap; import java.util.HashSet; @@ -54,11 +58,13 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.lib.TextProgressMonitor; -import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.transport.RemoteRefUpdate.Status; +import org.junit.Before; +import org.junit.Test; public class PushProcessTest extends SampleDataRepositoryTestCase { private PushProcess process; @@ -72,6 +78,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { private Status connectionUpdateStatus; @Override + @Before public void setUp() throws Exception { super.setUp(); transport = new MockTransport(db, new URIish()); @@ -85,6 +92,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateFastForward() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -100,6 +108,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateNonFastForwardUnknownObject() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -115,6 +124,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateNonFastForward() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", @@ -129,6 +139,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateNonFastForwardForced() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", @@ -143,6 +154,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateCreateRef() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", @@ -155,6 +167,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateDelete() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, null, "refs/heads/master", false, null, null); @@ -169,6 +182,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateDeleteNonExisting() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, null, "refs/heads/master", false, null, null); @@ -180,6 +194,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateUpToDate() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -194,6 +209,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateExpectedRemote() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -210,6 +226,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateUnexpectedRemote() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -227,6 +244,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateUnexpectedRemoteVsForce() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -242,6 +260,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateRejectedByConnection() throws IOException { connectionUpdateStatus = Status.REJECTED_OTHER_REASON; final RemoteRefUpdate rru = new RemoteRefUpdate(db, @@ -258,6 +277,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testUpdateMixedCases() throws IOException { final RemoteRefUpdate rruOk = new RemoteRefUpdate(db, null, "refs/heads/master", false, null, null); @@ -279,6 +299,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testTrackingRefUpdateEnabled() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -300,6 +321,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testTrackingRefUpdateDisabled() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", @@ -317,6 +339,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testTrackingRefUpdateOnReject() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", @@ -333,6 +356,7 @@ public class PushProcessTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testPushResult() throws IOException { final RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java index 3483b9d16..4aea1be02 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java @@ -43,6 +43,14 @@ package org.eclipse.jgit.transport; +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.ByteArrayInputStream; import java.io.IOException; import java.net.URISyntaxException; @@ -69,6 +77,9 @@ import org.eclipse.jgit.storage.file.ObjectDirectory; import org.eclipse.jgit.storage.pack.BinaryDelta; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.TemporaryBuffer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { private static final NullProgressMonitor PM = NullProgressMonitor.INSTANCE; @@ -86,7 +97,8 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { private RevBlob a, b; @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); src = createBareRepository(); @@ -118,7 +130,8 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { } @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (src != null) src.close(); if (dst != null) @@ -126,6 +139,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { super.tearDown(); } + @Test public void testFilterHidesPrivate() throws Exception { Map refs; TransportLocal t = new TransportLocal(src, uriOf(dst)) { @@ -160,6 +174,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { assertEquals(B, master.getObjectId()); } + @Test public void testSuccess() throws Exception { // Manually force a delta of an object so we reuse it later. // @@ -225,6 +240,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { assertEquals(N, dst.resolve(R_MASTER)); } + @Test public void testCreateBranchAtHiddenCommitFails() throws Exception { final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64); packHeader(pack, 0); @@ -271,6 +287,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); } + @Test public void testUsingHiddenDeltaBaseFails() throws Exception { byte[] delta = { 0x1, 0x1, 0x1, 'c' }; TestRepository s = new TestRepository(src); @@ -322,6 +339,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { assertSame(PacketLineIn.END, r.readString()); } + @Test public void testUsingHiddenCommonBlobFails() throws Exception { // Try to use the 'b' blob that is hidden. // @@ -371,6 +389,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { assertSame(PacketLineIn.END, r.readString()); } + @Test public void testUsingUnknownBlobFails() throws Exception { // Try to use the 'n' blob that is not on the server. // @@ -421,6 +440,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { assertSame(PacketLineIn.END, r.readString()); } + @Test public void testUsingUnknownTreeFails() throws Exception { TestRepository s = new TestRepository(src); RevCommit N = s.commit().parent(B).add("q", s.blob("a")).create(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java index 955b0c95e..871741f69 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java @@ -44,12 +44,19 @@ package org.eclipse.jgit.transport; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; +import org.junit.Test; -public class RefSpecTest extends TestCase { +public class RefSpecTest { + @Test public void testMasterMaster() { final String sn = "refs/heads/master"; final RefSpec rs = new RefSpec(sn + ":" + sn); @@ -70,6 +77,7 @@ public class RefSpecTest extends TestCase { assertFalse(rs.matchDestination(r)); } + @Test public void testSplitLastColon() { final String lhs = ":m:a:i:n:t"; final String rhs = "refs/heads/maint"; @@ -82,6 +90,7 @@ public class RefSpecTest extends TestCase { assertEquals(rs, new RefSpec(rs.toString())); } + @Test public void testForceMasterMaster() { final String sn = "refs/heads/master"; final RefSpec rs = new RefSpec("+" + sn + ":" + sn); @@ -102,6 +111,7 @@ public class RefSpecTest extends TestCase { assertFalse(rs.matchDestination(r)); } + @Test public void testMaster() { final String sn = "refs/heads/master"; final RefSpec rs = new RefSpec(sn); @@ -122,6 +132,7 @@ public class RefSpecTest extends TestCase { assertFalse(rs.matchDestination(r)); } + @Test public void testForceMaster() { final String sn = "refs/heads/master"; final RefSpec rs = new RefSpec("+" + sn); @@ -142,6 +153,7 @@ public class RefSpecTest extends TestCase { assertFalse(rs.matchDestination(r)); } + @Test public void testDeleteMaster() { final String sn = "refs/heads/master"; final RefSpec rs = new RefSpec(":" + sn); @@ -162,6 +174,7 @@ public class RefSpecTest extends TestCase { assertFalse(rs.matchDestination(r)); } + @Test public void testForceRemotesOrigin() { final String srcn = "refs/heads/*"; final String dstn = "refs/remotes/origin/*"; @@ -195,6 +208,7 @@ public class RefSpecTest extends TestCase { assertFalse(rs.matchDestination(r)); } + @Test public void testCreateEmpty() { final RefSpec rs = new RefSpec(); assertFalse(rs.isForceUpdate()); @@ -204,6 +218,7 @@ public class RefSpecTest extends TestCase { assertEquals("HEAD", rs.toString()); } + @Test public void testSetForceUpdate() { final String s = "refs/heads/*:refs/remotes/origin/*"; final RefSpec a = new RefSpec(s); @@ -216,6 +231,7 @@ public class RefSpecTest extends TestCase { assertEquals("+" + s, b.toString()); } + @Test public void testSetSource() { final RefSpec a = new RefSpec(); final RefSpec b = a.setSource("refs/heads/master"); @@ -224,6 +240,7 @@ public class RefSpecTest extends TestCase { assertEquals("refs/heads/master", b.toString()); } + @Test public void testSetDestination() { final RefSpec a = new RefSpec(); final RefSpec b = a.setDestination("refs/heads/master"); @@ -232,6 +249,7 @@ public class RefSpecTest extends TestCase { assertEquals("HEAD:refs/heads/master", b.toString()); } + @Test public void testSetDestination_SourceNull() { final RefSpec a = new RefSpec(); RefSpec b; @@ -243,6 +261,7 @@ public class RefSpecTest extends TestCase { assertEquals(":refs/heads/master", b.toString()); } + @Test public void testSetSourceDestination() { final RefSpec a = new RefSpec(); final RefSpec b; @@ -252,6 +271,7 @@ public class RefSpecTest extends TestCase { assertEquals("refs/heads/*:refs/remotes/origin/*", b.toString()); } + @Test public void testExpandFromDestination_NonWildcard() { final String src = "refs/heads/master"; final String dst = "refs/remotes/origin/master"; @@ -263,6 +283,7 @@ public class RefSpecTest extends TestCase { assertEquals(dst, r.getDestination()); } + @Test public void testExpandFromDestination_Wildcard() { final String src = "refs/heads/master"; final String dst = "refs/remotes/origin/master"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java index 3d9b51f9b..03a6c019e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java @@ -44,18 +44,24 @@ package org.eclipse.jgit.transport; -import java.util.List; +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 junit.framework.TestCase; +import java.util.List; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.Config; +import org.junit.Before; +import org.junit.Test; -public class RemoteConfigTest extends TestCase { +public class RemoteConfigTest { private Config config; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { config = new Config(); } @@ -68,10 +74,7 @@ public class RemoteConfigTest extends TestCase { assertEquals(exp, config.toText()); } - private static void assertEquals(final String exp, final URIish act) { - assertEquals(exp, act != null ? act.toString() : null); - } - + @Test public void testSimple() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -90,7 +93,8 @@ public class RemoteConfigTest extends TestCase { assertSame(TagOpt.AUTO_FOLLOW, rc.getTagOpt()); assertEquals(1, allURIs.size()); - assertEquals("http://www.spearce.org/egit.git", allURIs.get(0)); + assertEquals("http://www.spearce.org/egit.git", allURIs.get(0) + .toString()); assertEquals(1, rc.getFetchRefSpecs().size()); spec = rc.getFetchRefSpecs().get(0); @@ -102,6 +106,7 @@ public class RemoteConfigTest extends TestCase { assertEquals(0, rc.getPushRefSpecs().size()); } + @Test public void testSimpleNoTags() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -111,6 +116,7 @@ public class RemoteConfigTest extends TestCase { assertSame(TagOpt.NO_TAGS, rc.getTagOpt()); } + @Test public void testSimpleAlwaysTags() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -120,6 +126,7 @@ public class RemoteConfigTest extends TestCase { assertSame(TagOpt.FETCH_TAGS, rc.getTagOpt()); } + @Test public void testMirror() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -136,7 +143,8 @@ public class RemoteConfigTest extends TestCase { assertNotNull(rc.getPushRefSpecs()); assertEquals(1, allURIs.size()); - assertEquals("http://www.spearce.org/egit.git", allURIs.get(0)); + assertEquals("http://www.spearce.org/egit.git", allURIs.get(0) + .toString()); assertEquals(2, rc.getFetchRefSpecs().size()); @@ -155,6 +163,7 @@ public class RemoteConfigTest extends TestCase { assertEquals(0, rc.getPushRefSpecs().size()); } + @Test public void testBackup() throws Exception { readConfig("[remote \"backup\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -172,8 +181,10 @@ public class RemoteConfigTest extends TestCase { assertNotNull(rc.getPushRefSpecs()); assertEquals(2, allURIs.size()); - assertEquals("http://www.spearce.org/egit.git", allURIs.get(0)); - assertEquals("user@repo.or.cz:/srv/git/egit.git", allURIs.get(1)); + assertEquals("http://www.spearce.org/egit.git", allURIs.get(0) + .toString()); + assertEquals("user@repo.or.cz:/srv/git/egit.git", allURIs.get(1) + .toString()); assertEquals(0, rc.getFetchRefSpecs().size()); @@ -191,6 +202,7 @@ public class RemoteConfigTest extends TestCase { assertEquals("refs/tags/*", spec.getDestination()); } + @Test public void testUploadPack() throws Exception { readConfig("[remote \"example\"]\n" + "url = user@example.com:egit.git\n" @@ -208,7 +220,7 @@ public class RemoteConfigTest extends TestCase { assertNotNull(rc.getPushRefSpecs()); assertEquals(1, allURIs.size()); - assertEquals("user@example.com:egit.git", allURIs.get(0)); + assertEquals("user@example.com:egit.git", allURIs.get(0).toString()); assertEquals(1, rc.getFetchRefSpecs().size()); spec = rc.getFetchRefSpecs().get(0); @@ -223,6 +235,7 @@ public class RemoteConfigTest extends TestCase { assertEquals("/path/to/git/git-receive-pack", rc.getReceivePack()); } + @Test public void testUnknown() throws Exception { readConfig(""); @@ -234,6 +247,7 @@ public class RemoteConfigTest extends TestCase { assertEquals("git-receive-pack", rc.getReceivePack()); } + @Test public void testAddURI() throws Exception { readConfig(""); @@ -249,6 +263,7 @@ public class RemoteConfigTest extends TestCase { assertEquals(1, rc.getURIs().size()); } + @Test public void testRemoveFirstURI() throws Exception { readConfig(""); @@ -271,6 +286,7 @@ public class RemoteConfigTest extends TestCase { assertSame(c, rc.getURIs().get(1)); } + @Test public void testRemoveMiddleURI() throws Exception { readConfig(""); @@ -293,6 +309,7 @@ public class RemoteConfigTest extends TestCase { assertSame(c, rc.getURIs().get(1)); } + @Test public void testRemoveLastURI() throws Exception { readConfig(""); @@ -315,6 +332,7 @@ public class RemoteConfigTest extends TestCase { assertSame(b, rc.getURIs().get(1)); } + @Test public void testRemoveOnlyURI() throws Exception { readConfig(""); @@ -329,6 +347,7 @@ public class RemoteConfigTest extends TestCase { assertEquals(0, rc.getURIs().size()); } + @Test public void testCreateOrigin() throws Exception { final RemoteConfig rc = new RemoteConfig(config, "origin"); rc.addURI(new URIish("/some/dir")); @@ -339,6 +358,7 @@ public class RemoteConfigTest extends TestCase { + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"); } + @Test public void testSaveAddURI() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -354,6 +374,7 @@ public class RemoteConfigTest extends TestCase { + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n"); } + @Test public void testSaveRemoveLastURI() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -370,6 +391,7 @@ public class RemoteConfigTest extends TestCase { + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n"); } + @Test public void testSaveRemoveFirstURI() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -385,6 +407,7 @@ public class RemoteConfigTest extends TestCase { + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n"); } + @Test public void testSaveNoTags() throws Exception { final RemoteConfig rc = new RemoteConfig(config, "origin"); rc.addURI(new URIish("/some/dir")); @@ -397,6 +420,7 @@ public class RemoteConfigTest extends TestCase { + "\ttagopt = --no-tags\n"); } + @Test public void testSaveAllTags() throws Exception { final RemoteConfig rc = new RemoteConfig(config, "origin"); rc.addURI(new URIish("/some/dir")); @@ -409,6 +433,7 @@ public class RemoteConfigTest extends TestCase { + "\ttagopt = --tags\n"); } + @Test public void testSimpleTimeout() throws Exception { readConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" @@ -418,6 +443,7 @@ public class RemoteConfigTest extends TestCase { assertEquals(12, rc.getTimeout()); } + @Test public void testSaveTimeout() throws Exception { final RemoteConfig rc = new RemoteConfig(config, "origin"); rc.addURI(new URIish("/some/dir")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java index 156e4d023..d9eaee680 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java @@ -49,29 +49,32 @@ import static org.eclipse.jgit.transport.SideBandOutputStream.CH_PROGRESS; import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE; import static org.eclipse.jgit.transport.SideBandOutputStream.MAX_BUF; import static org.eclipse.jgit.transport.SideBandOutputStream.SMALL_BUF; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.text.MessageFormat; -import junit.framework.TestCase; - import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.Constants; +import org.junit.Before; +import org.junit.Test; // Note, test vectors created with: // // perl -e 'printf "%4.4x%s\n", 4+length($ARGV[0]),$ARGV[0]' -public class SideBandOutputStreamTest extends TestCase { +public class SideBandOutputStreamTest { private ByteArrayOutputStream rawOut; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { rawOut = new ByteArrayOutputStream(); } + @Test public void testWrite_CH_DATA() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_DATA, SMALL_BUF, rawOut); @@ -80,6 +83,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0008\001abc"); } + @Test public void testWrite_CH_PROGRESS() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_PROGRESS, SMALL_BUF, rawOut); @@ -88,6 +92,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0008\002abc"); } + @Test public void testWrite_CH_ERROR() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_ERROR, SMALL_BUF, rawOut); @@ -96,6 +101,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0008\003abc"); } + @Test public void testWrite_Small() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_DATA, SMALL_BUF, rawOut); @@ -106,6 +112,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0008\001abc"); } + @Test public void testWrite_SmallBlocks1() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_DATA, 6, rawOut); @@ -116,6 +123,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0006\001a0006\001b0006\001c"); } + @Test public void testWrite_SmallBlocks2() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_DATA, 6, rawOut); @@ -124,6 +132,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0006\001a0006\001b0006\001c"); } + @Test public void testWrite_SmallBlocks3() throws IOException { final SideBandOutputStream out; out = new SideBandOutputStream(CH_DATA, 7, rawOut); @@ -133,6 +142,7 @@ public class SideBandOutputStreamTest extends TestCase { assertBuffer("0007\001ab0006\001c"); } + @Test public void testWrite_Large() throws IOException { final int buflen = MAX_BUF - HDR_SIZE; final byte[] buf = new byte[buflen]; @@ -155,6 +165,7 @@ public class SideBandOutputStreamTest extends TestCase { } } + @Test public void testFlush() throws IOException { final int[] flushCnt = new int[1]; final OutputStream mockout = new OutputStream() { @@ -173,6 +184,7 @@ public class SideBandOutputStreamTest extends TestCase { assertEquals(1, flushCnt[0]); } + @Test public void testConstructor_RejectsBadChannel() { try { new SideBandOutputStream(-1, MAX_BUF, rawOut); @@ -197,6 +209,7 @@ public class SideBandOutputStreamTest extends TestCase { } } + @Test public void testConstructor_RejectsBadBufferSize() { try { new SideBandOutputStream(CH_DATA, -1, rawOut); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java index a6bdd8886..1233d699f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java @@ -43,6 +43,11 @@ package org.eclipse.jgit.transport; +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.IOException; import java.util.Arrays; import java.util.Collection; @@ -50,6 +55,9 @@ import java.util.Collections; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class TransportTest extends SampleDataRepositoryTestCase { private Transport transport; @@ -57,6 +65,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { private RemoteConfig remoteConfig; @Override + @Before public void setUp() throws Exception { super.setUp(); final Config config = db.getConfig(); @@ -66,7 +75,8 @@ public class TransportTest extends SampleDataRepositoryTestCase { } @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (transport != null) { transport.close(); transport = null; @@ -80,6 +90,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testFindRemoteRefUpdatesNoWildcardNoTracking() throws IOException { transport = Transport.open(db, remoteConfig); @@ -102,6 +113,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testFindRemoteRefUpdatesNoWildcardNoDestination() throws IOException { transport = Transport.open(db, remoteConfig); @@ -123,6 +135,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testFindRemoteRefUpdatesWildcardNoTracking() throws IOException { transport = Transport.open(db, remoteConfig); final Collection result = transport @@ -150,6 +163,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testFindRemoteRefUpdatesTwoRefSpecs() throws IOException { transport = Transport.open(db, remoteConfig); final RefSpec specA = new RefSpec("+refs/heads/a:refs/heads/b"); @@ -178,6 +192,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { * * @throws IOException */ + @Test public void testFindRemoteRefUpdatesTrackingRef() throws IOException { remoteConfig.addFetchRefSpec(new RefSpec( "refs/heads/*:refs/remotes/test/*")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index 93d909d7d..34dadf39e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -45,16 +45,23 @@ package org.eclipse.jgit.transport; +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.io.File; import java.io.IOException; import java.net.URISyntaxException; -import junit.framework.TestCase; +import org.junit.Test; -public class URIishTest extends TestCase { +public class URIishTest { private static final String GIT_SCHEME = "git://"; + @Test public void testUnixFile() throws Exception { final String str = "/home/m y"; URIish u = new URIish(str); @@ -65,6 +72,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testWindowsFile() throws Exception { final String str = "D:/m y"; URIish u = new URIish(str); @@ -75,6 +83,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testWindowsFile2() throws Exception { final String str = "D:\\m y"; URIish u = new URIish(str); @@ -85,6 +94,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testRelativePath() throws Exception { final String str = "../../foo/bar"; URIish u = new URIish(str); @@ -95,6 +105,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testUNC() throws Exception { final String str = "\\\\some\\place"; URIish u = new URIish(str); @@ -105,6 +116,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testFileProtoUnix() throws Exception { final String str = "file:///home/m y"; URIish u = new URIish(str); @@ -115,6 +127,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testFileProtoWindows() throws Exception { final String str = "file:///D:/m y"; URIish u = new URIish(str); @@ -125,6 +138,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGitProtoUnix() throws Exception { final String str = "git://example.com/home/m y"; URIish u = new URIish(str); @@ -136,6 +150,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGitProtoUnixPort() throws Exception { final String str = "git://example.com:333/home/m y"; URIish u = new URIish(str); @@ -148,6 +163,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGitProtoWindowsPort() throws Exception { final String str = "git://example.com:338/D:/m y"; URIish u = new URIish(str); @@ -160,6 +176,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGitProtoWindows() throws Exception { final String str = "git://example.com/D:/m y"; URIish u = new URIish(str); @@ -172,6 +189,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testScpStyleWithoutUserRelativePath() throws Exception { final String str = "example.com:some/p ath"; URIish u = new URIish(str); @@ -184,6 +202,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testScpStyleWithoutUserAbsolutePath() throws Exception { final String str = "example.com:/some/p ath"; URIish u = new URIish(str); @@ -196,6 +215,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testScpStyleWithUser() throws Exception { final String str = "user@example.com:some/p ath"; URIish u = new URIish(str); @@ -209,6 +229,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGitSshProto() throws Exception { final String str = "git+ssh://example.com/some/p ath"; URIish u = new URIish(str); @@ -221,6 +242,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testSshGitProto() throws Exception { final String str = "ssh+git://example.com/some/p ath"; URIish u = new URIish(str); @@ -233,6 +255,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testSshProto() throws Exception { final String str = "ssh://example.com/some/p ath"; URIish u = new URIish(str); @@ -245,6 +268,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testSshProtoWithUserAndPort() throws Exception { final String str = "ssh://user@example.com:33/some/p ath"; URIish u = new URIish(str); @@ -259,6 +283,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testSshProtoWithUserPassAndPort() throws Exception { final String str = "ssh://user:pass@example.com:33/some/p ath"; URIish u = new URIish(str); @@ -274,6 +299,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGitWithUserHome() throws Exception { final String str = "git://example.com/~some/p ath"; URIish u = new URIish(str); @@ -290,6 +316,7 @@ public class URIishTest extends TestCase { } /* Resolving ~user is beyond standard Java API and need more support + @Test public void testFileWithUserHome() throws Exception { final String str = "~some/p ath"; URIish u = new URIish(str); @@ -306,6 +333,7 @@ public class URIishTest extends TestCase { } */ + @Test public void testFileWithNoneUserHomeWithTilde() throws Exception { final String str = "/~some/p ath"; URIish u = new URIish(str); @@ -321,6 +349,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testGetNullHumanishName() { try { new URIish().getHumanishName(); @@ -330,6 +359,7 @@ public class URIishTest extends TestCase { } } + @Test public void testGetEmptyHumanishName() throws URISyntaxException { try { new URIish(GIT_SCHEME).getHumanishName(); @@ -339,6 +369,7 @@ public class URIishTest extends TestCase { } } + @Test public void testGetAbsEmptyHumanishName() { try { new URIish().getHumanishName(); @@ -348,26 +379,31 @@ public class URIishTest extends TestCase { } } + @Test public void testGetValidWithEmptySlashDotGitHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/a/b/.git").getHumanishName(); assertEquals("b", humanishName); } + @Test public void testGetWithSlashDotGitHumanishName() throws URISyntaxException { assertEquals("", new URIish("/.git").getHumanishName()); } + @Test public void testGetTwoSlashesDotGitHumanishName() throws URISyntaxException { assertEquals("", new URIish("/.git").getHumanishName()); } + @Test public void testGetValidHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish(GIT_SCHEME + "abc").getHumanishName(); assertEquals("abc", humanishName); } + @Test public void testGetValidSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish(GIT_SCHEME + "host/abc/") @@ -375,18 +411,21 @@ public class URIishTest extends TestCase { assertEquals("abc", humanishName); } + @Test public void testGetSlashValidSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/abc/").getHumanishName(); assertEquals("abc", humanishName); } + @Test public void testGetSlashValidSlashDotGitSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/abc/.git").getHumanishName(); assertEquals("abc", humanishName); } + @Test public void testGetSlashSlashDotGitSlashHumanishName() throws IllegalArgumentException, URISyntaxException { final String humanishName = new URIish(GIT_SCHEME + "/abc//.git") @@ -394,12 +433,14 @@ public class URIishTest extends TestCase { assertEquals("may return an empty humanish name", "", humanishName); } + @Test public void testGetSlashesValidSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/a/b/c/").getHumanishName(); assertEquals("c", humanishName); } + @Test public void testGetValidDotGitHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish(GIT_SCHEME + "abc.git") @@ -407,6 +448,7 @@ public class URIishTest extends TestCase { assertEquals("abc", humanishName); } + @Test public void testGetValidDotGitSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish(GIT_SCHEME + "host.xy/abc.git/") @@ -414,30 +456,35 @@ public class URIishTest extends TestCase { assertEquals("abc", humanishName); } + @Test public void testGetValidWithSlashDotGitHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/abc.git").getHumanishName(); assertEquals("abc", humanishName); } + @Test public void testGetValidWithSlashDotGitSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/abc.git/").getHumanishName(); assertEquals("abc", humanishName); } + @Test public void testGetValidWithSlashesDotGitHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/a/b/c.git").getHumanishName(); assertEquals("c", humanishName); } + @Test public void testGetValidWithSlashesDotGitSlashHumanishName() throws IllegalArgumentException, URISyntaxException { String humanishName = new URIish("/a/b/c.git/").getHumanishName(); assertEquals("c", humanishName); } + @Test public void testUserPasswordAndPort() throws URISyntaxException { String str = "http://user:secret@host.xy:80/some/path"; URIish u = new URIish(str); @@ -462,6 +509,7 @@ public class URIishTest extends TestCase { assertEquals(u, new URIish(str)); } + @Test public void testFileProtocol() throws IllegalArgumentException, URISyntaxException, IOException { // as defined by git docu @@ -497,6 +545,7 @@ public class URIishTest extends TestCase { assertEquals("b.txt", u.getHumanishName()); } + @Test public void testMissingPort() throws URISyntaxException { final String incorrectSshUrl = "ssh://some-host:/path/to/repository.git"; URIish u = new URIish(incorrectSshUrl); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/AbstractTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/AbstractTreeIteratorTest.java index 86b5a0f62..934984f7e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/AbstractTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/AbstractTreeIteratorTest.java @@ -44,18 +44,23 @@ package org.eclipse.jgit.treewalk; -import java.io.IOException; +import static org.junit.Assert.assertEquals; +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 junit.framework.TestCase; +import java.io.IOException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectReader; +import org.junit.Test; -public class AbstractTreeIteratorTest extends TestCase { +public class AbstractTreeIteratorTest { private static String prefix(String path) { final int s = path.lastIndexOf('/'); return s > 0 ? path.substring(0, s) : ""; @@ -80,6 +85,7 @@ public class AbstractTreeIteratorTest extends TestCase { } } + @Test public void testPathCompare() throws Exception { assertTrue(new FakeTreeIterator("a", FileMode.REGULAR_FILE).pathCompare( new FakeTreeIterator("a", FileMode.TREE)) < 0); @@ -94,6 +100,7 @@ public class AbstractTreeIteratorTest extends TestCase { new FakeTreeIterator("a", FileMode.TREE)) == 0); } + @Test public void testGrowPath() throws Exception { final FakeTreeIterator i = new FakeTreeIterator("ab", FileMode.TREE); final byte[] origpath = i.path; @@ -108,6 +115,7 @@ public class AbstractTreeIteratorTest extends TestCase { assertEquals(i.path[1], 'b'); } + @Test public void testEnsurePathCapacityFastCase() throws Exception { final FakeTreeIterator i = new FakeTreeIterator("ab", FileMode.TREE); final int want = 50; @@ -123,6 +131,7 @@ public class AbstractTreeIteratorTest extends TestCase { assertEquals(i.path[1], 'b'); } + @Test public void testEnsurePathCapacityGrows() throws Exception { final FakeTreeIterator i = new FakeTreeIterator("ab", FileMode.TREE); final int want = 384; @@ -139,6 +148,7 @@ public class AbstractTreeIteratorTest extends TestCase { assertEquals(i.path[1], 'b'); } + @Test public void testEntryFileMode() { for (FileMode m : new FileMode[] { FileMode.TREE, FileMode.REGULAR_FILE, FileMode.EXECUTABLE_FILE, @@ -149,6 +159,7 @@ public class AbstractTreeIteratorTest extends TestCase { } } + @Test public void testEntryPath() { FakeTreeIterator i = new FakeTreeIterator("a/b/cd", FileMode.TREE); assertEquals("a/b/cd", i.getEntryPathString()); @@ -161,6 +172,7 @@ public class AbstractTreeIteratorTest extends TestCase { assertEquals('d', b[2]); } + @Test public void testCreateEmptyTreeIterator() { FakeTreeIterator i = new FakeTreeIterator("a/b/cd", FileMode.TREE); EmptyTreeIterator e = i.createEmptyTreeIterator(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java index da25f8d63..52da69ef5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java @@ -43,16 +43,21 @@ package org.eclipse.jgit.treewalk; -import java.io.ByteArrayOutputStream; +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 junit.framework.TestCase; +import java.io.ByteArrayOutputStream; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.util.RawParseUtils; +import org.junit.Before; +import org.junit.Test; -public class CanonicalTreeParserTest extends TestCase { +public class CanonicalTreeParserTest { private final CanonicalTreeParser ctp = new CanonicalTreeParser(); private final FileMode m644 = FileMode.REGULAR_FILE; @@ -74,9 +79,8 @@ public class CanonicalTreeParserTest extends TestCase { private byte[] tree3; + @Before public void setUp() throws Exception { - super.setUp(); - tree1 = mktree(entry(m644, "a", hash_a)); tree2 = mktree(entry(m644, "a", hash_a), entry(m644, "foo", hash_foo)); tree3 = mktree(entry(m644, "a", hash_a), entry(mt, "b_sometree", @@ -106,11 +110,13 @@ public class CanonicalTreeParserTest extends TestCase { ctp.pathOffset, ctp.pathLen); } + @Test public void testEmptyTree_AtEOF() throws Exception { ctp.reset(new byte[0]); assertTrue(ctp.eof()); } + @Test public void testOneEntry_Forward() throws Exception { ctp.reset(tree1); @@ -125,6 +131,7 @@ public class CanonicalTreeParserTest extends TestCase { assertTrue(ctp.eof()); } + @Test public void testTwoEntries_ForwardOneAtATime() throws Exception { ctp.reset(tree2); @@ -145,24 +152,28 @@ public class CanonicalTreeParserTest extends TestCase { assertTrue(ctp.eof()); } + @Test public void testOneEntry_Seek1IsEOF() throws Exception { ctp.reset(tree1); ctp.next(1); assertTrue(ctp.eof()); } + @Test public void testTwoEntries_Seek2IsEOF() throws Exception { ctp.reset(tree2); ctp.next(2); assertTrue(ctp.eof()); } + @Test public void testThreeEntries_Seek3IsEOF() throws Exception { ctp.reset(tree3); ctp.next(3); assertTrue(ctp.eof()); } + @Test public void testThreeEntries_Seek2() throws Exception { ctp.reset(tree3); @@ -177,6 +188,7 @@ public class CanonicalTreeParserTest extends TestCase { assertTrue(ctp.eof()); } + @Test public void testOneEntry_Backwards() throws Exception { ctp.reset(tree1); ctp.next(1); @@ -191,6 +203,7 @@ public class CanonicalTreeParserTest extends TestCase { assertEquals(hash_a, ctp.getEntryObjectId()); } + @Test public void testTwoEntries_BackwardsOneAtATime() throws Exception { ctp.reset(tree2); ctp.next(2); @@ -209,6 +222,7 @@ public class CanonicalTreeParserTest extends TestCase { assertEquals(hash_a, ctp.getEntryObjectId()); } + @Test public void testTwoEntries_BackwardsTwo() throws Exception { ctp.reset(tree2); ctp.next(2); @@ -230,6 +244,7 @@ public class CanonicalTreeParserTest extends TestCase { assertTrue(ctp.eof()); } + @Test public void testThreeEntries_BackwardsTwo() throws Exception { ctp.reset(tree3); ctp.next(3); @@ -251,6 +266,7 @@ public class CanonicalTreeParserTest extends TestCase { assertTrue(ctp.eof()); } + @Test public void testBackwards_ConfusingPathName() throws Exception { final String aVeryConfusingName = "confusing 644 entry 755 and others"; ctp.reset(mktree(entry(m644, "a", hash_a), entry(mt, aVeryConfusingName, @@ -271,6 +287,7 @@ public class CanonicalTreeParserTest extends TestCase { assertEquals(hash_a, ctp.getEntryObjectId()); } + @Test public void testBackwords_Prebuilts1() throws Exception { // What is interesting about this test is the ObjectId for the // "darwin-x86" path entry ends in an octal digit (37 == '7'). @@ -305,6 +322,7 @@ public class CanonicalTreeParserTest extends TestCase { assertEquals(windows, ctp.getEntryObjectId()); } + @Test public void testBackwords_Prebuilts2() throws Exception { // What is interesting about this test is the ObjectId for the // "darwin-x86" path entry ends in an octal digit (37 == '7'). @@ -339,6 +357,7 @@ public class CanonicalTreeParserTest extends TestCase { assertEquals(windows, ctp.getEntryObjectId()); } + @Test public void testFreakingHugePathName() throws Exception { final int n = AbstractTreeIterator.DEFAULT_PATH_SIZE * 4; final StringBuilder b = new StringBuilder(n); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/EmptyTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/EmptyTreeIteratorTest.java index 1ea2dc625..03823aaf4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/EmptyTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/EmptyTreeIteratorTest.java @@ -43,17 +43,26 @@ package org.eclipse.jgit.treewalk; +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 org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class EmptyTreeIteratorTest extends RepositoryTestCase { + @Test public void testAtEOF() throws Exception { final EmptyTreeIterator etp = new EmptyTreeIterator(); assertTrue(etp.first()); assertTrue(etp.eof()); } + @Test public void testCreateSubtreeIterator() throws Exception { final EmptyTreeIterator etp = new EmptyTreeIterator(); final ObjectReader reader = db.newObjectReader(); @@ -64,6 +73,7 @@ public class EmptyTreeIteratorTest extends RepositoryTestCase { assertTrue(sub instanceof EmptyTreeIterator); } + @Test public void testEntryObjectId() throws Exception { final EmptyTreeIterator etp = new EmptyTreeIterator(); assertSame(ObjectId.zeroId(), etp.getEntryObjectId()); @@ -72,6 +82,7 @@ public class EmptyTreeIteratorTest extends RepositoryTestCase { assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer())); } + @Test public void testNextDoesNothing() throws Exception { final EmptyTreeIterator etp = new EmptyTreeIterator(); etp.next(1); @@ -85,6 +96,7 @@ public class EmptyTreeIteratorTest extends RepositoryTestCase { assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer())); } + @Test public void testBackDoesNothing() throws Exception { final EmptyTreeIterator etp = new EmptyTreeIterator(); etp.back(1); @@ -98,6 +110,7 @@ public class EmptyTreeIteratorTest extends RepositoryTestCase { assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer())); } + @Test public void testStopWalkCallsParent() throws Exception { final boolean called[] = new boolean[1]; assertFalse(called[0]); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java index 67fae270e..ad8917a92 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.treewalk; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.security.MessageDigest; @@ -56,12 +60,15 @@ import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.RawParseUtils; +import org.junit.Before; +import org.junit.Test; public class FileTreeIteratorTest extends RepositoryTestCase { private final String[] paths = { "a,", "a,b", "a/b", "a0b" }; private long[] mtime; + @Before public void setUp() throws Exception { super.setUp(); @@ -79,6 +86,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase { } } + @Test public void testEmptyIfRootIsFile() throws Exception { final File r = new File(trash, paths[0]); assertTrue(r.isFile()); @@ -88,6 +96,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase { assertTrue(fti.eof()); } + @Test public void testEmptyIfRootDoesNotExist() throws Exception { final File r = new File(trash, "not-existing-file"); assertFalse(r.exists()); @@ -97,6 +106,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase { assertTrue(fti.eof()); } + @Test public void testEmptyIfRootIsEmpty() throws Exception { final File r = new File(trash, "not-existing-file"); assertFalse(r.exists()); @@ -109,6 +119,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase { assertTrue(fti.eof()); } + @Test public void testSimpleIterate() throws Exception { final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY)); @@ -158,6 +169,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase { assertTrue(top.eof()); } + @Test public void testComputeFileObjectId() throws Exception { final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY)); @@ -178,6 +190,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase { assertEquals(expect, top.getEntryObjectId()); } + @Test public void testIsModifiedSymlink() throws Exception { File f = writeTrashFile("symlink", "content"); Git git = new Git(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java index 12ed780b8..707e6c9df 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java @@ -43,6 +43,10 @@ package org.eclipse.jgit.treewalk; +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.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheEntry; @@ -51,6 +55,7 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class NameConflictTreeWalkTest extends RepositoryTestCase { private static final FileMode TREE = FileMode.TREE; @@ -63,6 +68,7 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { private static final FileMode EXECUTABLE_FILE = FileMode.EXECUTABLE_FILE; + @Test public void testNoDF_NoGap() throws Exception { final DirCache tree0 = db.readDirCache(); final DirCache tree1 = db.readDirCache(); @@ -93,6 +99,7 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { assertModes("a0b", SYMLINK, MISSING, tw); } + @Test public void testDF_NoGap() throws Exception { final DirCache tree0 = db.readDirCache(); final DirCache tree1 = db.readDirCache(); @@ -127,6 +134,7 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { assertFalse(tw.isDirectoryFileConflict()); } + @Test public void testDF_GapByOne() throws Exception { final DirCache tree0 = db.readDirCache(); final DirCache tree1 = db.readDirCache(); @@ -162,6 +170,7 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { assertFalse(tw.isDirectoryFileConflict()); } + @Test public void testDF_SkipsSeenSubtree() throws Exception { final DirCache tree0 = db.readDirCache(); final DirCache tree1 = db.readDirCache(); @@ -197,6 +206,7 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { assertFalse(tw.isDirectoryFileConflict()); } + @Test public void testDF_DetectConflict() throws Exception { final DirCache tree0 = db.readDirCache(); final DirCache tree1 = db.readDirCache(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java index 9152c60fe..e80d48533 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java @@ -45,6 +45,9 @@ package org.eclipse.jgit.treewalk; import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE; import static org.eclipse.jgit.lib.FileMode.TREE; +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.DirCacheBuilder; @@ -54,13 +57,16 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; public class PostOrderTreeWalkTest extends RepositoryTestCase { + @Test public void testInitialize_NoPostOrder() throws Exception { final TreeWalk tw = new TreeWalk(db); assertFalse(tw.isPostOrderTraversal()); } + @Test public void testInitialize_TogglePostOrder() throws Exception { final TreeWalk tw = new TreeWalk(db); assertFalse(tw.isPostOrderTraversal()); @@ -70,6 +76,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase { assertFalse(tw.isPostOrderTraversal()); } + @Test public void testResetDoesNotAffectPostOrder() throws Exception { final TreeWalk tw = new TreeWalk(db); tw.setPostOrderTraversal(true); @@ -83,6 +90,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase { assertFalse(tw.isPostOrderTraversal()); } + @Test public void testNoPostOrder() throws Exception { final DirCache tree = db.readDirCache(); { @@ -111,6 +119,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase { assertModes("q", REGULAR_FILE, tw); } + @Test public void testWithPostOrder_EnterSubtree() throws Exception { final DirCache tree = db.readDirCache(); { @@ -145,6 +154,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase { assertModes("q", REGULAR_FILE, tw); } + @Test public void testWithPostOrder_NoEnterSubtree() throws Exception { final DirCache tree = db.readDirCache(); { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java index 7c882719f..78d8c6b77 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkBasicDiffTest.java @@ -46,6 +46,9 @@ package org.eclipse.jgit.treewalk; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_TREE; import static org.eclipse.jgit.lib.Constants.encode; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; @@ -53,8 +56,10 @@ import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.Tree; import org.eclipse.jgit.treewalk.filter.TreeFilter; +import org.junit.Test; public class TreeWalkBasicDiffTest extends RepositoryTestCase { + @Test public void testMissingSubtree_DetectFileAdded_FileModified() throws Exception { final ObjectInserter inserter = db.newObjectInserter(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/IndexDiffFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/IndexDiffFilterTest.java index 43ea78d72..542e169d7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/IndexDiffFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/IndexDiffFilterTest.java @@ -43,9 +43,12 @@ */ package org.eclipse.jgit.treewalk.filter; -import java.io.File; +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 junit.framework.AssertionFailedError; +import java.io.File; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.dircache.DirCacheIterator; @@ -53,6 +56,8 @@ import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Before; +import org.junit.Test; public class IndexDiffFilterTest extends RepositoryTestCase { private static final String FILE = "file"; @@ -83,11 +88,13 @@ public class IndexDiffFilterTest extends RepositoryTestCase { private Git git; + @Before public void setUp() throws Exception { super.setUp(); git = new Git(db); } + @Test public void testRecursiveTreeWalk() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); deleteAll(); @@ -101,6 +108,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testNonRecursiveTreeWalk() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); deleteAll(); @@ -118,24 +126,28 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileCommitted() throws Exception { RevCommit commit = writeFileAndCommit(); TreeWalk treeWalk = createTreeWalk(commit); assertFalse(treeWalk.next()); } + @Test public void testFileInFolderCommitted() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); TreeWalk treeWalk = createTreeWalk(commit); assertFalse(treeWalk.next()); } + @Test public void testEmptyFolderCommitted() throws Exception { RevCommit commit = createEmptyFolderAndCommit(); TreeWalk treeWalk = createTreeWalk(commit); assertFalse(treeWalk.next()); } + @Test public void testFileCommittedChangedNotModified() throws Exception { RevCommit commit = writeFileAndCommit(); writeFile(); @@ -143,6 +155,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileInFolderCommittedChangedNotModified() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolder(); @@ -150,6 +163,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileCommittedModified() throws Exception { RevCommit commit = writeFileAndCommit(); writeFileModified(); @@ -157,6 +171,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE); } + @Test public void testFileInFolderCommittedModified() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolderModified(); @@ -164,6 +179,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileCommittedDeleted() throws Exception { RevCommit commit = writeFileAndCommit(); deleteFile(); @@ -171,6 +187,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE); } + @Test public void testFileInFolderCommittedDeleted() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); deleteFileInFolder(); @@ -178,6 +195,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileInFolderCommittedAllDeleted() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); deleteAll(); @@ -185,6 +203,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testEmptyFolderCommittedDeleted() throws Exception { RevCommit commit = createEmptyFolderAndCommit(); deleteFolder(); @@ -192,6 +211,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileCommittedModifiedCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileAndCommit(); @@ -200,6 +220,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE); } + @Test public void testFileInFolderCommittedModifiedCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); @@ -208,6 +229,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileCommittedDeletedCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileAndCommit(); @@ -216,6 +238,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE); } + @Test public void testFileInFolderCommittedDeletedCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); @@ -224,6 +247,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileInFolderCommittedAllDeletedCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); @@ -232,6 +256,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testEmptyFolderCommittedDeletedCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = createEmptyFolderAndCommit(); @@ -240,6 +265,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileUntracked() throws Exception { RevCommit commit = writeFileAndCommit(); writeFileUntracked(); @@ -247,6 +273,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, UNTRACKED_FILE); } + @Test public void testFileInFolderUntracked() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolderUntracked(); @@ -254,6 +281,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, UNTRACKED_FILE_IN_FOLDER); } + @Test public void testEmptyFolderUntracked() throws Exception { RevCommit commit = createEmptyFolderAndCommit(); createEmptyFolderUntracked(); @@ -261,6 +289,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileIgnored() throws Exception { RevCommit commit = writeFileAndCommit(); writeFileIgnored(); @@ -268,6 +297,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileInFolderIgnored() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolderIgnored(); @@ -275,6 +305,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileInFolderAllIgnored() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolderAllIgnored(); @@ -282,6 +313,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testEmptyFolderIgnored() throws Exception { RevCommit commit = createEmptyFolderAndCommit(); createEmptyFolderIgnored(); @@ -289,6 +321,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileIgnoredNotHonored() throws Exception { RevCommit commit = writeFileAndCommit(); writeFileIgnored(); @@ -296,6 +329,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, IGNORED_FILE, GITIGNORE); } + @Test public void testFileCommittedModifiedIgnored() throws Exception { RevCommit commit = writeFileAndCommit(); writeFileModifiedIgnored(); @@ -303,6 +337,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE); } + @Test public void testFileInFolderCommittedModifiedIgnored() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolderModifiedIgnored(); @@ -310,6 +345,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileInFolderCommittedModifiedAllIgnored() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); writeFileInFolderModifiedAllIgnored(); @@ -317,6 +353,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileCommittedDeletedCommittedIgnoredComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileAndCommit(); @@ -326,6 +363,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE); } + @Test public void testFileInFolderCommittedDeletedCommittedIgnoredComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); @@ -335,6 +373,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testFileInFolderCommittedAllDeletedCommittedAllIgnoredComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); @@ -344,6 +383,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FILE_IN_FOLDER); } + @Test public void testEmptyFolderCommittedDeletedCommittedIgnoredComparedWithInitialCommit() throws Exception { RevCommit commit = createEmptyFolderAndCommit(); @@ -353,12 +393,14 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertFalse(treeWalk.next()); } + @Test public void testFileInFolderCommittedNonRecursive() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); TreeWalk treeWalk = createNonRecursiveTreeWalk(commit); assertPaths(treeWalk, FOLDER); } + @Test public void testFolderChangedToFile() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); deleteAll(); @@ -367,6 +409,7 @@ public class IndexDiffFilterTest extends RepositoryTestCase { assertPaths(treeWalk, FOLDER, FILE_IN_FOLDER); } + @Test public void testFolderChangedToFileCommittedComparedWithInitialCommit() throws Exception { RevCommit commit = writeFileInFolderAndCommit(); @@ -591,7 +634,6 @@ public class IndexDiffFilterTest extends RepositoryTestCase { for (String p : paths) if (p.equals(path)) return; - throw new AssertionFailedError("Expected path '" + path - + "' is not returned"); + fail("Expected path '" + path + "' is not returned"); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java index 7c7ab3e6a..b1b943c2d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java @@ -43,10 +43,19 @@ package org.eclipse.jgit.treewalk.filter; +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 org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Test; public class NotTreeFilterTest extends RepositoryTestCase { + @Test public void testWrap() throws Exception { final TreeWalk tw = new TreeWalk(db); final TreeFilter a = TreeFilter.ALL; @@ -56,18 +65,21 @@ public class NotTreeFilterTest extends RepositoryTestCase { assertFalse(n.include(tw)); } + @Test public void testNegateIsUnwrap() throws Exception { final TreeFilter a = PathFilter.create("a/b"); final TreeFilter n = NotTreeFilter.create(a); assertSame(a, n.negate()); } + @Test public void testShouldBeRecursive_ALL() throws Exception { final TreeFilter a = TreeFilter.ALL; final TreeFilter n = NotTreeFilter.create(a); assertEquals(a.shouldBeRecursive(), n.shouldBeRecursive()); } + @Test public void testShouldBeRecursive_PathFilter() throws Exception { final TreeFilter a = PathFilter.create("a/b"); assertTrue(a.shouldBeRecursive()); @@ -75,6 +87,7 @@ public class NotTreeFilterTest extends RepositoryTestCase { assertTrue(n.shouldBeRecursive()); } + @Test public void testCloneIsDeepClone() throws Exception { final TreeFilter a = new AlwaysCloneTreeFilter(); assertNotSame(a, a.clone()); @@ -82,6 +95,7 @@ public class NotTreeFilterTest extends RepositoryTestCase { assertNotSame(n, n.clone()); } + @Test public void testCloneIsSparseWhenPossible() throws Exception { final TreeFilter a = TreeFilter.ALL; assertSame(a, a.clone()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java similarity index 97% rename from org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java rename to org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java index 302eada99..2ff9179bd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.treewalk.filter; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.LinkedList; @@ -57,9 +58,11 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Test; -public class PathSuffixFilterTestCase extends RepositoryTestCase { +public class PathSuffixFilterTest extends RepositoryTestCase { + @Test public void testNonRecursiveFiltering() throws IOException { final ObjectInserter odi = db.newObjectInserter(); final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes()); @@ -94,6 +97,7 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase { assertEquals(expected, paths); } + @Test public void testRecursiveFiltering() throws IOException { final ObjectInserter odi = db.newObjectInserter(); final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java index 4ac82ecad..03c8e7337 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java @@ -43,41 +43,53 @@ package org.eclipse.jgit.treewalk.filter; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.treewalk.EmptyTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; +import org.junit.Test; public class TreeFilterTest extends RepositoryTestCase { + @Test public void testALL_IncludesAnything() throws Exception { final TreeWalk tw = new TreeWalk(db); tw.addTree(new EmptyTreeIterator()); assertTrue(TreeFilter.ALL.include(tw)); } + @Test public void testALL_ShouldNotBeRecursive() throws Exception { assertFalse(TreeFilter.ALL.shouldBeRecursive()); } + @Test public void testALL_IdentityClone() throws Exception { assertSame(TreeFilter.ALL, TreeFilter.ALL.clone()); } + @Test public void testNotALL_IncludesNothing() throws Exception { final TreeWalk tw = new TreeWalk(db); tw.addTree(new EmptyTreeIterator()); assertFalse(TreeFilter.ALL.negate().include(tw)); } + @Test public void testANY_DIFF_IncludesSingleTreeCase() throws Exception { final TreeWalk tw = new TreeWalk(db); tw.addTree(new EmptyTreeIterator()); assertTrue(TreeFilter.ANY_DIFF.include(tw)); } + @Test public void testANY_DIFF_ShouldNotBeRecursive() throws Exception { assertFalse(TreeFilter.ANY_DIFF.shouldBeRecursive()); } + @Test public void testANY_DIFF_IdentityClone() throws Exception { assertSame(TreeFilter.ANY_DIFF, TreeFilter.ANY_DIFF.clone()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/Base64Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/Base64Test.java index 2acc46110..c37c1e0d8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/Base64Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/Base64Test.java @@ -45,23 +45,30 @@ package org.eclipse.jgit.util; import static org.eclipse.jgit.util.Base64.decode; import static org.eclipse.jgit.util.Base64.encodeBytes; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class Base64Test extends TestCase { +public class Base64Test { + @Test public void testEncode() { assertEquals("aGkK", encodeBytes(b("hi\n"))); assertEquals("AAECDQoJcQ==", encodeBytes(b("\0\1\2\r\n\tq"))); } + @Test public void testDecode() { - assertEquals(b("hi\n"), decode("aGkK")); - assertEquals(b("\0\1\2\r\n\tq"), decode("AAECDQoJcQ==")); - assertEquals(b("\0\1\2\r\n\tq"), decode("A A E\tC D\rQ o\nJ c Q==")); - assertEquals(b("\u000EB"), decode("DkL=")); + JGitTestUtil.assertEquals(b("hi\n"), decode("aGkK")); + JGitTestUtil.assertEquals(b("\0\1\2\r\n\tq"), decode("AAECDQoJcQ==")); + JGitTestUtil.assertEquals(b("\0\1\2\r\n\tq"), + decode("A A E\tC D\rQ o\nJ c Q==")); + JGitTestUtil.assertEquals(b("\u000EB"), decode("DkL=")); } + @Test public void testDecodeFail_NonBase64Character() { try { decode("! a bad base64 string !"); @@ -71,6 +78,7 @@ public class Base64Test extends TestCase { } } + @Test public void testEncodeMatchesDecode() { String[] testStrings = { "", // "cow", // @@ -79,18 +87,11 @@ public class Base64Test extends TestCase { "\0\1\2\r\n\t" // }; for (String e : testStrings) - assertEquals(b(e), decode(encodeBytes(b(e)))); - } - - private static void assertEquals(byte[] exp, byte[] act) { - assertEquals(s(exp), s(act)); + JGitTestUtil.assertEquals(b(e), decode(encodeBytes(b(e)))); } private static byte[] b(String str) { return Constants.encode(str); } - private static String s(byte[] raw) { - return RawParseUtils.decode(raw); - } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java index c4adde372..4cdc02ac5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java @@ -43,19 +43,20 @@ */ package org.eclipse.jgit.util; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.util.concurrent.TimeUnit; -import junit.framework.TestCase; - import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; +import org.junit.Test; /** * Portions of this test is from CommitMsgHookTest in the Android project Gerrit */ -public class ChangeIdUtilTest extends TestCase { +public class ChangeIdUtilTest { private final String SOB1 = "Signed-off-by: J Author \n"; @@ -100,6 +101,7 @@ public class ChangeIdUtilTest extends TestCase { committer = new PersonIdent(committer, when, tz); } + @Test public void testClean() { assertEquals("hej", ChangeIdUtil.clean("hej\n\n")); assertEquals("hej\n\nsan", ChangeIdUtil.clean("hej\n\nsan\n\n")); @@ -110,6 +112,7 @@ public class ChangeIdUtilTest extends TestCase { .clean("#no\nhej\nsan\nSigned-off-by: me \n#men")); } + @Test public void testId() throws IOException { String msg = "A\nMessage\n"; ObjectId id = ChangeIdUtil.computeChangeId(treeId, parentId, p, q, msg); @@ -117,12 +120,14 @@ public class ChangeIdUtilTest extends TestCase { .toString(id)); } + @Test public void testHasChangeid() throws Exception { assertEquals( "has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n", call("has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n")); } + @Test public void testHasChangeidWithReplacement() throws Exception { assertEquals( "has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I988d2d7a6f2c0578fccabd4ebd3cec0768bc7f9f\nAnd then some\n", @@ -130,48 +135,56 @@ public class ChangeIdUtilTest extends TestCase { true)); } + @Test public void testOneliner() throws Exception { assertEquals( "oneliner\n\nChange-Id: I3a98091ce4470de88d52ae317fcd297e2339f063\n", call("oneliner\n")); } + @Test public void testOnelinerFollowedByBlank() throws Exception { assertEquals( "oneliner followed by blank\n\nChange-Id: I3a12c21ef342a18498f95c62efbc186cd782b743\n", call("oneliner followed by blank\n")); } + @Test public void testATwoLines() throws Exception { assertEquals( "a two lines\nwith text withour break after subject line\n\nChange-Id: I549a0fed3d69b7876c54b4f5a35637135fd43fac\n", call("a two lines\nwith text withour break after subject line\n")); } + @Test public void testRegularCommit() throws Exception { assertEquals( "regular commit\n\nwith header and body\n\nChange-Id: I62d8749d3c3a888c11e3fadc3924220a19389766\n", call("regular commit\n\nwith header and body\n")); } + @Test public void testRegularCommitWithSob_ButNoBody() throws Exception { assertEquals( "regular commit with sob, but no body\n\nChange-Id: I0f0b4307e9944ecbd5a9f6b9489e25cfaede43c4\nSigned-off-by: me@you.too\n", call("regular commit with sob, but no body\n\nSigned-off-by: me@you.too\n")); } + @Test public void testACommitWithBug_SubButNoBody() throws Exception { assertEquals( "a commit with bug, sub but no body\n\nBug: 33\nChange-Id: I337e264868613dab6d1e11a34f394db369487412\nSigned-off-by: me@you.too\n", call("a commit with bug, sub but no body\n\nBug: 33\nSigned-off-by: me@you.too\n")); } + @Test public void testACommitWithSubject_NoBodySobAndBug() throws Exception { assertEquals( "a commit with subject, no body sob and bug\n\nChange-Id: Ib3616d4bf77707a3215a6cb0602c004ee119a445\nSigned-off-by: me@you.too\nBug: 33\n", call("a commit with subject, no body sob and bug\n\nSigned-off-by: me@you.too\nBug: 33\n")); } + @Test public void testACommitWithSubjectBug_NonFooterLineAndSob() throws Exception { assertEquals( @@ -179,18 +192,21 @@ public class ChangeIdUtilTest extends TestCase { call("a commit with subject bug, non-footer line and sob\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\n")); } + @Test public void testACommitWithSubject_NonFooterAndBugAndSob() throws Exception { assertEquals( "a commit with subject, non-footer and bug and sob\n\nmore text (two empty lines after bug)\nBug: 33\n\n\nChange-Id: Idac75ccbad2ab6727b8612e344df5190d87891dd\nSigned-off-by: me@you.too\n", call("a commit with subject, non-footer and bug and sob\n\nmore text (two empty lines after bug)\nBug: 33\n\n\nSigned-off-by: me@you.too\n")); } + @Test public void testACommitWithSubjectBodyBugBrackersAndSob() throws Exception { assertEquals( "a commit with subject body, bug. brackers and sob\n\nText\n\nBug: 33\nChange-Id: I90ecb589bef766302532c3e00915e10114b00f62\n[bracket]\nSigned-off-by: me@you.too\n", call("a commit with subject body, bug. brackers and sob\n\nText\n\nBug: 33\n[bracket]\nSigned-off-by: me@you.too\n\n")); } + @Test public void testACommitWithSubjectBodyBugLineWithASpaceAndSob() throws Exception { assertEquals( @@ -198,12 +214,14 @@ public class ChangeIdUtilTest extends TestCase { call("a commit with subject body, bug. line with a space and sob\n\nText\n\nBug: 33\n \nSigned-off-by: me@you.too\n\n")); } + @Test public void testACommitWithSubjectBodyBugEmptyLineAndSob() throws Exception { assertEquals( "a commit with subject body, bug. empty line and sob\n\nText\n\nBug: 33\nChange-Id: I33f119f533313883e6ada3df600c4f0d4db23a76\n \nSigned-off-by: me@you.too\n", call("a commit with subject body, bug. empty line and sob\n\nText\n\nBug: 33\n \nSigned-off-by: me@you.too\n\n")); } + @Test public void testEmptyMessages() throws Exception { // Empty input must not produce a change id. hookDoesNotModify(""); @@ -222,6 +240,7 @@ public class ChangeIdUtilTest extends TestCase { + "new file mode 100644\nindex 0000000..c78b7f0\n"); } + @Test public void testChangeIdAlreadySet() throws Exception { // If a Change-Id is already present in the footer, the hook must // not modify the message but instead must leave the identity alone. @@ -243,6 +262,7 @@ public class ChangeIdUtilTest extends TestCase { "Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n"); } + @Test public void testChangeIdAlreadySetWithReplacement() throws Exception { // If a Change-Id is already present in the footer, the hook // replaces the Change-Id with the new value.. @@ -284,6 +304,7 @@ public class ChangeIdUtilTest extends TestCase { true)); } + @Test public void testTimeAltersId() throws Exception { assertEquals("a\n" + // "\n" + // @@ -313,6 +334,7 @@ public class ChangeIdUtilTest extends TestCase { committer = new PersonIdent(committer, now, tz); } + @Test public void testFirstParentAltersId() throws Exception { assertEquals("a\n" + // "\n" + // @@ -326,6 +348,7 @@ public class ChangeIdUtilTest extends TestCase { call("a\n")); } + @Test public void testDirCacheAltersId() throws Exception { assertEquals("a\n" + // "\n" + // @@ -339,6 +362,7 @@ public class ChangeIdUtilTest extends TestCase { call("a\n")); } + @Test public void testSingleLineMessages() throws Exception { assertEquals("a\n" + // "\n" + // @@ -364,6 +388,7 @@ public class ChangeIdUtilTest extends TestCase { call("Fix-A-Widget: this thing\n")); } + @Test public void testMultiLineMessagesWithoutFooter() throws Exception { assertEquals("a\n" + // "\n" + // @@ -389,6 +414,7 @@ public class ChangeIdUtilTest extends TestCase { call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n")); } + @Test public void testSingleLineMessagesWithSignedOffBy() throws Exception { assertEquals("a\n" + // "\n" + // @@ -404,6 +430,7 @@ public class ChangeIdUtilTest extends TestCase { call("a\n" + "\n" + SOB1 + SOB2)); } + @Test public void testMultiLineMessagesWithSignedOffBy() throws Exception { assertEquals("a\n" + // "\n" + // @@ -453,6 +480,7 @@ public class ChangeIdUtilTest extends TestCase { SOB2)); } + @Test public void testNoteInMiddle() throws Exception { assertEquals("a\n" + // "\n" + // @@ -466,6 +494,7 @@ public class ChangeIdUtilTest extends TestCase { "does not fix it.\n")); } + @Test public void testKernelStyleFooter() throws Exception { assertEquals("a\n" + // "\n" + // @@ -482,6 +511,7 @@ public class ChangeIdUtilTest extends TestCase { SOB2)); } + @Test public void testChangeIdAfterBugOrIssue() throws Exception { assertEquals("a\n" + // "\n" + // @@ -521,6 +551,7 @@ public class ChangeIdUtilTest extends TestCase { "index 0000000..c78b7f0\n")); } + @Test public void testWithEndingURL() throws Exception { assertEquals("a\n" + // "\n" + // diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java index cc53a5a74..4ad423486 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java @@ -43,25 +43,32 @@ package org.eclipse.jgit.util; +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.IOException; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class FileUtilTest extends TestCase { +public class FileUtilTest { private final File trash = new File(new File("target"), "trash"); - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { assertTrue(trash.mkdirs()); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { FileUtils.delete(trash, FileUtils.RECURSIVE | FileUtils.RETRY); } + @Test public void testDeleteFile() throws IOException { File f = new File(trash, "test"); assertTrue(f.createNewFile()); @@ -82,6 +89,7 @@ public class FileUtilTest extends TestCase { } } + @Test public void testDeleteRecursive() throws IOException { File f1 = new File(trash, "test/test/a"); f1.mkdirs(); @@ -106,6 +114,7 @@ public class FileUtilTest extends TestCase { } } + @Test public void testMkdir() throws IOException { File d = new File(trash, "test"); FileUtils.mkdir(d); @@ -134,6 +143,7 @@ public class FileUtilTest extends TestCase { assertTrue(f.delete()); } + @Test public void testMkdirs() throws IOException { File root = new File(trash, "test"); assertTrue(root.mkdir()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java index b8d5bd102..c6eca9d5e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java @@ -43,9 +43,14 @@ package org.eclipse.jgit.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -public class IntListTest extends TestCase { +import org.junit.Test; + +public class IntListTest { + @Test public void testEmpty_DefaultCapacity() { final IntList i = new IntList(); assertEquals(0, i.size()); @@ -57,6 +62,7 @@ public class IntListTest extends TestCase { } } + @Test public void testEmpty_SpecificCapacity() { final IntList i = new IntList(5); assertEquals(0, i.size()); @@ -68,6 +74,7 @@ public class IntListTest extends TestCase { } } + @Test public void testAdd_SmallGroup() { final IntList i = new IntList(); final int n = 5; @@ -85,6 +92,7 @@ public class IntListTest extends TestCase { } } + @Test public void testAdd_ZeroCapacity() { final IntList i = new IntList(0); assertEquals(0, i.size()); @@ -92,6 +100,7 @@ public class IntListTest extends TestCase { assertEquals(1, i.get(0)); } + @Test public void testAdd_LargeGroup() { final IntList i = new IntList(); final int n = 500; @@ -109,12 +118,14 @@ public class IntListTest extends TestCase { } } + @Test public void testFillTo0() { final IntList i = new IntList(); i.fillTo(0, Integer.MIN_VALUE); assertEquals(0, i.size()); } + @Test public void testFillTo1() { final IntList i = new IntList(); i.fillTo(1, Integer.MIN_VALUE); @@ -124,6 +135,7 @@ public class IntListTest extends TestCase { assertEquals(0, i.get(1)); } + @Test public void testFillTo100() { final IntList i = new IntList(); i.fillTo(100, Integer.MIN_VALUE); @@ -133,6 +145,7 @@ public class IntListTest extends TestCase { assertEquals(3, i.get(100)); } + @Test public void testClear() { final IntList i = new IntList(); final int n = 5; @@ -150,6 +163,7 @@ public class IntListTest extends TestCase { } } + @Test public void testSet() { final IntList i = new IntList(); i.add(1); @@ -171,6 +185,7 @@ public class IntListTest extends TestCase { assertEquals(2, i.get(1)); } + @Test public void testToString() { final IntList i = new IntList(); i.add(1); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java index 21fea9e9d..06cb11b37 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java @@ -43,9 +43,13 @@ package org.eclipse.jgit.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -public class NBTest extends TestCase { +import org.junit.Test; + +public class NBTest { + @Test public void testCompareUInt32() { assertTrue(NB.compareUInt32(0, 0) == 0); assertTrue(NB.compareUInt32(1, 0) > 0); @@ -56,6 +60,7 @@ public class NBTest extends TestCase { assertTrue(NB.compareUInt32(1, -1) < 0); } + @Test public void testDecodeUInt16() { assertEquals(0, NB.decodeUInt16(b(0, 0), 0)); assertEquals(0, NB.decodeUInt16(padb(3, 0, 0), 3)); @@ -73,6 +78,7 @@ public class NBTest extends TestCase { assertEquals(0xffff, NB.decodeUInt16(padb(3, 0xff, 0xff), 3)); } + @Test public void testDecodeInt32() { assertEquals(0, NB.decodeInt32(b(0, 0, 0, 0), 0)); assertEquals(0, NB.decodeInt32(padb(3, 0, 0, 0, 0), 3)); @@ -93,6 +99,7 @@ public class NBTest extends TestCase { padb(3, 0xff, 0xff, 0xff, 0xff), 3)); } + @Test public void testDecodeUInt32() { assertEquals(0L, NB.decodeUInt32(b(0, 0, 0, 0), 0)); assertEquals(0L, NB.decodeUInt32(padb(3, 0, 0, 0, 0), 3)); @@ -113,6 +120,7 @@ public class NBTest extends TestCase { 0xff), 3)); } + @Test public void testDecodeUInt64() { assertEquals(0L, NB.decodeUInt64(b(0, 0, 0, 0, 0, 0, 0, 0), 0)); assertEquals(0L, NB.decodeUInt64(padb(3, 0, 0, 0, 0, 0, 0, 0, 0), 3)); @@ -145,6 +153,7 @@ public class NBTest extends TestCase { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), 3)); } + @Test public void testEncodeInt16() { final byte[] out = new byte[16]; @@ -177,6 +186,7 @@ public class NBTest extends TestCase { assertOutput(b(0xff, 0xff), out, 3); } + @Test public void testEncodeInt32() { final byte[] out = new byte[16]; @@ -217,6 +227,7 @@ public class NBTest extends TestCase { assertOutput(b(0xff, 0xff, 0xff, 0xff), out, 3); } + @Test public void testEncodeInt64() { final byte[] out = new byte[16]; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java index b9a721a46..65078763e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneStyleTest.java @@ -44,11 +44,14 @@ package org.eclipse.jgit.util; import static org.eclipse.jgit.util.QuotedString.BOURNE; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class QuotedStringBourneStyleTest extends TestCase { +public class QuotedStringBourneStyleTest { private static void assertQuote(final String in, final String exp) { final String r = BOURNE.quote(in); assertNotSame(in, r); @@ -62,32 +65,39 @@ public class QuotedStringBourneStyleTest extends TestCase { assertEquals(exp, r); } + @Test public void testQuote_Empty() { assertEquals("''", BOURNE.quote("")); } + @Test public void testDequote_Empty1() { assertEquals("", BOURNE.dequote(new byte[0], 0, 0)); } + @Test public void testDequote_Empty2() { assertEquals("", BOURNE.dequote(new byte[] { '\'', '\'' }, 0, 2)); } + @Test public void testDequote_SoleSq() { assertEquals("", BOURNE.dequote(new byte[] { '\'' }, 0, 1)); } + @Test public void testQuote_BareA() { assertQuote("a", "a"); } + @Test public void testDequote_BareA() { final String in = "a"; final byte[] b = Constants.encode(in); assertEquals(in, BOURNE.dequote(b, 0, b.length)); } + @Test public void testDequote_BareABCZ_OnlyBC() { final String in = "abcz"; final byte[] b = Constants.encode(in); @@ -95,10 +105,12 @@ public class QuotedStringBourneStyleTest extends TestCase { assertEquals("bc", BOURNE.dequote(b, p, p + 2)); } + @Test public void testDequote_LoneBackslash() { assertDequote("\\", "\\"); } + @Test public void testQuote_NamedEscapes() { assertQuote("'", "'\\''"); assertQuote("!", "'\\!'"); @@ -107,6 +119,7 @@ public class QuotedStringBourneStyleTest extends TestCase { assertQuote("a!b", "a'\\!'b"); } + @Test public void testDequote_NamedEscapes() { assertDequote("'", "'\\''"); assertDequote("!", "'\\!'"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java index 69201249c..7463528b5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringBourneUserPathStyleTest.java @@ -44,11 +44,14 @@ package org.eclipse.jgit.util; import static org.eclipse.jgit.util.QuotedString.BOURNE_USER_PATH; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class QuotedStringBourneUserPathStyleTest extends TestCase { +public class QuotedStringBourneUserPathStyleTest { private static void assertQuote(final String in, final String exp) { final String r = BOURNE_USER_PATH.quote(in); assertNotSame(in, r); @@ -62,33 +65,40 @@ public class QuotedStringBourneUserPathStyleTest extends TestCase { assertEquals(exp, r); } + @Test public void testQuote_Empty() { assertEquals("''", BOURNE_USER_PATH.quote("")); } + @Test public void testDequote_Empty1() { assertEquals("", BOURNE_USER_PATH.dequote(new byte[0], 0, 0)); } + @Test public void testDequote_Empty2() { assertEquals("", BOURNE_USER_PATH.dequote(new byte[] { '\'', '\'' }, 0, 2)); } + @Test public void testDequote_SoleSq() { assertEquals("", BOURNE_USER_PATH.dequote(new byte[] { '\'' }, 0, 1)); } + @Test public void testQuote_BareA() { assertQuote("a", "a"); } + @Test public void testDequote_BareA() { final String in = "a"; final byte[] b = Constants.encode(in); assertEquals(in, BOURNE_USER_PATH.dequote(b, 0, b.length)); } + @Test public void testDequote_BareABCZ_OnlyBC() { final String in = "abcz"; final byte[] b = Constants.encode(in); @@ -96,10 +106,12 @@ public class QuotedStringBourneUserPathStyleTest extends TestCase { assertEquals("bc", BOURNE_USER_PATH.dequote(b, p, p + 2)); } + @Test public void testDequote_LoneBackslash() { assertDequote("\\", "\\"); } + @Test public void testQuote_NamedEscapes() { assertQuote("'", "'\\''"); assertQuote("!", "'\\!'"); @@ -108,6 +120,7 @@ public class QuotedStringBourneUserPathStyleTest extends TestCase { assertQuote("a!b", "a'\\!'b"); } + @Test public void testDequote_NamedEscapes() { assertDequote("'", "'\\''"); assertDequote("!", "'\\!'"); @@ -116,6 +129,7 @@ public class QuotedStringBourneUserPathStyleTest extends TestCase { assertDequote("a!b", "a'\\!'b"); } + @Test public void testQuote_User() { assertEquals("~foo/", BOURNE_USER_PATH.quote("~foo")); assertEquals("~foo/", BOURNE_USER_PATH.quote("~foo/")); @@ -125,6 +139,7 @@ public class QuotedStringBourneUserPathStyleTest extends TestCase { assertEquals("~/'a'", BOURNE_USER_PATH.quote("~/a")); } + @Test public void testDequote_User() { assertEquals("~foo", BOURNE_USER_PATH.dequote("~foo")); assertEquals("~foo/", BOURNE_USER_PATH.dequote("~foo/")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java index 1af45c227..670fbaf27 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java @@ -44,14 +44,17 @@ package org.eclipse.jgit.util; import static org.eclipse.jgit.util.QuotedString.GIT_PATH; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; import java.io.UnsupportedEncodingException; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class QuotedStringGitPathStyleTest extends TestCase { +public class QuotedStringGitPathStyleTest { private static void assertQuote(final String exp, final String in) { final String r = GIT_PATH.quote(in); assertNotSame(in, r); @@ -70,33 +73,40 @@ public class QuotedStringGitPathStyleTest extends TestCase { assertEquals(exp, r); } + @Test public void testQuote_Empty() { assertEquals("\"\"", GIT_PATH.quote("")); } + @Test public void testDequote_Empty1() { assertEquals("", GIT_PATH.dequote(new byte[0], 0, 0)); } + @Test public void testDequote_Empty2() { assertEquals("", GIT_PATH.dequote(new byte[] { '"', '"' }, 0, 2)); } + @Test public void testDequote_SoleDq() { assertEquals("\"", GIT_PATH.dequote(new byte[] { '"' }, 0, 1)); } + @Test public void testQuote_BareA() { final String in = "a"; assertSame(in, GIT_PATH.quote(in)); } + @Test public void testDequote_BareA() { final String in = "a"; final byte[] b = Constants.encode(in); assertEquals(in, GIT_PATH.dequote(b, 0, b.length)); } + @Test public void testDequote_BareABCZ_OnlyBC() { final String in = "abcz"; final byte[] b = Constants.encode(in); @@ -104,10 +114,12 @@ public class QuotedStringGitPathStyleTest extends TestCase { assertEquals("bc", GIT_PATH.dequote(b, p, p + 2)); } + @Test public void testDequote_LoneBackslash() { assertDequote("\\", "\\"); } + @Test public void testQuote_NamedEscapes() { assertQuote("\\a", "\u0007"); assertQuote("\\b", "\b"); @@ -120,6 +132,7 @@ public class QuotedStringGitPathStyleTest extends TestCase { assertQuote("\\\"", "\""); } + @Test public void testDequote_NamedEscapes() { assertDequote("\u0007", "\\a"); assertDequote("\b", "\\b"); @@ -132,6 +145,7 @@ public class QuotedStringGitPathStyleTest extends TestCase { assertDequote("\"", "\\\""); } + @Test public void testDequote_OctalAll() { for (int i = 0; i < 127; i++) { assertDequote("" + (char) i, octalEscape(i)); @@ -151,40 +165,49 @@ public class QuotedStringGitPathStyleTest extends TestCase { return "\\"+s; } + @Test public void testQuote_OctalAll() { assertQuote("\\001", "\1"); assertQuote("\\177", "\u007f"); assertQuote("\\303\\277", "\u00ff"); // \u00ff in UTF-8 } + @Test public void testDequote_UnknownEscapeQ() { assertDequote("\\q", "\\q"); } + @Test public void testDequote_FooTabBar() { assertDequote("foo\tbar", "foo\\tbar"); } + @Test public void testDequote_Latin1() { assertDequote("\u00c5ngstr\u00f6m", "\\305ngstr\\366m"); // Latin1 } + @Test public void testDequote_UTF8() { assertDequote("\u00c5ngstr\u00f6m", "\\303\\205ngstr\\303\\266m"); } + @Test public void testDequote_RawUTF8() { assertDequote("\u00c5ngstr\u00f6m", "\303\205ngstr\303\266m"); } + @Test public void testDequote_RawLatin1() { assertDequote("\u00c5ngstr\u00f6m", "\305ngstr\366m"); } + @Test public void testQuote_Ang() { assertQuote("\\303\\205ngstr\\303\\266m", "\u00c5ngstr\u00f6m"); } + @Test public void testQuoteAtAndNumber() { assertSame("abc@2x.png", GIT_PATH.quote("abc@2x.png")); assertDequote("abc@2x.png", "abc\\1002x.png"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java index 6747b26ad..a8c576334 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java @@ -43,18 +43,23 @@ package org.eclipse.jgit.util; -import java.io.UnsupportedEncodingException; - -import junit.framework.TestCase; import static org.eclipse.jgit.util.RawCharUtil.isWhitespace; -import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace; import static org.eclipse.jgit.util.RawCharUtil.trimLeadingWhitespace; +import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; + +import org.junit.Test; -public class RawCharUtilTest extends TestCase { +public class RawCharUtilTest { /** * Test method for {@link RawCharUtil#isWhitespace(byte)}. */ + @Test public void testIsWhitespace() { for (byte c = -128; c < 127; c++) { switch (c) { @@ -76,6 +81,7 @@ public class RawCharUtilTest extends TestCase { * * @throws UnsupportedEncodingException */ + @Test public void testTrimTrailingWhitespace() throws UnsupportedEncodingException { assertEquals(0, trimTrailingWhitespace("".getBytes("US-ASCII"), 0, 0)); @@ -95,6 +101,7 @@ public class RawCharUtilTest extends TestCase { * * @throws UnsupportedEncodingException */ + @Test public void testTrimLeadingWhitespace() throws UnsupportedEncodingException { assertEquals(0, trimLeadingWhitespace("".getBytes("US-ASCII"), 0, 0)); assertEquals(1, trimLeadingWhitespace(" ".getBytes("US-ASCII"), 0, 1)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_FormatTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_FormatTest.java index 289c26ede..a28a2d4c9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_FormatTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_FormatTest.java @@ -43,11 +43,14 @@ package org.eclipse.jgit.util; +import static org.junit.Assert.assertEquals; + import java.io.UnsupportedEncodingException; -import junit.framework.TestCase; +import org.junit.Test; -public class RawParseUtils_FormatTest extends TestCase { +public class RawParseUtils_FormatTest { + @Test public void testFormatBase10() throws UnsupportedEncodingException { byte[] b = new byte[64]; int p; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java index a2c9e9dbd..f5b56e7b7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_HexParseTest.java @@ -43,11 +43,14 @@ package org.eclipse.jgit.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class RawParseUtils_HexParseTest extends TestCase { +public class RawParseUtils_HexParseTest { + @Test public void testInt4_1() { assertEquals(0, RawParseUtils.parseHexInt4((byte) '0')); assertEquals(1, RawParseUtils.parseHexInt4((byte) '1')); @@ -87,6 +90,7 @@ public class RawParseUtils_HexParseTest extends TestCase { } } + @Test public void testInt16() { assertEquals(0x0000, parse16("0000")); assertEquals(0x0001, parse16("0001")); @@ -122,6 +126,7 @@ public class RawParseUtils_HexParseTest extends TestCase { return RawParseUtils.parseHexInt16(Constants.encodeASCII(str), 0); } + @Test public void testInt32() { assertEquals(0x00000000, parse32("00000000")); assertEquals(0x00000001, parse32("00000001")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java index 6dcd56ee0..593971478 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java @@ -43,11 +43,15 @@ package org.eclipse.jgit.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.UnsupportedEncodingException; -import junit.framework.TestCase; +import org.junit.Test; -public class RawParseUtils_LineMapTest extends TestCase { +public class RawParseUtils_LineMapTest { + @Test public void testEmpty() { final IntList map = RawParseUtils.lineMap(new byte[] {}, 0, 0); assertNotNull(map); @@ -56,6 +60,7 @@ public class RawParseUtils_LineMapTest extends TestCase { assertEquals(0, map.get(1)); } + @Test public void testOneBlankLine() { final IntList map = RawParseUtils.lineMap(new byte[] { '\n' }, 0, 1); assertEquals(3, map.size()); @@ -64,6 +69,7 @@ public class RawParseUtils_LineMapTest extends TestCase { assertEquals(1, map.get(2)); } + @Test public void testTwoLineFooBar() throws UnsupportedEncodingException { final byte[] buf = "foo\nbar\n".getBytes("ISO-8859-1"); final IntList map = RawParseUtils.lineMap(buf, 0, buf.length); @@ -74,6 +80,7 @@ public class RawParseUtils_LineMapTest extends TestCase { assertEquals(buf.length, map.get(3)); } + @Test public void testTwoLineNoLF() throws UnsupportedEncodingException { final byte[] buf = "foo\nbar".getBytes("ISO-8859-1"); final IntList map = RawParseUtils.lineMap(buf, 0, buf.length); @@ -84,6 +91,7 @@ public class RawParseUtils_LineMapTest extends TestCase { assertEquals(buf.length, map.get(3)); } + @Test public void testFourLineBlanks() throws UnsupportedEncodingException { final byte[] buf = "foo\n\n\nbar\n".getBytes("ISO-8859-1"); final IntList map = RawParseUtils.lineMap(buf, 0, buf.length); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_MatchTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_MatchTest.java index 29459326d..5c5f66ec2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_MatchTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_MatchTest.java @@ -43,23 +43,27 @@ package org.eclipse.jgit.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertTrue; import org.eclipse.jgit.lib.Constants; +import org.junit.Test; -public class RawParseUtils_MatchTest extends TestCase { +public class RawParseUtils_MatchTest { + @Test public void testMatch_Equal() { final byte[] src = Constants.encodeASCII(" differ\n"); final byte[] dst = Constants.encodeASCII("foo differ\n"); assertTrue(RawParseUtils.match(dst, 3, src) == 3 + src.length); } + @Test public void testMatch_NotEqual() { final byte[] src = Constants.encodeASCII(" differ\n"); final byte[] dst = Constants.encodeASCII("a differ\n"); assertTrue(RawParseUtils.match(dst, 2, src) < 0); } + @Test public void testMatch_Prefix() { final byte[] src = Constants.encodeASCII("author "); final byte[] dst = Constants.encodeASCII("author A. U. Thor"); @@ -67,6 +71,7 @@ public class RawParseUtils_MatchTest extends TestCase { assertTrue(RawParseUtils.match(dst, 1, src) < 0); } + @Test public void testMatch_TooSmall() { final byte[] src = Constants.encodeASCII("author "); final byte[] dst = Constants.encodeASCII("author autho"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java index e76cd48b3..df5eb4bd4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java @@ -43,15 +43,17 @@ package org.eclipse.jgit.util; +import static org.junit.Assert.assertEquals; + import java.util.Date; import java.util.TimeZone; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.PersonIdent; +import org.junit.Test; -public class RawParseUtils_ParsePersonIdentTest extends TestCase { +public class RawParseUtils_ParsePersonIdentTest { + @Test public void testParsePersonIdent_legalCases() { final Date when = new Date(1234567890000l); final TimeZone tz = TimeZone.getTimeZone("GMT-7"); @@ -79,6 +81,7 @@ public class RawParseUtils_ParsePersonIdentTest extends TestCase { new PersonIdent("A U Thor", "author@example.com", when, tz)); } + @Test public void testParsePersonIdent_fuzzyCases() { final Date when = new Date(1234567890000l); final TimeZone tz = TimeZone.getTimeZone("GMT-7"); @@ -92,6 +95,7 @@ public class RawParseUtils_ParsePersonIdentTest extends TestCase { new PersonIdent("A U Thor", "author@example.com", when, tz)); } + @Test public void testParsePersonIdent_incompleteCases() { final Date when = new Date(1234567890000l); final TimeZone tz = TimeZone.getTimeZone("GMT-7"); @@ -127,6 +131,7 @@ public class RawParseUtils_ParsePersonIdentTest extends TestCase { "Me", "me@example.com", 0, 0)); } + @Test public void testParsePersonIdent_malformedCases() { assertPersonIdent("Me me@example.com> 1234567890 -0700", null); assertPersonIdent("Me list = RefList.emptyList(); assertEquals(0, list.size()); @@ -79,6 +87,7 @@ public class RefListTest extends TestCase { } } + @Test public void testEmptyBuilder() { RefList list = new RefList.Builder().toRefList(); assertEquals(0, list.size()); @@ -100,6 +109,7 @@ public class RefListTest extends TestCase { } } + @Test public void testBuilder_AddThenSort() { RefList.Builder builder = new RefList.Builder(1); builder.add(REF_B); @@ -117,6 +127,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, list.get(1)); } + @Test public void testBuilder_AddAll() { RefList.Builder builder = new RefList.Builder(1); Ref[] src = { REF_A, REF_B, REF_c, REF_A }; @@ -128,6 +139,7 @@ public class RefListTest extends TestCase { assertSame(REF_c, list.get(1)); } + @Test public void testBuilder_Set() { RefList.Builder builder = new RefList.Builder(); builder.add(REF_A); @@ -149,6 +161,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, list.get(1)); } + @Test public void testBuilder_Remove() { RefList.Builder builder = new RefList.Builder(); builder.add(REF_A); @@ -159,6 +172,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, builder.get(0)); } + @Test public void testSet() { RefList one = toList(REF_A, REF_A); RefList two = one.set(1, REF_B); @@ -175,6 +189,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, two.get(1)); } + @Test public void testAddToEmptyList() { RefList one = toList(); RefList two = one.add(0, REF_B); @@ -187,6 +202,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, two.get(0)); } + @Test public void testAddToFrontOfList() { RefList one = toList(REF_A); RefList two = one.add(0, REF_B); @@ -200,6 +216,7 @@ public class RefListTest extends TestCase { assertSame(REF_A, two.get(1)); } + @Test public void testAddToEndOfList() { RefList one = toList(REF_A); RefList two = one.add(1, REF_B); @@ -213,6 +230,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, two.get(1)); } + @Test public void testAddToMiddleOfListByInsertionPosition() { RefList one = toList(REF_A, REF_c); @@ -232,6 +250,7 @@ public class RefListTest extends TestCase { assertSame(REF_c, two.get(2)); } + @Test public void testPutNewEntry() { RefList one = toList(REF_A, REF_c); RefList two = one.put(REF_B); @@ -248,6 +267,7 @@ public class RefListTest extends TestCase { assertSame(REF_c, two.get(2)); } + @Test public void testPutReplaceEntry() { Ref otherc = newRef(REF_c.getName()); assertNotSame(REF_c, otherc); @@ -266,6 +286,7 @@ public class RefListTest extends TestCase { assertSame(otherc, two.get(1)); } + @Test public void testRemoveFrontOfList() { RefList one = toList(REF_A, REF_B, REF_c); RefList two = one.remove(0); @@ -281,6 +302,7 @@ public class RefListTest extends TestCase { assertSame(REF_c, two.get(1)); } + @Test public void testRemoveMiddleOfList() { RefList one = toList(REF_A, REF_B, REF_c); RefList two = one.remove(1); @@ -296,6 +318,7 @@ public class RefListTest extends TestCase { assertSame(REF_c, two.get(1)); } + @Test public void testRemoveEndOfList() { RefList one = toList(REF_A, REF_B, REF_c); RefList two = one.remove(2); @@ -311,6 +334,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, two.get(1)); } + @Test public void testRemoveMakesEmpty() { RefList one = toList(REF_A); RefList two = one.remove(1); @@ -318,6 +342,7 @@ public class RefListTest extends TestCase { assertSame(two, RefList.emptyList()); } + @Test public void testToString() { StringBuilder exp = new StringBuilder(); exp.append("["); @@ -330,6 +355,7 @@ public class RefListTest extends TestCase { assertEquals(exp.toString(), list.toString()); } + @Test public void testBuilder_ToString() { StringBuilder exp = new StringBuilder(); exp.append("["); @@ -344,6 +370,7 @@ public class RefListTest extends TestCase { assertEquals(exp.toString(), list.toString()); } + @Test public void testFindContainsGet() { RefList list = toList(REF_A, REF_B, REF_c); @@ -369,6 +396,7 @@ public class RefListTest extends TestCase { assertFalse(list.contains("z")); } + @Test public void testIterable() { RefList list = toList(REF_A, REF_B, REF_c); @@ -396,6 +424,7 @@ public class RefListTest extends TestCase { } } + @Test public void testCopyLeadingPrefix() { RefList one = toList(REF_A, REF_B, REF_c); RefList two = one.copy(2).toRefList(); @@ -411,6 +440,7 @@ public class RefListTest extends TestCase { assertSame(REF_B, two.get(1)); } + @Test public void testCopyConstructorReusesArray() { RefList.Builder one = new RefList.Builder(); one.add(REF_A); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefMapTest.java index c4c2383f5..40790a5b4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefMapTest.java @@ -43,18 +43,25 @@ package org.eclipse.jgit.util; +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; +import static org.junit.Assert.fail; + import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; -import junit.framework.TestCase; - import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.SymbolicRef; +import org.junit.Before; +import org.junit.Test; -public class RefMapTest extends TestCase { +public class RefMapTest { private static final ObjectId ID_ONE = ObjectId .fromString("41eb0d88f833b558bddeb269b7ab77399cdf98ed"); @@ -67,13 +74,14 @@ public class RefMapTest extends TestCase { private RefList resolved; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { packed = RefList.emptyList(); loose = RefList.emptyList(); resolved = RefList.emptyList(); } + @Test public void testEmpty_NoPrefix1() { RefMap map = new RefMap("", packed, loose, resolved); assertTrue(map.isEmpty()); // before size was computed @@ -86,6 +94,7 @@ public class RefMapTest extends TestCase { assertNull(map.get("a")); } + @Test public void testEmpty_NoPrefix2() { RefMap map = new RefMap(); assertTrue(map.isEmpty()); // before size was computed @@ -98,6 +107,7 @@ public class RefMapTest extends TestCase { assertNull(map.get("a")); } + @Test public void testNotEmpty_NoPrefix() { final Ref master = newRef("refs/heads/master", ID_ONE); packed = toList(master); @@ -109,6 +119,7 @@ public class RefMapTest extends TestCase { assertSame(master, map.values().iterator().next()); } + @Test public void testEmpty_WithPrefix() { final Ref master = newRef("refs/heads/master", ID_ONE); packed = toList(master); @@ -122,6 +133,7 @@ public class RefMapTest extends TestCase { assertFalse(map.keySet().iterator().hasNext()); } + @Test public void testNotEmpty_WithPrefix() { final Ref master = newRef("refs/heads/master", ID_ONE); packed = toList(master); @@ -133,6 +145,7 @@ public class RefMapTest extends TestCase { assertSame(master, map.values().iterator().next()); } + @Test public void testClear() { final Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); @@ -146,6 +159,7 @@ public class RefMapTest extends TestCase { assertEquals(0, map.size()); } + @Test public void testIterator_RefusesRemove() { final Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); @@ -162,6 +176,7 @@ public class RefMapTest extends TestCase { } } + @Test public void testIterator_FailsAtEnd() { final Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); @@ -178,6 +193,7 @@ public class RefMapTest extends TestCase { } } + @Test public void testIterator_MissingUnresolvedSymbolicRefIsBug() { final Ref master = newRef("refs/heads/master", ID_ONE); final Ref headR = newRef("HEAD", master); @@ -196,6 +212,7 @@ public class RefMapTest extends TestCase { } } + @Test public void testMerge_HeadMaster() { final Ref master = newRef("refs/heads/master", ID_ONE); final Ref headU = newRef("HEAD", "refs/heads/master"); @@ -221,6 +238,7 @@ public class RefMapTest extends TestCase { assertFalse(itr.hasNext()); } + @Test public void testMerge_PackedLooseLoose() { final Ref refA = newRef("A", ID_ONE); final Ref refB_ONE = newRef("B", ID_ONE); @@ -249,6 +267,7 @@ public class RefMapTest extends TestCase { assertFalse(itr.hasNext()); } + @Test public void testMerge_WithPrefix() { final Ref a = newRef("refs/heads/A", ID_ONE); final Ref b = newRef("refs/heads/foo/bar/B", ID_TWO); @@ -282,6 +301,7 @@ public class RefMapTest extends TestCase { assertFalse(itr.hasNext()); } + @Test public void testPut_KeyMustMatchName_NoPrefix() { final Ref refA = newRef("refs/heads/A", ID_ONE); RefMap map = new RefMap("", packed, loose, resolved); @@ -293,6 +313,7 @@ public class RefMapTest extends TestCase { } } + @Test public void testPut_KeyMustMatchName_WithPrefix() { final Ref refA = newRef("refs/heads/A", ID_ONE); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); @@ -304,6 +325,7 @@ public class RefMapTest extends TestCase { } } + @Test public void testPut_NoPrefix() { final Ref refA_one = newRef("refs/heads/A", ID_ONE); final Ref refA_two = newRef("refs/heads/A", ID_TWO); @@ -323,6 +345,7 @@ public class RefMapTest extends TestCase { assertSame(refA_one, map.get(refA_one.getName())); } + @Test public void testPut_WithPrefix() { final Ref refA_one = newRef("refs/heads/A", ID_ONE); final Ref refA_two = newRef("refs/heads/A", ID_TWO); @@ -342,6 +365,7 @@ public class RefMapTest extends TestCase { assertSame(refA_one, map.get("A")); } + @Test public void testPut_CollapseResolved() { final Ref master = newRef("refs/heads/master", ID_ONE); final Ref headU = newRef("HEAD", "refs/heads/master"); @@ -357,6 +381,7 @@ public class RefMapTest extends TestCase { assertSame(headR, map.get("HEAD")); } + @Test public void testRemove() { final Ref master = newRef("refs/heads/master", ID_ONE); final Ref headU = newRef("HEAD", "refs/heads/master"); @@ -378,6 +403,7 @@ public class RefMapTest extends TestCase { assertTrue(map.isEmpty()); } + @Test public void testToString_NoPrefix() { final Ref a = newRef("refs/heads/A", ID_ONE); final Ref b = newRef("refs/heads/B", ID_TWO); @@ -395,6 +421,7 @@ public class RefMapTest extends TestCase { assertEquals(exp.toString(), map.toString()); } + @Test public void testToString_WithPrefix() { final Ref a = newRef("refs/heads/A", ID_ONE); final Ref b = newRef("refs/heads/foo/B", ID_TWO); @@ -414,6 +441,7 @@ public class RefMapTest extends TestCase { assertEquals(exp.toString(), map.toString()); } + @Test public void testEntryType() { final Ref a = newRef("refs/heads/A", ID_ONE); final Ref b = newRef("refs/heads/B", ID_TWO); @@ -432,6 +460,7 @@ public class RefMapTest extends TestCase { assertEquals(a.toString(), ent_a.toString()); } + @Test public void testEntryTypeSet() { final Ref refA_one = newRef("refs/heads/A", ID_ONE); final Ref refA_two = newRef("refs/heads/A", ID_TWO); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java index 912380dcd..d7b92ade9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java @@ -43,9 +43,14 @@ package org.eclipse.jgit.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -public class StringUtilsTest extends TestCase { +import org.junit.Test; + +public class StringUtilsTest { + @Test public void testToLowerCaseChar() { assertEquals('a', StringUtils.toLowerCase('A')); assertEquals('z', StringUtils.toLowerCase('Z')); @@ -57,25 +62,30 @@ public class StringUtilsTest extends TestCase { assertEquals((char) 0xffff, StringUtils.toLowerCase((char) 0xffff)); } + @Test public void testToLowerCaseString() { assertEquals("\n abcdefghijklmnopqrstuvwxyz\n", StringUtils .toLowerCase("\n ABCDEFGHIJKLMNOPQRSTUVWXYZ\n")); } + @Test public void testEqualsIgnoreCase1() { final String a = "FOO"; assertTrue(StringUtils.equalsIgnoreCase(a, a)); } + @Test public void testEqualsIgnoreCase2() { assertFalse(StringUtils.equalsIgnoreCase("a", "")); } + @Test public void testEqualsIgnoreCase3() { assertFalse(StringUtils.equalsIgnoreCase("a", "b")); assertFalse(StringUtils.equalsIgnoreCase("ac", "ab")); } + @Test public void testEqualsIgnoreCase4() { assertTrue(StringUtils.equalsIgnoreCase("a", "a")); assertTrue(StringUtils.equalsIgnoreCase("A", "a")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java index ea1fd7313..cc4cad5ee 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java @@ -43,16 +43,22 @@ package org.eclipse.jgit.util; +import static org.eclipse.jgit.junit.JGitTestUtil.getName; +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.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import org.eclipse.jgit.junit.TestRng; +import org.junit.Test; -import junit.framework.TestCase; - -public class TemporaryBufferTest extends TestCase { +public class TemporaryBufferTest { + @Test public void testEmpty() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); try { @@ -66,6 +72,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testOneByte() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte test = (byte) new TestRng(getName()).nextInt(); @@ -92,6 +99,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testOneBlock_BulkWrite() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -122,6 +130,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testOneBlockAndHalf_BulkWrite() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -152,6 +161,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testOneBlockAndHalf_SingleWrite() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -180,6 +190,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testOneBlockAndHalf_Copy() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -209,6 +220,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testLarge_SingleWrite() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -236,6 +248,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testInCoreLimit_SwitchOnAppendByte() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -264,6 +277,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -292,6 +306,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testInCoreLimit_SwitchOnCopy() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final byte[] test = new TestRng(getName()) @@ -323,6 +338,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testDestroyWhileOpen() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); try { @@ -333,6 +349,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testRandomWrites() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.LocalFile(); final TestRng rng = new TestRng(getName()); @@ -379,6 +396,7 @@ public class TemporaryBufferTest extends TestCase { } } + @Test public void testHeap() throws IOException { final TemporaryBuffer b = new TemporaryBuffer.Heap(2 * 8 * 1024); final byte[] r = new byte[8 * 1024]; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java index b8061dcf3..37660ce72 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/EolCanonicalizingInputStreamTest.java @@ -43,29 +43,35 @@ package org.eclipse.jgit.util.io; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import junit.framework.TestCase; +import org.junit.Test; -public class EolCanonicalizingInputStreamTest extends TestCase { +public class EolCanonicalizingInputStreamTest { + @Test public void testLF() throws IOException { final byte[] bytes = asBytes("1\n2\n3"); test(bytes, bytes); } + @Test public void testCR() throws IOException { final byte[] bytes = asBytes("1\r2\r3"); test(bytes, bytes); } + @Test public void testCRLF() throws IOException { test(asBytes("1\r\n2\r\n3"), asBytes("1\n2\n3")); } + @Test public void testLFCR() throws IOException { final byte[] bytes = asBytes("1\n\r2\n\r3"); test(bytes, bytes); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutInputStreamTest.java index b4a6a6a9b..21aab0690 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutInputStreamTest.java @@ -43,6 +43,11 @@ package org.eclipse.jgit.util.io; +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.IOException; import java.io.InterruptedIOException; import java.io.PipedInputStream; @@ -51,12 +56,11 @@ import java.util.Arrays; import java.util.List; import org.eclipse.jgit.util.IO; -import org.eclipse.jgit.util.io.InterruptTimer; -import org.eclipse.jgit.util.io.TimeoutInputStream; - -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class TimeoutInputStreamTest extends TestCase { +public class TimeoutInputStreamTest { private static final int timeout = 250; private PipedOutputStream out; @@ -69,8 +73,8 @@ public class TimeoutInputStreamTest extends TestCase { private long start; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { out = new PipedOutputStream(); in = new PipedInputStream(out); timer = new InterruptTimer(); @@ -78,18 +82,20 @@ public class TimeoutInputStreamTest extends TestCase { is.setTimeout(timeout); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { timer.terminate(); for (Thread t : active()) assertFalse(t instanceof InterruptTimer.AlarmThread); - super.tearDown(); } + @Test public void testTimeout_readByte_Success1() throws IOException { out.write('a'); assertEquals('a', is.read()); } + @Test public void testTimeout_readByte_Success2() throws IOException { final byte[] exp = new byte[] { 'a', 'b', 'c' }; out.write(exp); @@ -100,6 +106,7 @@ public class TimeoutInputStreamTest extends TestCase { assertEquals(-1, is.read()); } + @Test public void testTimeout_readByte_Timeout() throws IOException { beginRead(); try { @@ -111,6 +118,7 @@ public class TimeoutInputStreamTest extends TestCase { assertTimeout(); } + @Test public void testTimeout_readBuffer_Success1() throws IOException { final byte[] exp = new byte[] { 'a', 'b', 'c' }; final byte[] act = new byte[exp.length]; @@ -119,6 +127,7 @@ public class TimeoutInputStreamTest extends TestCase { assertTrue(Arrays.equals(exp, act)); } + @Test public void testTimeout_readBuffer_Success2() throws IOException { final byte[] exp = new byte[] { 'a', 'b', 'c' }; final byte[] act = new byte[exp.length]; @@ -129,6 +138,7 @@ public class TimeoutInputStreamTest extends TestCase { assertTrue(Arrays.equals(exp, act)); } + @Test public void testTimeout_readBuffer_Timeout() throws IOException { beginRead(); try { @@ -140,6 +150,7 @@ public class TimeoutInputStreamTest extends TestCase { assertTimeout(); } + @Test public void testTimeout_skip_Success() throws IOException { final byte[] exp = new byte[] { 'a', 'b', 'c' }; out.write(exp); @@ -147,6 +158,7 @@ public class TimeoutInputStreamTest extends TestCase { assertEquals('c', is.read()); } + @Test public void testTimeout_skip_Timeout() throws IOException { beginRead(); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java index f7afd21ab..f4d1ad5ae 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java @@ -43,6 +43,11 @@ package org.eclipse.jgit.util.io; +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.IOException; import java.io.InterruptedIOException; import java.io.OutputStream; @@ -52,12 +57,11 @@ import java.util.Arrays; import java.util.List; import org.eclipse.jgit.util.IO; -import org.eclipse.jgit.util.io.InterruptTimer; -import org.eclipse.jgit.util.io.TimeoutOutputStream; - -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class TimeoutOutputStreamTest extends TestCase { +public class TimeoutOutputStreamTest { private static final int timeout = 250; private PipedOutputStream out; @@ -70,8 +74,8 @@ public class TimeoutOutputStreamTest extends TestCase { private long start; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { out = new PipedOutputStream(); in = new FullPipeInputStream(out); timer = new InterruptTimer(); @@ -79,13 +83,14 @@ public class TimeoutOutputStreamTest extends TestCase { os.setTimeout(timeout); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { timer.terminate(); for (Thread t : active()) assertFalse(t instanceof InterruptTimer.AlarmThread); - super.tearDown(); } + @Test public void testTimeout_writeByte_Success1() throws IOException { in.free(1); os.write('a'); @@ -93,6 +98,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertEquals('a', in.read()); } + @Test public void testTimeout_writeByte_Success2() throws IOException { final byte[] exp = new byte[] { 'a', 'b', 'c' }; final byte[] act = new byte[exp.length]; @@ -105,6 +111,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTrue(Arrays.equals(exp, act)); } + @Test public void testTimeout_writeByte_Timeout() throws IOException { beginWrite(); try { @@ -116,6 +123,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTimeout(); } + @Test public void testTimeout_writeBuffer_Success1() throws IOException { final byte[] exp = new byte[] { 'a', 'b', 'c' }; final byte[] act = new byte[exp.length]; @@ -126,6 +134,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTrue(Arrays.equals(exp, act)); } + @Test public void testTimeout_writeBuffer_Timeout() throws IOException { beginWrite(); try { @@ -137,6 +146,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTimeout(); } + @Test public void testTimeout_flush_Success() throws IOException { final boolean[] called = new boolean[1]; os = new TimeoutOutputStream(new OutputStream() { @@ -155,6 +165,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTrue(called[0]); } + @Test public void testTimeout_flush_Timeout() throws IOException { final boolean[] called = new boolean[1]; os = new TimeoutOutputStream(new OutputStream() { @@ -188,6 +199,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTrue(called[0]); } + @Test public void testTimeout_close_Success() throws IOException { final boolean[] called = new boolean[1]; os = new TimeoutOutputStream(new OutputStream() { @@ -206,6 +218,7 @@ public class TimeoutOutputStreamTest extends TestCase { assertTrue(called[0]); } + @Test public void testTimeout_close_Timeout() throws IOException { final boolean[] called = new boolean[1]; os = new TimeoutOutputStream(new OutputStream() { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java index 2bcd134c6..5fd6816ec 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java @@ -43,13 +43,19 @@ package org.eclipse.jgit.util.io; +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.ByteArrayInputStream; import java.io.IOException; import java.util.Arrays; -import junit.framework.TestCase; +import org.junit.Test; -public class UnionInputStreamTest extends TestCase { +public class UnionInputStreamTest { + @Test public void testEmptyStream() throws IOException { final UnionInputStream u = new UnionInputStream(); assertTrue(u.isEmpty()); @@ -60,6 +66,7 @@ public class UnionInputStreamTest extends TestCase { u.close(); } + @Test public void testReadSingleBytes() throws IOException { final UnionInputStream u = new UnionInputStream(); @@ -91,6 +98,7 @@ public class UnionInputStreamTest extends TestCase { assertTrue(u.isEmpty()); } + @Test public void testReadByteBlocks() throws IOException { final UnionInputStream u = new UnionInputStream(); u.add(new ByteArrayInputStream(new byte[] { 1, 0, 2 })); @@ -105,6 +113,7 @@ public class UnionInputStreamTest extends TestCase { assertEquals(-1, u.read(r, 0, 5)); } + @Test public void testArrayConstructor() throws IOException { final UnionInputStream u = new UnionInputStream( new ByteArrayInputStream(new byte[] { 1, 0, 2 }), @@ -119,6 +128,7 @@ public class UnionInputStreamTest extends TestCase { assertEquals(-1, u.read(r, 0, 5)); } + @Test public void testMarkSupported() { final UnionInputStream u = new UnionInputStream(); assertFalse(u.markSupported()); @@ -126,6 +136,7 @@ public class UnionInputStreamTest extends TestCase { assertFalse(u.markSupported()); } + @Test public void testSkip() throws IOException { final UnionInputStream u = new UnionInputStream(); u.add(new ByteArrayInputStream(new byte[] { 1, 0, 2 })); @@ -147,6 +158,7 @@ public class UnionInputStreamTest extends TestCase { assertEquals(-1, u.read()); } + @Test public void testAutoCloseDuringRead() throws IOException { final UnionInputStream u = new UnionInputStream(); final boolean closed[] = new boolean[2]; @@ -177,6 +189,7 @@ public class UnionInputStreamTest extends TestCase { assertTrue(closed[1]); } + @Test public void testCloseDuringClose() throws IOException { final UnionInputStream u = new UnionInputStream(); final boolean closed[] = new boolean[2]; @@ -200,6 +213,7 @@ public class UnionInputStreamTest extends TestCase { assertTrue(closed[1]); } + @Test public void testExceptionDuringClose() { final UnionInputStream u = new UnionInputStream(); u.add(new ByteArrayInputStream(new byte[] { 1 }) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/InvalidMergeHeadsException.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/InvalidMergeHeadsException.java index e56cbc438..c8edb5720 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/InvalidMergeHeadsException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/InvalidMergeHeadsException.java @@ -37,7 +37,6 @@ */ package org.eclipse.jgit.api.errors; - /** * Exception thrown when a merge command was called without specifying the * proper amount/type of merge heads. E.g. a non-octopus merge strategy was diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java index 25065a1d0..07f7990b7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java @@ -43,7 +43,6 @@ package org.eclipse.jgit.util; - /** Conversion utilities for network byte order handling. */ public final class NB { /**