You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MetricUtilsTest.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.tests;
  17. import java.util.List;
  18. import java.util.TimeZone;
  19. import org.eclipse.jgit.lib.Repository;
  20. import org.junit.Test;
  21. import com.gitblit.models.Metric;
  22. import com.gitblit.utils.MetricUtils;
  23. public class MetricUtilsTest extends GitblitUnitTest {
  24. @Test
  25. public void testMetrics() throws Exception {
  26. testMetrics(GitBlitSuite.getHelloworldRepository());
  27. testMetrics(GitBlitSuite.getJGitRepository());
  28. }
  29. private void testMetrics(Repository repository) throws Exception {
  30. List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null,
  31. TimeZone.getDefault());
  32. repository.close();
  33. assertTrue("No date metrics found!", metrics.size() > 0);
  34. }
  35. @Test
  36. public void testAuthorMetrics() throws Exception {
  37. Repository repository = GitBlitSuite.getHelloworldRepository();
  38. List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);
  39. List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false);
  40. repository.close();
  41. assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byEmail, -1), byEmail.size());
  42. assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byName, -1), byName.size());
  43. }
  44. }