From 793f76563d4bb3f58fa62ff53985e20561c6e330 Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 1 Jun 2011 21:01:51 -0400 Subject: Refactored some unit tests and utils. --- tests/com/gitblit/tests/GitBlitSuite.java | 2 ++ tests/com/gitblit/tests/JGitUtilsTest.java | 35 ------------------ tests/com/gitblit/tests/MetricUtilsTest.java | 35 ++++++++++++++++++ tests/com/gitblit/tests/TicgitUtilsTest.java | 54 ++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 tests/com/gitblit/tests/MetricUtilsTest.java create mode 100644 tests/com/gitblit/tests/TicgitUtilsTest.java (limited to 'tests') diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java index d9963646..fcb57239 100644 --- a/tests/com/gitblit/tests/GitBlitSuite.java +++ b/tests/com/gitblit/tests/GitBlitSuite.java @@ -44,6 +44,8 @@ public class GitBlitSuite extends TestSetup { suite.addTestSuite(ByteFormatTest.class); suite.addTestSuite(JGitUtilsTest.class); suite.addTestSuite(DiffUtilsTest.class); + suite.addTestSuite(MetricUtilsTest.class); + suite.addTestSuite(TicgitUtilsTest.class); suite.addTestSuite(GitBlitTest.class); return new GitBlitSuite(suite); } diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java index 14d318f3..f1dcaac4 100644 --- a/tests/com/gitblit/tests/JGitUtilsTest.java +++ b/tests/com/gitblit/tests/JGitUtilsTest.java @@ -30,13 +30,9 @@ import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevTree; import com.gitblit.GitBlit; -import com.gitblit.models.Metric; import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.models.RefModel; -import com.gitblit.models.TicketModel; -import com.gitblit.models.TicketModel.Comment; import com.gitblit.utils.JGitUtils; -import com.gitblit.utils.MetricUtils; public class JGitUtilsTest extends TestCase { @@ -182,35 +178,4 @@ public class JGitUtilsTest extends TestCase { zipFile.delete(); repository.close(); } - - public void testMetrics() throws Exception { - Repository repository = GitBlitSuite.getHelloworldRepository(); - List metrics = MetricUtils.getDateMetrics(repository, true); - repository.close(); - assertTrue("No metrics found!", metrics.size() > 0); - } - - public void testTicGit() throws Exception { - Repository repository = GitBlitSuite.getTicgitRepository(); - RefModel branch = JGitUtils.getTicketsBranch(repository); - assertTrue("Ticgit branch does not exist!", branch != null); - List ticketsA = JGitUtils.getTickets(repository); - List ticketsB = JGitUtils.getTickets(repository); - repository.close(); - assertTrue("No tickets found!", ticketsA.size() > 0); - for (int i = 0; i < ticketsA.size(); i++) { - TicketModel ticketA = ticketsA.get(i); - TicketModel ticketB = ticketsB.get(i); - assertTrue("Tickets are not equal!", ticketA.equals(ticketB)); - assertFalse(ticketA.equals("")); - assertTrue(ticketA.hashCode() == ticketA.id.hashCode()); - for (int j = 0; j < ticketA.comments.size(); j++) { - Comment commentA = ticketA.comments.get(j); - Comment commentB = ticketB.comments.get(j); - assertTrue("Comments are not equal!", commentA.equals(commentB)); - assertFalse(commentA.equals("")); - assertTrue(commentA.hashCode() == commentA.text.hashCode()); - } - } - } } \ No newline at end of file diff --git a/tests/com/gitblit/tests/MetricUtilsTest.java b/tests/com/gitblit/tests/MetricUtilsTest.java new file mode 100644 index 00000000..77f43a16 --- /dev/null +++ b/tests/com/gitblit/tests/MetricUtilsTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.jgit.lib.Repository; + +import com.gitblit.models.Metric; +import com.gitblit.utils.MetricUtils; + +public class MetricUtilsTest extends TestCase { + + public void testMetrics() throws Exception { + Repository repository = GitBlitSuite.getHelloworldRepository(); + List metrics = MetricUtils.getDateMetrics(repository, true); + repository.close(); + assertTrue("No metrics found!", metrics.size() > 0); + } +} \ No newline at end of file diff --git a/tests/com/gitblit/tests/TicgitUtilsTest.java b/tests/com/gitblit/tests/TicgitUtilsTest.java new file mode 100644 index 00000000..25dba2c6 --- /dev/null +++ b/tests/com/gitblit/tests/TicgitUtilsTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.jgit.lib.Repository; + +import com.gitblit.models.RefModel; +import com.gitblit.models.TicketModel; +import com.gitblit.models.TicketModel.Comment; +import com.gitblit.utils.TicgitUtils; + +public class TicgitUtilsTest extends TestCase { + + public void testTicGit() throws Exception { + Repository repository = GitBlitSuite.getTicgitRepository(); + RefModel branch = TicgitUtils.getTicketsBranch(repository); + assertTrue("Ticgit branch does not exist!", branch != null); + List ticketsA = TicgitUtils.getTickets(repository); + List ticketsB = TicgitUtils.getTickets(repository); + repository.close(); + assertTrue("No tickets found!", ticketsA.size() > 0); + for (int i = 0; i < ticketsA.size(); i++) { + TicketModel ticketA = ticketsA.get(i); + TicketModel ticketB = ticketsB.get(i); + assertTrue("Tickets are not equal!", ticketA.equals(ticketB)); + assertFalse(ticketA.equals("")); + assertTrue(ticketA.hashCode() == ticketA.id.hashCode()); + for (int j = 0; j < ticketA.comments.size(); j++) { + Comment commentA = ticketA.comments.get(j); + Comment commentB = ticketB.comments.get(j); + assertTrue("Comments are not equal!", commentA.equals(commentB)); + assertFalse(commentA.equals("")); + assertTrue(commentA.hashCode() == commentA.text.hashCode()); + } + } + } +} \ No newline at end of file -- cgit v1.2.3