|
|
|
@ -9,32 +9,34 @@ import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import java.util.Calendar
|
|
|
|
|
|
|
|
|
|
class HistoryAdapterTest {
|
|
|
|
|
class HistoryItemTimeGroupTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with future date THEN item is grouped to today`() {
|
|
|
|
|
val time = System.currentTimeMillis() + DateUtils.WEEK_IN_MILLIS
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() + DateUtils.WEEK_IN_MILLIS
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Today, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Today, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with today's date THEN item is grouped to today`() {
|
|
|
|
|
val time = System.currentTimeMillis() + DateUtils.MINUTE_IN_MILLIS
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Today, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Today, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -49,11 +51,11 @@ class HistoryAdapterTest {
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = calendar.timeInMillis
|
|
|
|
|
visitedAt = calendar.timeInMillis,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(calendar.timeInMillis)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Today, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Today, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -64,15 +66,17 @@ class HistoryAdapterTest {
|
|
|
|
|
set(Calendar.SECOND, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val time = calendar.timeInMillis - DateUtils.HOUR_IN_MILLIS
|
|
|
|
|
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = calendar.timeInMillis - DateUtils.HOUR_IN_MILLIS
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Yesterday, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Yesterday, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -82,15 +86,17 @@ class HistoryAdapterTest {
|
|
|
|
|
calendar.set(Calendar.MINUTE, 0)
|
|
|
|
|
calendar.set(Calendar.SECOND, 0)
|
|
|
|
|
|
|
|
|
|
val time = calendar.timeInMillis - (DateUtils.HOUR_IN_MILLIS * 23)
|
|
|
|
|
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = calendar.timeInMillis - (DateUtils.HOUR_IN_MILLIS * 23)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Yesterday, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Yesterday, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -101,80 +107,86 @@ class HistoryAdapterTest {
|
|
|
|
|
set(Calendar.SECOND, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val time = calendar.timeInMillis - (DateUtils.HOUR_IN_MILLIS * 25)
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = calendar.timeInMillis - (DateUtils.HOUR_IN_MILLIS * 25)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisWeek, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisWeek, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with 3 days ago date THEN item is grouped to this week`() {
|
|
|
|
|
val time = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 3)
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 3)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisWeek, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisWeek, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with 6 days ago date THEN item is grouped to this week`() {
|
|
|
|
|
val time = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 6)
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 6)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisWeek, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisWeek, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with 8 days ago date THEN item is grouped to this month`() {
|
|
|
|
|
val time = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 8)
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 8)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisMonth, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisMonth, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with 29 days ago date THEN item is grouped to this month`() {
|
|
|
|
|
val time = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 29)
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 29)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisMonth, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.ThisMonth, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `WHEN grouping history item with 31 days ago date THEN item is grouped to older`() {
|
|
|
|
|
val time = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 31)
|
|
|
|
|
val history = History.Regular(
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = System.currentTimeMillis() - (DateUtils.DAY_IN_MILLIS * 31)
|
|
|
|
|
visitedAt = time,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(time)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Older, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Older, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -183,11 +195,11 @@ class HistoryAdapterTest {
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = 0
|
|
|
|
|
visitedAt = 0,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(0)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Older, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Older, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -196,10 +208,10 @@ class HistoryAdapterTest {
|
|
|
|
|
position = 1,
|
|
|
|
|
title = "test item",
|
|
|
|
|
url = "url",
|
|
|
|
|
visitedAt = -100
|
|
|
|
|
visitedAt = -100,
|
|
|
|
|
historyTimeGroup = HistoryItemTimeGroup.timeGroupForTimestamp(-100)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val timeGroup = HistoryAdapter.timeGroupForHistoryItem(history as History)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Older, timeGroup)
|
|
|
|
|
assertEquals(HistoryItemTimeGroup.Older, history.historyTimeGroup)
|
|
|
|
|
}
|
|
|
|
|
}
|