generated from SmartOperatingBlock/kotlin-template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for application services
- Loading branch information
1 parent
e4b8f7b
commit 4a6e62e
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/application/service/TestApplicationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2023. Smart Operating Block | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package application.service | ||
|
||
import application.controller.UserController | ||
import application.service.mock.MockDBManager | ||
import entity.user.User | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.shouldNotBe | ||
|
||
class TestApplicationService : StringSpec({ | ||
|
||
var userController = UserController(MockDBManager()) | ||
val mockUser = User("00000001", "User1999!") | ||
|
||
beforeEach { | ||
userController = UserController(MockDBManager()) | ||
} | ||
|
||
"The application service should be able to create a User!" { | ||
userController.createUser(mockUser).also { | ||
it shouldNotBe null | ||
userController.getUser(mockUser.userId) shouldBe mockUser | ||
} | ||
} | ||
|
||
"The application service should be able to get a User!" { | ||
userController.createUser(mockUser) | ||
userController.getUser(mockUser.userId).also { | ||
it shouldNotBe null | ||
it shouldBe mockUser | ||
} | ||
} | ||
|
||
"The application service should be able to delete a User!" { | ||
userController.createUser(mockUser) | ||
userController.deleteUser(mockUser.userId).also { | ||
it shouldBe true | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2023. Smart Operating Block | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package application.service.mock | ||
|
||
import application.controller.manager.HealthProfessionalDatabaseManager | ||
import application.controller.manager.UserDatabaseManager | ||
import entity.healthprofessional.HealthProfessionalData.HealthProfessional | ||
import entity.user.User | ||
|
||
class MockDBManager : UserDatabaseManager, HealthProfessionalDatabaseManager { | ||
|
||
private val users = mutableSetOf<User>() | ||
private val healthProfessionals = mutableSetOf<HealthProfessional>() | ||
|
||
override fun createHealthProfessional(healthProfessional: HealthProfessional): HealthProfessional? { | ||
healthProfessionals.add(healthProfessional) | ||
return getHealthProfessional(healthProfessional.healthProfessionalId) | ||
} | ||
|
||
override fun deleteHealthProfessional(healthProfessionalId: String): Boolean = | ||
healthProfessionals.removeIf { it.healthProfessionalId == healthProfessionalId } | ||
|
||
override fun getHealthProfessional(healthProfessionalId: String): HealthProfessional? = | ||
healthProfessionals.find { it.healthProfessionalId == healthProfessionalId } | ||
|
||
override fun createUser(user: User): User? { | ||
users.add(user) | ||
return getUser(user.userId) | ||
} | ||
|
||
override fun deleteUser(userId: String): Boolean = | ||
users.removeIf { it.userId == userId } | ||
|
||
override fun getUser(userId: String): User? = | ||
users.find { it.userId == userId } | ||
} |