From 143fc9d357c174a56340052618d481617686fc72 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 7 Nov 2011 21:21:28 -0500 Subject: [PATCH] Unit testing --- src/com/gitblit/utils/TimeUtils.java | 8 +- tests/com/gitblit/tests/Base64Test.java | 31 +++++++ tests/com/gitblit/tests/FileUtilsTest.java | 8 ++ tests/com/gitblit/tests/GitBlitSuite.java | 44 ++++++++++ tests/com/gitblit/tests/GitBlitTest.java | 10 +-- tests/com/gitblit/tests/JsonUtilsTest.java | 58 ++++++++++++++ tests/com/gitblit/tests/ObjectCacheTest.java | 42 ++++++++++ tests/com/gitblit/tests/RpcTests.java | 40 +++------- .../gitblit/tests/SyndicationUtilsTest.java | 23 ++++-- tests/com/gitblit/tests/TimeUtilsTest.java | 80 ++++++++++--------- 10 files changed, 262 insertions(+), 82 deletions(-) create mode 100644 tests/com/gitblit/tests/Base64Test.java create mode 100644 tests/com/gitblit/tests/JsonUtilsTest.java create mode 100644 tests/com/gitblit/tests/ObjectCacheTest.java diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java index 7ac1e79f..ef8d4287 100644 --- a/src/com/gitblit/utils/TimeUtils.java +++ b/src/com/gitblit/utils/TimeUtils.java @@ -253,11 +253,9 @@ public class TimeUtils { int mins = 60; if (!StringUtils.isEmpty(frequency)) { try { - String str; + String str = frequency.trim(); if (frequency.indexOf(' ') > -1) { - str = frequency.substring(0, frequency.indexOf(' ')).trim(); - } else { - str = frequency.trim(); + str = str.substring(0, str.indexOf(' ')).trim(); } mins = (int) Float.parseFloat(str); } catch (NumberFormatException e) { @@ -268,7 +266,7 @@ public class TimeUtils { } if (frequency.indexOf("day") > -1) { // convert to minutes - mins *= 24 * 60; + mins *= 1440; } else if (frequency.indexOf("hour") > -1) { // convert to minutes mins *= 60; diff --git a/tests/com/gitblit/tests/Base64Test.java b/tests/com/gitblit/tests/Base64Test.java new file mode 100644 index 00000000..31277362 --- /dev/null +++ b/tests/com/gitblit/tests/Base64Test.java @@ -0,0 +1,31 @@ +/* + * 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 junit.framework.TestCase; + +import com.gitblit.utils.Base64; + +public class Base64Test extends TestCase { + + public void testBase64() { + String source = "this is a test"; + String base64 = Base64.encodeBytes(source.getBytes()); + assertEquals("dGhpcyBpcyBhIHRlc3Q=", base64); + String decoded = new String(Base64.decode(base64)); + assertEquals(source, decoded); + } +} \ No newline at end of file diff --git a/tests/com/gitblit/tests/FileUtilsTest.java b/tests/com/gitblit/tests/FileUtilsTest.java index 63d0f330..025a2238 100644 --- a/tests/com/gitblit/tests/FileUtilsTest.java +++ b/tests/com/gitblit/tests/FileUtilsTest.java @@ -28,6 +28,14 @@ public class FileUtilsTest extends TestCase { String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n"); assertTrue(rawContent.trim().startsWith("Apache License")); } + + public void testWriteContent() throws Exception { + String contentA = "this is a test"; + File tmp = File.createTempFile("gitblit-", ".test"); + FileUtils.writeContent(tmp, contentA); + String contentB = FileUtils.readContent(tmp, "\n").trim(); + assertEquals(contentA, contentB); + } public void testFolderSize() throws Exception { assertEquals(-1, FileUtils.folderSize(null)); diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java index 52a1d0bf..ad87cb0b 100644 --- a/tests/com/gitblit/tests/GitBlitSuite.java +++ b/tests/com/gitblit/tests/GitBlitSuite.java @@ -16,6 +16,7 @@ package com.gitblit.tests; import java.io.File; +import java.util.concurrent.Executors; import junit.extensions.TestSetup; import junit.framework.Test; @@ -28,12 +29,21 @@ import com.gitblit.FileSettings; import com.gitblit.FileUserService; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; +import com.gitblit.GitBlitServer; import com.gitblit.models.RepositoryModel; import com.gitblit.utils.JGitUtils; public class GitBlitSuite extends TestSetup { + public static final File REPOSITORIES = new File("git"); + static int port = 8280; + static int shutdownPort = 8281; + + public static String url = "http://localhost:" + port; + public static String account = "admin"; + public static String password = "admin"; + private GitBlitSuite(TestSuite suite) { super(suite); } @@ -43,7 +53,10 @@ public class GitBlitSuite extends TestSetup { suite.addTestSuite(FileUtilsTest.class); suite.addTestSuite(TimeUtilsTest.class); suite.addTestSuite(StringUtilsTest.class); + suite.addTestSuite(Base64Test.class); + suite.addTestSuite(JsonUtilsTest.class); suite.addTestSuite(ByteFormatTest.class); + suite.addTestSuite(ObjectCacheTest.class); suite.addTestSuite(MarkdownUtilsTest.class); suite.addTestSuite(JGitUtilsTest.class); suite.addTestSuite(SyndicationUtilsTest.class); @@ -51,6 +64,7 @@ public class GitBlitSuite extends TestSetup { suite.addTestSuite(MetricUtilsTest.class); suite.addTestSuite(TicgitUtilsTest.class); suite.addTestSuite(GitBlitTest.class); + suite.addTestSuite(RpcTests.class); return new GitBlitSuite(suite); } @@ -70,6 +84,29 @@ public class GitBlitSuite extends TestSetup { return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git")); } + public static void startGitblit() throws Exception { + // Start a Gitblit instance + Executors.newSingleThreadExecutor().execute(new Runnable() { + public void run() { + GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort", + "" + shutdownPort, "--repositoriesFolder", + "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService", + "distrib/users.properties"); + } + }); + + // Wait a few seconds for it to be running + Thread.sleep(2500); + } + + public static void stopGitblit() throws Exception { + // Stop Gitblit + GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort); + + // Wait a few seconds for it to be running + Thread.sleep(2500); + } + @Override protected void setUp() throws Exception { FileSettings settings = new FileSettings("distrib/gitblit.properties"); @@ -90,6 +127,13 @@ public class GitBlitSuite extends TestSetup { showRemoteBranches("ticgit.git"); showRemoteBranches("test/jgit.git"); } + + startGitblit(); + } + + @Override + protected void tearDown() throws Exception { + stopGitblit(); } private void cloneOrFetch(String name, String fromUrl) throws Exception { diff --git a/tests/com/gitblit/tests/GitBlitTest.java b/tests/com/gitblit/tests/GitBlitTest.java index 81616c3b..1d20ced9 100644 --- a/tests/com/gitblit/tests/GitBlitTest.java +++ b/tests/com/gitblit/tests/GitBlitTest.java @@ -111,13 +111,13 @@ public class GitBlitTest extends TestCase { public void testGitblitSettings() throws Exception { // These are already tested by above test method. assertTrue(GitBlit.getBoolean("missing", true)); - assertTrue(GitBlit.getString("missing", "default").equals("default")); - assertTrue(GitBlit.getInteger("missing", 10) == 10); - assertTrue(GitBlit.getInteger("realm.userService", 5) == 5); + assertEquals("default", GitBlit.getString("missing", "default")); + assertEquals(10, GitBlit.getInteger("missing", 10)); + assertEquals(5, GitBlit.getInteger("realm.userService", 5)); assertTrue(GitBlit.getBoolean("git.enableGitServlet", false)); - assertTrue(GitBlit.getString("realm.userService", null).equals("users.properties")); - assertTrue(GitBlit.getInteger("realm.minPasswordLength", 0) == 5); + assertEquals("distrib/users.properties", GitBlit.getString("realm.userService", null)); + assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0)); List mdExtensions = GitBlit.getStrings("web.markdownExtensions"); assertTrue(mdExtensions.size() > 0); assertTrue(mdExtensions.contains("md")); diff --git a/tests/com/gitblit/tests/JsonUtilsTest.java b/tests/com/gitblit/tests/JsonUtilsTest.java new file mode 100644 index 00000000..e70bd8a0 --- /dev/null +++ b/tests/com/gitblit/tests/JsonUtilsTest.java @@ -0,0 +1,58 @@ +/* + * 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.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import com.gitblit.utils.JsonUtils; +import com.google.gson.reflect.TypeToken; + +public class JsonUtilsTest extends TestCase { + + public void testSerialization() { + Map map = new HashMap(); + map.put("a", "alligator"); + map.put("b", "bear"); + map.put("c", "caterpillar"); + map.put("d", "dingo"); + map.put("e", "eagle"); + String json = JsonUtils.toJsonString(map); + assertEquals( + "{\n \"d\": \"dingo\",\n \"e\": \"eagle\",\n \"b\": \"bear\",\n \"c\": \"caterpillar\",\n \"a\": \"alligator\"\n}", + json); + Map map2 = JsonUtils.fromJsonString(json, + new TypeToken>() { + }.getType()); + assertEquals(map, map2); + + SomeJsonObject someJson = new SomeJsonObject(); + json = JsonUtils.toJsonString(someJson); + SomeJsonObject someJson2 = JsonUtils.fromJsonString(json, SomeJsonObject.class); + assertEquals(someJson.name, someJson2.name); + SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HHmmss"); + assertEquals(df.format(someJson.date), df.format(someJson2.date)); + } + + private class SomeJsonObject { + Date date = new Date(); + String name = "myJson"; + } +} \ No newline at end of file diff --git a/tests/com/gitblit/tests/ObjectCacheTest.java b/tests/com/gitblit/tests/ObjectCacheTest.java new file mode 100644 index 00000000..054761ff --- /dev/null +++ b/tests/com/gitblit/tests/ObjectCacheTest.java @@ -0,0 +1,42 @@ +/* + * 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.Date; + +import junit.framework.TestCase; + +import com.gitblit.utils.ObjectCache; + +public class ObjectCacheTest extends TestCase { + + public void testCache() throws Exception { + ObjectCache cache = new ObjectCache(); + cache.updateObject("test", "alpha"); + Date date = cache.getDate("test"); + assertTrue("cache date is not working!", cache.hasCurrent("test", date)); + // The cache is time-based (msecs) so we insert this artificial sleep to + // ensure that time (msecs) advances. The ObjectCache class is suitable + // for Gitblit's needs but may not be suitable for other needs. + Thread.sleep(10); + cache.updateObject("test", "beta"); + assertFalse("update cache date is not working!", cache.hasCurrent("test", date)); + assertEquals("unexpected cache object", cache.getObject("test"), "beta"); + assertEquals("beta", cache.remove("test")); + assertEquals(null, cache.getObject("test")); + assertEquals(null, cache.remove("test")); + } +} diff --git a/tests/com/gitblit/tests/RpcTests.java b/tests/com/gitblit/tests/RpcTests.java index a64d1b87..ab6a8b8a 100644 --- a/tests/com/gitblit/tests/RpcTests.java +++ b/tests/com/gitblit/tests/RpcTests.java @@ -15,15 +15,13 @@ */ package com.gitblit.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.Executors; + +import junit.framework.TestCase; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -31,7 +29,6 @@ import org.junit.Test; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlitException.UnauthorizedException; -import com.gitblit.GitBlitServer; import com.gitblit.Keys; import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; @@ -48,38 +45,21 @@ import com.gitblit.utils.RpcUtils; * @author James Moger * */ -public class RpcTests { - - static int port = 8180; - static int shutdownPort = 8181; - - String url = "http://localhost:" + port; - String account = "admin"; - String password = "admin"; +public class RpcTests extends TestCase { + + String url = GitBlitSuite.url; + String account = GitBlitSuite.account; + String password = GitBlitSuite.password; + @BeforeClass public static void startGitblit() throws Exception { - // Start a Gitblit instance - Executors.newSingleThreadExecutor().execute(new Runnable() { - public void run() { - GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort", - "" + shutdownPort, "--repositoriesFolder", - "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService", - "distrib/users.properties"); - } - }); - - // Wait a few seconds for it to be running - Thread.sleep(2500); + GitBlitSuite.startGitblit(); } @AfterClass public static void stopGitblit() throws Exception { - // Stop Gitblit - GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort); - - // Wait a few seconds for it to be running - Thread.sleep(2500); + GitBlitSuite.stopGitblit(); } @Test diff --git a/tests/com/gitblit/tests/SyndicationUtilsTest.java b/tests/com/gitblit/tests/SyndicationUtilsTest.java index e0a32bf3..0746642c 100644 --- a/tests/com/gitblit/tests/SyndicationUtilsTest.java +++ b/tests/com/gitblit/tests/SyndicationUtilsTest.java @@ -24,6 +24,7 @@ import java.util.Set; import junit.framework.TestCase; +import com.gitblit.Constants.SearchType; import com.gitblit.models.SyndicatedEntryModel; import com.gitblit.utils.SyndicationUtils; @@ -41,6 +42,11 @@ public class SyndicationUtilsTest extends TestCase { entry.content = "Content " + i; entry.repository = "Repository " + i; entry.branch = "Branch " + i; + List tags = new ArrayList(); + for (int j = 0; j < 5; j++) { + tags.add("Tag " + j); + } + entry.tags = tags; entries.add(entry); } ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -55,8 +61,9 @@ public class SyndicationUtilsTest extends TestCase { public void testFeedRead() throws Exception { Set links = new HashSet(); for (int i = 0; i < 2; i++) { - List feed = SyndicationUtils.readFeed("https://localhost:8443", - "ticgit.git", "master", 5, i, "admin", "admin".toCharArray()); + List feed = SyndicationUtils.readFeed(GitBlitSuite.url, + "ticgit.git", "master", 5, i, GitBlitSuite.account, + GitBlitSuite.password.toCharArray()); assertTrue(feed != null); assertTrue(feed.size() > 0); assertEquals(5, feed.size()); @@ -69,10 +76,16 @@ public class SyndicationUtilsTest extends TestCase { } public void testSearchFeedRead() throws Exception { - List feed = SyndicationUtils.readSearchFeed("https://localhost:8443", - "ticgit.git", null, "documentation", null, 5, 0, "admin", "admin".toCharArray()); + List feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, + "ticgit.git", null, "test", null, 5, 0, GitBlitSuite.account, + GitBlitSuite.password.toCharArray()); + assertTrue(feed != null); + assertTrue(feed.size() > 0); + assertEquals(5, feed.size()); + feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, "ticgit.git", "master", "test", + SearchType.COMMIT, 5, 1, GitBlitSuite.account, GitBlitSuite.password.toCharArray()); assertTrue(feed != null); assertTrue(feed.size() > 0); - assertEquals(2, feed.size()); + assertEquals(5, feed.size()); } } \ No newline at end of file diff --git a/tests/com/gitblit/tests/TimeUtilsTest.java b/tests/com/gitblit/tests/TimeUtilsTest.java index b2c819ff..07ed827c 100644 --- a/tests/com/gitblit/tests/TimeUtilsTest.java +++ b/tests/com/gitblit/tests/TimeUtilsTest.java @@ -47,49 +47,55 @@ public class TimeUtilsTest extends TestCase { } public void testDurations() throws Exception { - assertTrue(TimeUtils.duration(1).equals("1 day")); - assertTrue(TimeUtils.duration(5).equals("5 days")); - assertTrue(TimeUtils.duration(75).equals("3 months")); - assertTrue(TimeUtils.duration(364).equals("12 months")); - assertTrue(TimeUtils.duration(365 + 0).equals("1 year")); - assertTrue(TimeUtils.duration(365 + 10).equals("1 year")); - assertTrue(TimeUtils.duration(365 + 15).equals("1 year, 1 month")); - assertTrue(TimeUtils.duration(365 + 30).equals("1 year, 1 month")); - assertTrue(TimeUtils.duration(365 + 44).equals("1 year, 1 month")); - assertTrue(TimeUtils.duration(365 + 45).equals("1 year, 2 months")); - assertTrue(TimeUtils.duration(365 + 60).equals("1 year, 2 months")); + assertEquals("1 day", TimeUtils.duration(1)); + assertEquals("5 days", TimeUtils.duration(5)); + assertEquals("3 months", TimeUtils.duration(75)); + assertEquals("12 months", TimeUtils.duration(364)); + assertEquals("1 year", TimeUtils.duration(365 + 0)); + assertEquals("1 year", TimeUtils.duration(365 + 10)); + assertEquals("1 year, 1 month", TimeUtils.duration(365 + 15)); + assertEquals("1 year, 1 month", TimeUtils.duration(365 + 30)); + assertEquals("1 year, 1 month", TimeUtils.duration(365 + 44)); + assertEquals("1 year, 2 months", TimeUtils.duration(365 + 45)); + assertEquals("1 year, 2 months", TimeUtils.duration(365 + 60)); - assertTrue(TimeUtils.duration(2 * 365 + 0).equals("2 years")); - assertTrue(TimeUtils.duration(2 * 365 + 10).equals("2 years")); - assertTrue(TimeUtils.duration(2 * 365 + 15).equals("2 years, 1 month")); - assertTrue(TimeUtils.duration(2 * 365 + 30).equals("2 years, 1 month")); - assertTrue(TimeUtils.duration(2 * 365 + 44).equals("2 years, 1 month")); - assertTrue(TimeUtils.duration(2 * 365 + 45).equals("2 years, 2 months")); - assertTrue(TimeUtils.duration(2 * 365 + 60).equals("2 years, 2 months")); + assertEquals("2 years", TimeUtils.duration(2 * 365 + 0)); + assertEquals("2 years", TimeUtils.duration(2 * 365 + 10)); + assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 15)); + assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 30)); + assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 44)); + assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 45)); + assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 60)); } public void testTimeAgo() throws Exception { // standard time ago tests - assertTrue(TimeUtils.timeAgo(offset(1 * TimeUtils.MIN)).equals("1 min ago")); - assertTrue(TimeUtils.timeAgo(offset(60 * TimeUtils.MIN)).equals("60 mins ago")); - assertTrue(TimeUtils.timeAgo(offset(120 * TimeUtils.MIN)).equals("2 hours ago")); - assertTrue(TimeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)).equals("15 hours ago")); - assertTrue(TimeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)).equals("yesterday")); - assertTrue(TimeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)).equals("2 days ago")); - assertTrue(TimeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)).equals("5 weeks ago")); - assertTrue(TimeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)).equals("3 months ago")); - assertTrue(TimeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)).equals("3 months ago")); - assertTrue(TimeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)).equals("4 months ago")); - assertTrue(TimeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)).equals("1 year ago")); - assertTrue(TimeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)).equals("13 months ago")); - assertTrue(TimeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)).equals( - "2 years ago")); + assertEquals("1 min ago", TimeUtils.timeAgo(offset(1 * TimeUtils.MIN))); + assertEquals("60 mins ago", TimeUtils.timeAgo(offset(60 * TimeUtils.MIN))); + assertEquals("2 hours ago", TimeUtils.timeAgo(offset(120 * TimeUtils.MIN))); + assertEquals("15 hours ago", TimeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR))); + assertEquals("yesterday", TimeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR))); + assertEquals("2 days ago", TimeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY))); + assertEquals("5 weeks ago", TimeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY))); + assertEquals("3 months ago", TimeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY))); + assertEquals("3 months ago", TimeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY))); + assertEquals("4 months ago", TimeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY))); + assertEquals("1 year ago", TimeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY))); + assertEquals("13 months ago", TimeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY))); + assertEquals("2 years ago", TimeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY))); // css class tests - assertTrue(TimeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)).equals("age0")); - assertTrue(TimeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)).equals("age0")); - assertTrue(TimeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)).equals("age1")); - assertTrue(TimeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)).equals("age1")); - assertTrue(TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)).equals("age2")); + assertEquals("age0", TimeUtils.timeAgoCss(offset(1 * TimeUtils.MIN))); + assertEquals("age0", TimeUtils.timeAgoCss(offset(60 * TimeUtils.MIN))); + assertEquals("age1", TimeUtils.timeAgoCss(offset(120 * TimeUtils.MIN))); + assertEquals("age1", TimeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR))); + assertEquals("age2", TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY))); + } + + public void testFrequency() { + assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins")); + assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins")); + assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours")); + assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days ")); } } -- 2.39.5