You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1287,4 +1288,197 @@ class SuccessOrSingleErrorTest {
1287
1288
1288
1289
assertEquals(initialValue, result)
1289
1290
}
1291
+
1292
+
@Test
1293
+
fun`flat map success with possible error as mapper result must return possible error with initial error if success or single error was initiated as error and mapper result is error`() {
1294
+
val initialError =Exception(Uuid.random().toString())
1295
+
val newError =Exception(Uuid.random().toString())
1296
+
var evaluated =false
1297
+
val result =
1298
+
SuccessOrSingleError
1299
+
.Error
1300
+
.of<String, _>(initialError)
1301
+
.flatMapSuccessToPossibleError {
1302
+
evaluated =true
1303
+
PossibleError.Error.of(newError)
1304
+
}
1305
+
.toMaybeError()
1306
+
.orNull()!!
1307
+
1308
+
assertSoftly {
1309
+
assertFalse { evaluated }
1310
+
assertEquals(initialError, result)
1311
+
}
1312
+
}
1313
+
1314
+
@Test
1315
+
fun`flat map success with possible error as mapper result must return possible error with initial error if success or single error was initiated as error and mapper result is success`() {
1316
+
val initialError =Exception(Uuid.random().toString())
1317
+
var evaluated =false
1318
+
val result =
1319
+
SuccessOrSingleError
1320
+
.Error
1321
+
.of<String, _>(initialError)
1322
+
.flatMapSuccessToPossibleError {
1323
+
evaluated =true
1324
+
PossibleError.Success.of()
1325
+
}
1326
+
.toMaybeError()
1327
+
.orNull()!!
1328
+
1329
+
assertSoftly {
1330
+
assertFalse { evaluated }
1331
+
assertEquals(initialError, result)
1332
+
}
1333
+
}
1334
+
1335
+
@Test
1336
+
fun`flat map success with possible error as mapper result must return possible error with mapper error if success or single error was initiated as success and mapper result is error`() {
1337
+
val initialValue =Uuid.random().toString()
1338
+
val error =Exception(Uuid.random().toString())
1339
+
var evaluated =false
1340
+
val result =
1341
+
SuccessOrSingleError
1342
+
.Success
1343
+
.of<_, Throwable>(initialValue)
1344
+
.flatMapSuccessToPossibleError {
1345
+
evaluated =true
1346
+
PossibleError.Error.of(error)
1347
+
}
1348
+
.toMaybeError()
1349
+
.orNull()!!
1350
+
1351
+
assertSoftly {
1352
+
assertTrue { evaluated }
1353
+
assertEquals(error, result)
1354
+
}
1355
+
}
1356
+
1357
+
@Test
1358
+
fun`flat map success with possible error as mapper result must return possible error success if success or single error was initiated as success and mapper result is success`() {
1359
+
val initialValue =Uuid.random().toString()
1360
+
var evaluated =false
1361
+
val result =
1362
+
SuccessOrSingleError
1363
+
.Success
1364
+
.of<_, Throwable>(initialValue)
1365
+
.flatMapSuccessToPossibleError {
1366
+
evaluated =true
1367
+
PossibleError.Success.of()
1368
+
}
1369
+
.error()
1370
+
1371
+
assertSoftly {
1372
+
assertTrue { evaluated }
1373
+
assertFalse { result }
1374
+
}
1375
+
}
1376
+
1377
+
@Test
1378
+
fun`flat map success with maybe error as mapper result must return maybe with initial error if success or single error was initiated as error and mapper result is not empty`() {
1379
+
val initialError =Exception(Uuid.random().toString())
1380
+
val newError =Exception(Uuid.random().toString())
1381
+
var evaluated =false
1382
+
val result =
1383
+
SuccessOrSingleError
1384
+
.Error
1385
+
.of<String, _>(initialError)
1386
+
.flatMapSuccessToMaybe {
1387
+
evaluated =true
1388
+
Maybe.NotEmpty.of(newError)
1389
+
}
1390
+
.orNull()!!
1391
+
1392
+
assertSoftly {
1393
+
assertFalse { evaluated }
1394
+
assertEquals(initialError, result)
1395
+
}
1396
+
}
1397
+
1398
+
@Test
1399
+
fun`flat map success with maybe error as mapper result must return maybe with initial error if success or single error was initiated as error and mapper result is empty`() {
1400
+
val initialError =Exception(Uuid.random().toString())
1401
+
var evaluated =false
1402
+
val result =
1403
+
SuccessOrSingleError
1404
+
.Error
1405
+
.of<String, _>(initialError)
1406
+
.flatMapSuccessToMaybe {
1407
+
evaluated =true
1408
+
Maybe.Empty.of()
1409
+
}
1410
+
.orNull()!!
1411
+
1412
+
assertSoftly {
1413
+
assertFalse { evaluated }
1414
+
assertEquals(initialError, result)
1415
+
}
1416
+
}
1417
+
1418
+
@Test
1419
+
fun`flat map success with maybe error as mapper result must return maybe with mapper error if success or single error was initiated as success and mapper result is not empty`() {
1420
+
val initialValue =Uuid.random().toString()
1421
+
val error =Exception(Uuid.random().toString())
1422
+
var evaluated =false
1423
+
val result =
1424
+
SuccessOrSingleError
1425
+
.Success
1426
+
.of<_, Throwable>(initialValue)
1427
+
.flatMapSuccessToMaybe {
1428
+
evaluated =true
1429
+
Maybe.NotEmpty.of(error)
1430
+
}
1431
+
.orNull()!!
1432
+
1433
+
assertSoftly {
1434
+
assertTrue { evaluated }
1435
+
assertEquals(error, result)
1436
+
}
1437
+
}
1438
+
1439
+
@Test
1440
+
fun`flat map success with maybe error as mapper result must return empty maybe if success or single error was initiated as success and mapper result is empty`() {
1441
+
val initialValue =Uuid.random().toString()
1442
+
var evaluated =false
1443
+
val result =
1444
+
SuccessOrSingleError
1445
+
.Success
1446
+
.of<_, Throwable>(initialValue)
1447
+
.flatMapSuccessToMaybe {
1448
+
evaluated =true
1449
+
Maybe.Empty.of()
1450
+
}
1451
+
.empty()
1452
+
1453
+
assertSoftly {
1454
+
assertTrue { evaluated }
1455
+
assertTrue { result }
1456
+
}
1457
+
}
1458
+
1459
+
@Test
1460
+
fun`as possible error must return success possible error if initial success or single error is success`() {
1461
+
val result =
1462
+
SuccessOrSingleError
1463
+
.Success
1464
+
.of<_, Throwable>(Uuid.random().toString())
1465
+
.asPossibleError()
1466
+
.error()
1467
+
1468
+
assertFalse { result }
1469
+
}
1470
+
1471
+
@Test
1472
+
fun`as possible error must return error possible error if initial success or single error is error`() {
1473
+
val initialError =Exception(Uuid.random().toString())
0 commit comments