-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAvroCodeGenerationSpec.scala
More file actions
41 lines (30 loc) · 969 Bytes
/
Copy pathAvroCodeGenerationSpec.scala
File metadata and controls
41 lines (30 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.kafka.demo
package original
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
final class AvroCodeGenerationSpec extends AnyWordSpecLike with Matchers {
private[this] def getUsers(): List[User] = {
// Leave favorite color null
val user1 = new User()
user1.setName("Alyssa")
user1.setFavoriteNumber(256)
// Alternate constructor
val user2 = new User("Ben", 7, "red")
// Construct via builder
val user3 = User
.newBuilder()
.setName("Charlie")
.setFavoriteColor("blue")
.setFavoriteNumber(null)
.build()
List(user1, user2, user3)
}
"AvroCodeGeneration" should {
"serialize and deserialize" in {
val filePath = "avro/target/data/users-code-generation.avro"
val users = getUsers()
AvroCodeGeneration.serializeUsers(users, filePath)
AvroCodeGeneration.deserializeUsers(filePath) shouldBe users
}
}
}