Skip to content

Commit d92b906

Browse files
committed
Refactor: less confusing name for SUT factory methods in tests
1 parent dc4e309 commit d92b906

File tree

14 files changed

+85
-80
lines changed

14 files changed

+85
-80
lines changed

carp.deployments.core/src/commonTest/kotlin/dk/cachet/carp/deployments/application/DeploymentServiceHostTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DeploymentServiceHostTest : DeploymentServiceTest
1515
{
1616
companion object
1717
{
18-
fun createService(): DeploymentServiceTest.DependentServices
18+
fun createSUT(): DeploymentServiceTest.SUT
1919
{
2020
val eventBus: EventBus = SingleThreadedEventBus()
2121

@@ -26,9 +26,9 @@ class DeploymentServiceHostTest : DeploymentServiceTest
2626
TestClock
2727
)
2828

29-
return DeploymentServiceTest.DependentServices( deploymentService, eventBus )
29+
return DeploymentServiceTest.SUT( deploymentService, eventBus )
3030
}
3131
}
3232

33-
override fun createService(): DeploymentServiceTest.DependentServices = DeploymentServiceHostTest.createService()
33+
override fun createSUT(): DeploymentServiceTest.SUT = DeploymentServiceHostTest.createSUT()
3434
}

carp.deployments.core/src/commonTest/kotlin/dk/cachet/carp/deployments/application/DeploymentServiceTest.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ private val unknownId: UUID = UUID.randomUUID()
2121
*/
2222
interface DeploymentServiceTest
2323
{
24-
data class DependentServices(
25-
val deploymentService: DeploymentService,
26-
val eventBus: EventBus
27-
)
24+
/**
25+
* System under test: the [deploymentService] and all dependencies to be used in tests.
26+
*/
27+
data class SUT( val deploymentService: DeploymentService, val eventBus: EventBus )
2828

2929
/**
30-
* Create a deployment service and dependent services to be used in tests.
30+
* Create the system under test (SUT): the [DeploymentService] and all dependencies to be used in tests.
3131
*/
32-
fun createService(): DependentServices
32+
fun createSUT(): SUT
3333

3434

3535
@Test
3636
fun createStudyDeployment_registers_preregistered_devices() = runTest {
37-
val (service, _) = createService()
37+
val (service, _) = createSUT()
3838
val (protocol, primaryDevice, connectedDevice) = createSinglePrimaryWithConnectedDeviceProtocol()
3939

4040
val deploymentId = UUID.randomUUID()
@@ -53,7 +53,7 @@ interface DeploymentServiceTest
5353

5454
@Test
5555
fun createStudyDeployment_fails_for_existing_id() = runTest {
56-
val (service, _) = createService()
56+
val (service, _) = createSUT()
5757
val studyDeploymentId = addTestDeployment( service, "Primary" )
5858

5959
val deviceRole = "Test device"
@@ -71,7 +71,7 @@ interface DeploymentServiceTest
7171

7272
@Test
7373
fun removeStudyDeployments_succeeds() = runTest {
74-
val (service, _) = createService()
74+
val (service, _) = createSUT()
7575
val deploymentId1 = addTestDeployment( service, "Test device" )
7676
val deploymentId2 = addTestDeployment( service, "Test device" )
7777
val deploymentIds = setOf( deploymentId1, deploymentId2 )
@@ -84,7 +84,7 @@ interface DeploymentServiceTest
8484

8585
@Test
8686
fun removeStudyDeployments_ignores_unknown_ids() = runTest {
87-
val (service, _) = createService()
87+
val (service, _) = createSUT()
8888
val deploymentId = addTestDeployment( service, "Test device" )
8989
val unknownId = UUID.randomUUID()
9090
val deploymentIds = setOf( deploymentId, unknownId )
@@ -95,7 +95,7 @@ interface DeploymentServiceTest
9595

9696
@Test
9797
fun getStudyDeploymentStatus_succeeds() = runTest {
98-
val (service, _) = createService()
98+
val (service, _) = createSUT()
9999
val studyDeploymentId = addTestDeployment( service, "Test device" )
100100

101101
// Actual testing of the status responses should already be covered adequately in StudyDeployment tests.
@@ -104,14 +104,14 @@ interface DeploymentServiceTest
104104

105105
@Test
106106
fun getStudyDeploymentStatus_fails_for_unknown_studyDeploymentId() = runTest {
107-
val (service, _) = createService()
107+
val (service, _) = createSUT()
108108

109109
assertFailsWith<IllegalArgumentException> { service.getStudyDeploymentStatus( unknownId ) }
110110
}
111111

112112
@Test
113113
fun getStudyDeploymentStatusList_succeeds() = runTest {
114-
val (service, _) = createService()
114+
val (service, _) = createSUT()
115115
val deviceRoleName = "Primary"
116116
val (protocol, _, _) = createSinglePrimaryWithConnectedDeviceProtocol( deviceRoleName )
117117
val protocolSnapshot = protocol.getSnapshot()
@@ -129,7 +129,7 @@ interface DeploymentServiceTest
129129

130130
@Test
131131
fun getStudyDeploymentStatusList_fails_when_containing_an_unknown_studyDeploymentId() = runTest {
132-
val (service, _) = createService()
132+
val (service, _) = createSUT()
133133
val studyDeploymentId = addTestDeployment( service, "Test device" )
134134

135135
val deploymentIds = setOf( studyDeploymentId, unknownId )
@@ -138,7 +138,7 @@ interface DeploymentServiceTest
138138

139139
@Test
140140
fun registerDevice_can_be_called_multiple_times() = runTest {
141-
val (service, _) = createService()
141+
val (service, _) = createSUT()
142142
val studyDeploymentId = addTestDeployment( service, "Primary" )
143143
val status = service.getStudyDeploymentStatus( studyDeploymentId )
144144
val primary = status.getRemainingDevicesToRegister().first { it.roleName == "Primary" }
@@ -151,7 +151,7 @@ interface DeploymentServiceTest
151151

152152
@Test
153153
fun registerDevice_cannot_be_called_with_same_registration_when_stopped() = runTest {
154-
val (service, _) = createService()
154+
val (service, _) = createSUT()
155155
val studyDeploymentId = addTestDeployment( service, "Primary" )
156156
val status = service.getStudyDeploymentStatus( studyDeploymentId )
157157
val primary = status.getRemainingDevicesToRegister().first { it.roleName == "Primary" }
@@ -167,7 +167,7 @@ interface DeploymentServiceTest
167167

168168
@Test
169169
fun unregisterDevice_succeeds() = runTest {
170-
val (service, _) = createService()
170+
val (service, _) = createSUT()
171171
val deviceRolename = "Test device"
172172
val studyDeploymentId = addTestDeployment( service, deviceRolename )
173173
var status = service.getStudyDeploymentStatus( studyDeploymentId )
@@ -180,7 +180,7 @@ interface DeploymentServiceTest
180180

181181
@Test
182182
fun getDeviceDeploymentFor_during_device_reregistrations() = runTest {
183-
val (service, _) = createService()
183+
val (service, _) = createSUT()
184184
val protocol = createSinglePrimaryDeviceProtocol( "Test device" )
185185
val device = protocol.primaryDevices.first()
186186
val deploymentId = UUID.randomUUID()
@@ -202,7 +202,7 @@ interface DeploymentServiceTest
202202

203203
@Test
204204
fun stop_succeeds() = runTest {
205-
val (service, _) = createService()
205+
val (service, _) = createSUT()
206206
val studyDeploymentId = addTestDeployment( service, "Test device" )
207207

208208
val status = service.stop( studyDeploymentId )
@@ -211,14 +211,14 @@ interface DeploymentServiceTest
211211

212212
@Test
213213
fun stop_fails_for_unknown_studyDeploymentId() = runTest {
214-
val (service, _) = createService()
214+
val (service, _) = createSUT()
215215

216216
assertFailsWith<IllegalArgumentException> { service.stop( unknownId ) }
217217
}
218218

219219
@Test
220220
fun modifications_after_stop_not_allowed() = runTest {
221-
val (service, _) = createService()
221+
val (service, _) = createSUT()
222222
val studyDeploymentId = addTestDeployment( service, "Primary", "Connected" )
223223
val status = service.getStudyDeploymentStatus( studyDeploymentId )
224224
val primary = status.getRemainingDevicesToRegister().first { it.roleName == "Primary" }

carp.deployments.core/src/commonTest/kotlin/dk/cachet/carp/deployments/application/ParticipationServiceHostTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ParticipationServiceHostTest : ParticipationServiceTest
1919
{
2020
companion object
2121
{
22-
fun createService(): ParticipationServiceTest.DependentServices
22+
fun createSUT(): ParticipationServiceTest.SUT
2323
{
2424
val eventBus: EventBus = SingleThreadedEventBus()
2525

@@ -38,7 +38,7 @@ class ParticipationServiceHostTest : ParticipationServiceTest
3838
eventBus.createApplicationServiceAdapter( ParticipationService::class )
3939
)
4040

41-
return ParticipationServiceTest.DependentServices(
41+
return ParticipationServiceTest.SUT(
4242
participationService,
4343
deploymentService,
4444
accountService,
@@ -47,6 +47,5 @@ class ParticipationServiceHostTest : ParticipationServiceTest
4747
}
4848
}
4949

50-
override fun createService(): ParticipationServiceTest.DependentServices =
51-
ParticipationServiceHostTest.createService()
50+
override fun createSUT(): ParticipationServiceTest.SUT = ParticipationServiceHostTest.createSUT()
5251
}

carp.deployments.core/src/commonTest/kotlin/dk/cachet/carp/deployments/application/ParticipationServiceTest.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,25 @@ interface ParticipationServiceTest
3535
}
3636

3737

38-
data class DependentServices(
38+
/**
39+
* System under test: the [participationService] and all dependencies to be used in tests.
40+
*/
41+
data class SUT(
3942
val participationService: ParticipationService,
4043
val deploymentService: DeploymentService,
4144
val accountService: AccountService,
4245
val eventBus: EventBus
4346
)
4447

4548
/**
46-
* Create a deployment service and account service it depends on to be used in the tests.
49+
* Create the system under test (SUT): the [ParticipationService] and all dependencies to be used in tests.
4750
*/
48-
fun createService(): DependentServices
51+
fun createSUT(): SUT
4952

5053

5154
@Test
5255
fun getActiveParticipationInvitations_succeeds() = runTest {
53-
val (participationService, deploymentService, accountService) = createService()
56+
val (participationService, deploymentService, accountService) = createSUT()
5457
val protocol = createSinglePrimaryDeviceProtocol()
5558
val identity = AccountIdentity.fromEmailAddress( "[email protected]" )
5659
val invitation = StudyInvitation( "Test study", "description", "Custom data" )
@@ -75,7 +78,7 @@ interface ParticipationServiceTest
7578

7679
@Test
7780
fun getParticipantData_initially_returns_null_for_all_expected_data() = runTest {
78-
val (participationService, deploymentService, _) = createService()
81+
val (participationService, deploymentService, _) = createSUT()
7982

8083
// Create protocol with one common custom attribute and 'sex' assigned to two participant roles.
8184
val protocol = createSinglePrimaryDeviceProtocol( deviceRoleName )
@@ -109,14 +112,14 @@ interface ParticipationServiceTest
109112

110113
@Test
111114
fun getParticipantData_fails_for_unknown_deploymentId() = runTest {
112-
val (participationService, _, _) = createService()
115+
val (participationService, _, _) = createSUT()
113116

114117
assertFailsWith<IllegalArgumentException> { participationService.getParticipantData( unknownId ) }
115118
}
116119

117120
@Test
118121
fun getParticipantDataList_succeeds() = runTest {
119-
val (participationService, deploymentService, _) = createService()
122+
val (participationService, deploymentService, _) = createSUT()
120123
val protocol = createSinglePrimaryDeviceProtocol( deviceRoleName )
121124
val protocolSnapshot = protocol.getSnapshot()
122125
val invitation1 = createParticipantInvitation()
@@ -133,15 +136,15 @@ interface ParticipationServiceTest
133136

134137
@Test
135138
fun getParticipantDataList_fails_for_unknown_deploymentId() = runTest {
136-
val (participationService, _, _) = createService()
139+
val (participationService, _, _) = createSUT()
137140

138141
val deploymentIds = setOf( unknownId )
139142
assertFailsWith<IllegalArgumentException> { participationService.getParticipantDataList( deploymentIds ) }
140143
}
141144

142145
@Test
143146
fun setParticipantData_assigned_to_all_roles_succeeds() = runTest {
144-
val (participationService, deploymentService, _) = createService()
147+
val (participationService, deploymentService, _) = createSUT()
145148

146149
// Create protocol without roles with expected 'sex' participant data.
147150
val protocol = createSinglePrimaryDeviceProtocol( deviceRoleName )
@@ -163,7 +166,7 @@ interface ParticipationServiceTest
163166

164167
@Test
165168
fun setParticipantData_assigned_to_role_succeeds() = runTest {
166-
val (participationService, deploymentService, _) = createService()
169+
val (participationService, deploymentService, _) = createSUT()
167170

168171
// Create protocol with expected 'sex' participant data for a single participant role.
169172
val protocol = createSinglePrimaryDeviceProtocol( deviceRoleName )
@@ -191,7 +194,7 @@ interface ParticipationServiceTest
191194

192195
@Test
193196
fun setParticipantData_fails_for_unknown_deploymentId() = runTest {
194-
val (participationService, _, _) = createService()
197+
val (participationService, _, _) = createSUT()
195198

196199
val toSet = mapOf( CarpInputDataTypes.SEX to Sex.Male )
197200
assertFailsWith<IllegalArgumentException>
@@ -202,7 +205,7 @@ interface ParticipationServiceTest
202205

203206
@Test
204207
fun setParticipantData_fails_for_unexpected_input_for_protocol() = runTest {
205-
val (participationService, deploymentService, _) = createService()
208+
val (participationService, deploymentService, _) = createSUT()
206209
val studyDeploymentId = addTestDeployment( deploymentService )
207210

208211
val toSet = mapOf( CarpInputDataTypes.SEX to Sex.Male )
@@ -214,7 +217,7 @@ interface ParticipationServiceTest
214217

215218
@Test
216219
fun setParticipantData_fails_for_invalid_data() = runTest {
217-
val (participationService, deploymentService, _) = createService()
220+
val (participationService, deploymentService, _) = createSUT()
218221

219222
// Create protocol with expected 'sex' participant data.
220223
val protocol = createSinglePrimaryDeviceProtocol( deviceRoleName )

carp.deployments.core/src/commonTest/kotlin/dk/cachet/carp/deployments/infrastructure/DeploymentServiceRequestsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ class DeploymentServiceRequestsTest : ApplicationServiceRequestsTest<DeploymentS
3636

3737
override fun createServiceLoggingProxy(): ApplicationServiceLoggingProxy<DeploymentService, DeploymentService.Event> =
3838
DeploymentServiceHostTest
39-
.createService()
39+
.createSUT()
4040
.let { DeploymentServiceLoggingProxy( it.deploymentService, it.eventBus ) }
4141
}

carp.deployments.core/src/commonTest/kotlin/dk/cachet/carp/deployments/infrastructure/ParticipationServiceRequestsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ class ParticipationServiceRequestsTest : ApplicationServiceRequestsTest<Particip
3333

3434
override fun createServiceLoggingProxy(): ApplicationServiceLoggingProxy<ParticipationService, ParticipationService.Event> =
3535
ParticipationServiceHostTest
36-
.createService()
36+
.createSUT()
3737
.let { ParticipationServiceLoggingProxy( it.participationService, it.eventBus ) }
3838
}

carp.deployments.core/src/jvmTest/kotlin/dk/cachet/carp/deployments/infrastructure/versioning/BackwardsCompatibilityTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlinx.serialization.ExperimentalSerializationApi
1212
class DeploymentServiceBackwardsCompatibilityTest :
1313
BackwardsCompatibilityTest<DeploymentService>( DeploymentService::class )
1414
{
15-
override fun createService() = DeploymentServiceHostTest.createService()
15+
override fun createService() = DeploymentServiceHostTest.createSUT()
1616
.let { Pair( it.deploymentService, it.eventBus ) }
1717
}
1818

@@ -21,6 +21,6 @@ class DeploymentServiceBackwardsCompatibilityTest :
2121
class ParticipationServiceBackwardsCompatibilityTest :
2222
BackwardsCompatibilityTest<ParticipationService>( ParticipationService::class )
2323
{
24-
override fun createService() = ParticipationServiceHostTest.createService()
24+
override fun createService() = ParticipationServiceHostTest.createSUT()
2525
.let { Pair( it.participationService, it.eventBus ) }
2626
}

carp.deployments.core/src/jvmTest/kotlin/dk/cachet/carp/deployments/infrastructure/versioning/OutputDeploymentServiceTestRequests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class OutputDeploymentServiceTestRequests :
1111
OutputTestRequests<DeploymentService>( DeploymentService::class ),
1212
DeploymentServiceTest
1313
{
14-
override fun createService(): DeploymentServiceTest.DependentServices
14+
override fun createSUT(): DeploymentServiceTest.SUT
1515
{
16-
val services = DeploymentServiceHostTest.createService()
16+
val services = DeploymentServiceHostTest.createSUT()
1717
val service = DeploymentServiceLoggingProxy( services.deploymentService, services.eventBus )
1818
loggedService = service
1919

20-
return DeploymentServiceTest.DependentServices( service, services.eventBus )
20+
return DeploymentServiceTest.SUT( service, services.eventBus )
2121
}
2222
}

carp.deployments.core/src/jvmTest/kotlin/dk/cachet/carp/deployments/infrastructure/versioning/OutputParticipationServiceTestRequests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class OutputParticipationServiceTestRequests :
1111
OutputTestRequests<ParticipationService>( ParticipationService::class ),
1212
ParticipationServiceTest
1313
{
14-
override fun createService(): ParticipationServiceTest.DependentServices
14+
override fun createSUT(): ParticipationServiceTest.SUT
1515
{
16-
val services = ParticipationServiceHostTest.createService()
16+
val services = ParticipationServiceHostTest.createSUT()
1717
val service = ParticipationServiceLoggingProxy( services.participationService, services.eventBus )
1818
loggedService = service
1919

20-
return ParticipationServiceTest.DependentServices(
20+
return ParticipationServiceTest.SUT(
2121
service,
2222
services.deploymentService,
2323
services.accountService,

carp.studies.core/src/commonTest/kotlin/dk/cachet/carp/studies/application/RecruitmentServiceHostTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RecruitmentServiceHostTest : RecruitmentServiceTest
1919
{
2020
companion object
2121
{
22-
fun createService(): RecruitmentServiceTest.DependentServices
22+
fun createSUT(): RecruitmentServiceTest.SUT
2323
{
2424
val eventBus = SingleThreadedEventBus()
2525

@@ -48,9 +48,9 @@ class RecruitmentServiceHostTest : RecruitmentServiceTest
4848
TestClock
4949
)
5050

51-
return RecruitmentServiceTest.DependentServices( recruitmentService, studyService, eventBus )
51+
return RecruitmentServiceTest.SUT( recruitmentService, studyService, eventBus )
5252
}
5353
}
5454

55-
override fun createService(): RecruitmentServiceTest.DependentServices = RecruitmentServiceHostTest.createService()
55+
override fun createSUT(): RecruitmentServiceTest.SUT = RecruitmentServiceHostTest.createSUT()
5656
}

0 commit comments

Comments
 (0)