@@ -4,17 +4,17 @@ import zio._
4
4
import zio .test .Assertion ._
5
5
import zio .test ._
6
6
7
- object CacheSpec extends DefaultRunnableSpec {
7
+ object CacheSpec extends ZIOSpecDefault {
8
8
9
9
def hash (x : Int ): Int => UIO [Int ] =
10
10
y => ZIO .succeed((x ^ y).hashCode)
11
11
12
- def spec : ZSpec [Environment , Failure ] = suite(" CacheSpec" )(
12
+ def spec : ZSpec [Environment , Any ] = suite(" CacheSpec" )(
13
13
test(" cacheStats" ) {
14
14
check(Gen .int) { salt =>
15
15
for {
16
16
cache <- Cache .make(100 , Duration .Infinity , Lookup (hash(salt)))
17
- _ <- ZIO .foreachPar_ ((1 to 100 ).map(_ / 2 ))(cache.get)
17
+ _ <- ZIO .foreachParDiscard ((1 to 100 ).map(_ / 2 ))(cache.get)
18
18
cacheStats <- cache.cacheStats
19
19
hits = cacheStats.hits
20
20
misses = cacheStats.misses
@@ -26,17 +26,17 @@ object CacheSpec extends DefaultRunnableSpec {
26
26
check(Gen .int) { salt =>
27
27
for {
28
28
cache <- Cache .make(100 , Duration .Infinity , Lookup (hash(salt)))
29
- _ <- ZIO .foreach_ (1 to 100 )(cache.get)
29
+ _ <- ZIO .foreachDiscard (1 to 100 )(cache.get)
30
30
_ <- cache.invalidate(42 )
31
31
contains <- cache.contains(42 )
32
32
} yield assert(contains)(isFalse)
33
33
}
34
34
},
35
- testM (" invalidateAll" ) {
36
- checkM (Gen .anyInt ) { salt =>
35
+ test (" invalidateAll" ) {
36
+ check (Gen .int ) { salt =>
37
37
for {
38
38
cache <- Cache .make(100 , Duration .Infinity , Lookup (hash(salt)))
39
- _ <- ZIO .foreach_ (1 to 100 )(cache.get)
39
+ _ <- ZIO .foreachDiscard (1 to 100 )(cache.get)
40
40
_ <- cache.invalidateAll
41
41
size <- cache.size
42
42
} yield assertTrue(size == 0 )
@@ -72,7 +72,7 @@ object CacheSpec extends DefaultRunnableSpec {
72
72
}
73
73
),
74
74
suite(" `refresh` method" )(
75
- testM (" should update the cache with a new value" ) {
75
+ test (" should update the cache with a new value" ) {
76
76
def inc (n : Int ) = n * 10
77
77
def retrieve (multiplier : Ref [Int ])(key : Int ) =
78
78
multiplier
@@ -90,7 +90,7 @@ object CacheSpec extends DefaultRunnableSpec {
90
90
val2 <- cache.get(key)
91
91
} yield assertTrue(val1 == inc(key)) && assertTrue(val2 == inc(val1))
92
92
},
93
- testM (" should update the cache with a new value even if the last `get` or `refresh` failed" ) {
93
+ test (" should update the cache with a new value even if the last `get` or `refresh` failed" ) {
94
94
95
95
val error = new RuntimeException (" Must be a multiple of 3" )
96
96
@@ -122,13 +122,13 @@ object CacheSpec extends DefaultRunnableSpec {
122
122
assert(val1)(isRight(equalTo(4 ))) &&
123
123
assert(val2)(isRight(equalTo(7 )))
124
124
},
125
- testM (" should get the value if the key doesn't exist in the cache" ) {
126
- checkM (Gen .anyInt ) { salt =>
125
+ test (" should get the value if the key doesn't exist in the cache" ) {
126
+ check (Gen .int ) { salt =>
127
127
val cap = 100
128
128
for {
129
129
cache <- Cache .make(cap, Duration .Infinity , Lookup (hash(salt)))
130
130
count0 <- cache.size
131
- _ <- ZIO .foreach_ (1 to cap)(cache.refresh)
131
+ _ <- ZIO .foreachDiscard (1 to cap)(cache.refresh)
132
132
count1 <- cache.size
133
133
} yield assertTrue(count0 == 0 ) && assertTrue(count1 == cap)
134
134
}
@@ -138,7 +138,7 @@ object CacheSpec extends DefaultRunnableSpec {
138
138
check(Gen .int) { salt =>
139
139
for {
140
140
cache <- Cache .make(10 , Duration .Infinity , Lookup (hash(salt)))
141
- _ <- ZIO .foreach_ (1 to 100 )(cache.get)
141
+ _ <- ZIO .foreachDiscard (1 to 100 )(cache.get)
142
142
size <- cache.size
143
143
} yield assertTrue(size == 10 )
144
144
}
0 commit comments