File tree Expand file tree Collapse file tree 3 files changed +12
-10
lines changed
main/java/travelator/marketing
test/java/travelator/marketing Expand file tree Collapse file tree 3 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import kotlin.system.exitProcess
7
7
fun main () {
8
8
System .`in `.reader().use { reader ->
9
9
System .out .writer().use { writer ->
10
- val errorLines = mutableListOf<String >()
10
+ val errorLines = mutableListOf<ParseFailure >()
11
11
val reportLines = reader
12
12
.asLineSequence()
13
13
.toHighValueCustomerReport {
@@ -16,7 +16,9 @@ fun main() {
16
16
if (errorLines.isNotEmpty()) {
17
17
System .err.writer().use { error ->
18
18
error.appendLine(" Lines with errors" )
19
- errorLines.asSequence().writeTo(error)
19
+ errorLines.asSequence().map { parseFailure ->
20
+ " ${parseFailure::class .simpleName} in ${parseFailure.line} "
21
+ }.writeTo(error)
20
22
}
21
23
exitProcess(- 1 )
22
24
} else {
Original file line number Diff line number Diff line change @@ -6,13 +6,13 @@ import com.natpryce.Success
6
6
import com.natpryce.recover
7
7
8
8
fun Sequence<String>.toHighValueCustomerReport (
9
- onErrorLine : (String ) -> Unit = {}
9
+ onErrorLine : (ParseFailure ) -> Unit = {}
10
10
): Sequence <String > {
11
11
val valuableCustomers = this
12
12
.withoutHeader()
13
13
.map { line ->
14
14
line.toCustomerData().recover {
15
- onErrorLine(line )
15
+ onErrorLine(it )
16
16
null
17
17
}
18
18
}
Original file line number Diff line number Diff line change @@ -54,14 +54,18 @@ class HighValueCustomersReportTests {
54
54
" 1\t Fred\t Flintstone\t 11\t 1000.00" ,
55
55
)
56
56
57
- val errorCollector = mutableListOf<String >()
57
+ val errorCollector = mutableListOf<ParseFailure >()
58
58
val result = lines
59
59
.asSequence()
60
60
.constrainOnce()
61
- .toHighValueCustomerReport { badLine -> // <1>
61
+ .toHighValueCustomerReport { badLine ->
62
62
errorCollector + = badLine
63
63
}
64
64
.toList()
65
+ assertEquals(
66
+ listOf (NotEnoughFieldsFailure (" INVALID LINE" )),
67
+ errorCollector
68
+ )
65
69
66
70
assertEquals(
67
71
listOf (
@@ -71,10 +75,6 @@ class HighValueCustomersReportTests {
71
75
),
72
76
result
73
77
)
74
- assertEquals(
75
- listOf (" INVALID LINE" ),
76
- errorCollector
77
- )
78
78
}
79
79
80
80
You can’t perform that action at this time.
0 commit comments