@@ -16,33 +16,25 @@ import kotlin.test.assertTrue
16
16
class TimeZoneNativeTest {
17
17
18
18
@Test
19
- fun correctSymlinkTest () {
20
- root = " ${RESOURCES } correct-symlink/"
21
-
19
+ fun correctSymlinkTest () = withFakeRoot(" ${RESOURCES } correct-symlink/" ) {
22
20
val tz = TimeZone .currentSystemDefault()
23
21
assertEquals(TimeZone .of(" Europe/Oslo" ), tz)
24
22
}
25
23
26
24
@Test
27
- fun correctLocaltimeCopyTest () {
28
- root = " ${RESOURCES } correct-localtime-copy/"
29
-
25
+ fun correctLocaltimeCopyTest () = withFakeRoot(" ${RESOURCES } correct-localtime-copy/" ) {
30
26
val tz = TimeZone .currentSystemDefault()
31
27
assertEquals(TimeZone .of(" Europe/Oslo" ), tz)
32
28
}
33
29
34
30
@Test
35
- fun fallsBackToUTC () {
36
- root = " ${RESOURCES } missing-localtime/"
37
-
31
+ fun fallsBackToUTC () = withFakeRoot(" ${RESOURCES } falls-back-to-utc/" ) {
38
32
val tz = TimeZone .currentSystemDefault()
39
33
assertEquals(TimeZone .UTC , tz)
40
34
}
41
35
42
36
@Test
43
- fun missingTimezoneTest () {
44
- root = " ${RESOURCES } missing-timezone/"
45
-
37
+ fun missingTimezoneTest () = withFakeRoot(" ${RESOURCES } missing-timezone/" ) {
46
38
val exception = assertFailsWith<IllegalTimeZoneException > {
47
39
TimeZone .currentSystemDefault()
48
40
}
@@ -54,9 +46,7 @@ class TimeZoneNativeTest {
54
46
}
55
47
56
48
@Test
57
- fun incorrectTimezoneTest () {
58
- root = " ${RESOURCES } incorrect-timezone/"
59
-
49
+ fun incorrectTimezoneTest () = withFakeRoot(" ${RESOURCES } incorrect-timezone/" ) {
60
50
val exception = assertFailsWith<IllegalTimeZoneException > {
61
51
TimeZone .currentSystemDefault()
62
52
}
@@ -68,9 +58,7 @@ class TimeZoneNativeTest {
68
58
}
69
59
70
60
@Test
71
- fun differentTimezonesTest () {
72
- root = " ${RESOURCES } different-timezones/"
73
-
61
+ fun differentTimezonesTest () = withFakeRoot(" ${RESOURCES } different-timezones/" ) {
74
62
val exception = assertFailsWith<IllegalTimeZoneException > {
75
63
TimeZone .currentSystemDefault()
76
64
}
@@ -83,5 +71,15 @@ class TimeZoneNativeTest {
83
71
84
72
companion object {
85
73
const val RESOURCES = " ./linux/test/time-zone-native-test-resources/"
74
+
75
+ private fun withFakeRoot (fakeRoot : String , action : () -> Unit ) {
76
+ val defaultRoot = root
77
+ root = fakeRoot
78
+ try {
79
+ action()
80
+ } finally {
81
+ root = defaultRoot
82
+ }
83
+ }
86
84
}
87
85
}
0 commit comments