Skip to content

Commit 1e5923e

Browse files
authored
Added more tests (#8)
1 parent 3eee64c commit 1e5923e

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package ton.sdk.client.binding
2+
3+
import org.scalatest.flatspec.AsyncFlatSpec
4+
import org.scalatest.matchers.should.Matchers._
5+
import ton.sdk.client.binding.Context._
6+
import ton.sdk.client.jni.Binding
7+
import ton.sdk.client.modules.Client
8+
9+
import scala.concurrent.duration.DurationInt
10+
import scala.concurrent.{Await, ExecutionContext, Future}
11+
import scala.util.Try
12+
13+
class ContextSpec extends AsyncFlatSpec {
14+
15+
"Context" should "throw an exception if library is not loaded" in {
16+
try {
17+
implicit val effect: Context.Effect[Try] = Context.tryEffect
18+
Context(1).request(Client.Request.BuildInfo)
19+
fail("Should throw an exception")
20+
} catch {
21+
case _: UnsatisfiedLinkError => succeed
22+
}
23+
}
24+
25+
"Sync Context" should "not allow usage if not open" in {
26+
implicit val effect: Context.Effect[Try] = Context.tryEffect
27+
Binding.loadNativeLibrary()
28+
val c = Context.create(ClientConfig.MAIN_NET).get
29+
val result1 = c.request(Client.Request.BuildInfo)
30+
c.close()
31+
val result2 = c.request(Client.Request.BuildInfo)
32+
result1.isSuccess shouldEqual true
33+
result2.isSuccess shouldEqual false
34+
}
35+
36+
"Async Context" should "not allow usage if not open" in {
37+
implicit def executionContext: ExecutionContext = ExecutionContext.Implicits.global
38+
implicit val ef: Effect[Future] = futureEffect
39+
40+
val c = Context.create(ClientConfig.TEST_NET).get
41+
val result1 = c.request(Client.Request.BuildInfo)
42+
Await.ready(result1, 10.seconds)
43+
c.close()
44+
val result2 = c.request(Client.Request.BuildInfo)
45+
Await.ready(result2, 10.seconds)
46+
result1.value.get.isSuccess shouldEqual true
47+
result2.value.get.isSuccess shouldEqual false
48+
}
49+
}

src/test/scala/ton/sdk/client/binding/QueueBackedIteratorTest.scala renamed to src/test/scala/ton/sdk/client/binding/QueueBackedIteratorSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.scalatest.matchers.should.Matchers._
66
import scala.concurrent.Promise
77
import scala.concurrent.duration.DurationInt
88

9-
class QueueBackedIteratorTest extends AsyncFlatSpec {
9+
class QueueBackedIteratorSpec extends AsyncFlatSpec {
1010

1111
private val flag = Promise[Unit]()
1212
private val bit = new QueueBackedIterator[Int](flag)

0 commit comments

Comments
 (0)