Skip to content

Commit

Permalink
#23 TimeStampTest.kt 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
kimny927 committed Jan 20, 2025
1 parent 111d497 commit d29b5bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions data/src/test/java/ny/photomap/data/TimeStampTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ny.photomap.data

import ny.photomap.domain.TimeStamp
import org.junit.Before
import org.junit.Test

class TimeStampTest {

var timeStamp : TimeStamp? = null

@Before
fun setUp() {
timeStamp = TimeStampImpl()
}

@Test
fun `현재 시간 기능 테스트`() {
val startTime = System.currentTimeMillis()
val testResult = timeStamp?.currentTime
val endTime = System.currentTimeMillis()
assert(testResult != null && testResult in startTime..endTime)
}

@Test
fun `현재의 시점이 과거의 시점으로부터 기준 일수를 지나갔다는 테스트`() {
val time3DaysAgo = getTimeMillisTimeAfterDay(-3)
assert(timeStamp?.hasTimePassed(time3DaysAgo, 2) == true)
}

@Test
fun `현재의 시점이 과거의 시점으로부터 기준 일 수를 아직 지나가지 않았다는 테스트`() {
val time3DaysAgo = getTimeMillisTimeAfterDay(-3)
assert(timeStamp?.hasTimePassed(time3DaysAgo, 5) == false)
}

fun getTimeMillisTimeAfterDay(day: Int) : Long {
return System.currentTimeMillis() + (24 * 60 * 60 * 1000 * day)
}
}
5 changes: 5 additions & 0 deletions domain/src/main/java/ny/photomap/domain/TimeStamp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package ny.photomap.domain
interface TimeStamp {
val currentTime : Long

/**
* @param lastUpdateTime 과거 시간
* @param day 기준 일 수
* @return 현재 시간이 (과거 시간 + 기준 일 수)를 지나간 시점이면 true, 아직 현재 시간이 기준 일을 지나가지 못 했으면 false
*/
fun hasTimePassed(lastUpdateTime: Long, day : Int) : Boolean

}

0 comments on commit d29b5bb

Please sign in to comment.