diff options
author | Florian Zschocke <f.zschocke+git@gmail.com> | 2021-10-23 23:41:25 +0200 |
---|---|---|
committer | Florian Zschocke <f.zschocke+git@gmail.com> | 2021-10-23 23:47:47 +0200 |
commit | bb15bf10a7052adf0f5feb55db4f894a9053adac (patch) | |
tree | 95a3d24dd4501cf9d2852c24b7d560d8e4d66bff | |
parent | b3f35278cead1c4647a10ae615258555618bd087 (diff) | |
download | gitblit-bb15bf10a7052adf0f5feb55db4f894a9053adac.tar.gz gitblit-bb15bf10a7052adf0f5feb55db4f894a9053adac.zip |
TimeUtils: Move unit test to same package as TimeUtils is
For some reason the `TimeUtilsTest` class is, like almost all tests, in
the `com.gitblit.tests` package. But this way all methods in classes
which we might predominately need for tests have to be public.
So move the unit test class `TimeUtilsTest` to the same package as the
class it is testing, i.e. `com.gitblit.utils.TimeUtils`.
This way we ca set the new added methods which get the current time
passed in to be at least not public.
-rw-r--r-- | src/main/java/com/gitblit/utils/TimeUtils.java | 10 | ||||
-rw-r--r-- | src/test/java/com/gitblit/tests/GitBlitSuite.java | 1 | ||||
-rw-r--r-- | src/test/java/com/gitblit/utils/TimeUtilsTest.java (renamed from src/test/java/com/gitblit/tests/TimeUtilsTest.java) | 7 |
3 files changed, 10 insertions, 8 deletions
diff --git a/src/main/java/com/gitblit/utils/TimeUtils.java b/src/main/java/com/gitblit/utils/TimeUtils.java index 001e6be6..12737047 100644 --- a/src/main/java/com/gitblit/utils/TimeUtils.java +++ b/src/main/java/com/gitblit/utils/TimeUtils.java @@ -63,7 +63,7 @@ public class TimeUtils { }
- public static boolean isToday(Date date, TimeZone timezone, Date now) {
+ static boolean isToday(Date date, TimeZone timezone, Date now) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
if (timezone != null) {
df.setTimeZone(timezone);
@@ -82,7 +82,7 @@ public class TimeUtils { }
- public static boolean isYesterday(Date date, TimeZone timezone, Date now) {
+ static boolean isYesterday(Date date, TimeZone timezone, Date now) {
Calendar cal = Calendar.getInstance();
cal.setTime(now);
cal.add(Calendar.DATE, -1);
@@ -170,7 +170,7 @@ public class TimeUtils { }
- public static int hoursAgo(Date date, long now, boolean roundup) {
+ static int hoursAgo(Date date, long now, boolean roundup) {
long diff = now - date.getTime();
int hours = (int) (diff / ONEHOUR);
if (roundup && (diff % ONEHOUR) >= HALFHOUR) {
@@ -189,7 +189,7 @@ public class TimeUtils { return daysAgo(date, System.currentTimeMillis());
}
- public static int daysAgo(Date date, long now) {
+ static int daysAgo(Date date, long now) {
long today = ONEDAY * (now/ONEDAY);
long day = ONEDAY * (date.getTime()/ONEDAY);
long diff = today - day;
@@ -239,7 +239,7 @@ public class TimeUtils { }
- public String timeAgo(Date date, boolean css, long now) {
+ String timeAgo(Date date, boolean css, long now) {
Date dNow = new Date(now);
if (isToday(date, timezone, dNow) || isYesterday(date, timezone, dNow)) {
int mins = minutesAgo(date, now, true);
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index 3292d090..fbae039c 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import com.gitblit.utils.TimeUtilsTest;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
diff --git a/src/test/java/com/gitblit/tests/TimeUtilsTest.java b/src/test/java/com/gitblit/utils/TimeUtilsTest.java index 2dde6d51..77710e06 100644 --- a/src/test/java/com/gitblit/tests/TimeUtilsTest.java +++ b/src/test/java/com/gitblit/utils/TimeUtilsTest.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitblit.tests;
+package com.gitblit.utils;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
+import com.gitblit.tests.GitblitUnitTest;
import org.junit.Test;
-import com.gitblit.utils.TimeUtils;
-public class TimeUtilsTest extends GitblitUnitTest {
+public class TimeUtilsTest extends GitblitUnitTest
+{
private Date offset(long subtract) {
return new Date(System.currentTimeMillis() - subtract);
|