File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
main/java/edu/ie3/datamodel/io/source/csv
test/groovy/edu/ie3/datamodel/io/source/csv Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,7 @@ protected <T extends UniqueEntity> Stream<T> filterEmptyOptionals(Stream<Optiona
329
329
*/
330
330
protected <T extends UniqueEntity > Optional <T > findFirstEntityByUuid (
331
331
String entityUuid , Collection <T > entities ) {
332
+ if (entities == null ) return Optional .empty ();
332
333
return entities .stream ()
333
334
.parallel ()
334
335
.filter (uniqueEntity -> uniqueEntity .getUuid ().toString ().equalsIgnoreCase (entityUuid ))
Original file line number Diff line number Diff line change @@ -66,6 +66,36 @@ class CsvDataSourceTest extends Specification {
66
66
67
67
DummyCsvSource dummyCsvSource = new DummyCsvSource (csvSep, testBaseFolderPath, fileNamingStrategy)
68
68
69
+ def " A csv data source returns empty optional, when looking for a specific uuid" () {
70
+ given :
71
+ def entities = null
72
+ def uuid = UUID . randomUUID(). toString()
73
+
74
+ when :
75
+ def actual = dummyCsvSource. findFirstEntityByUuid(uuid, entities)
76
+
77
+ then :
78
+ ! actual. present
79
+ }
80
+
81
+ def " A csv data source is able to find the correct first entity by uuid" () {
82
+ given :
83
+ def uuid = UUID . randomUUID()
84
+ def queriedOperator = new OperatorInput (uuid, " b" )
85
+ def entities = Arrays . asList(
86
+ new OperatorInput (UUID . randomUUID(), " a" ),
87
+ queriedOperator,
88
+ new OperatorInput (UUID . randomUUID(), " c" )
89
+ )
90
+
91
+ when :
92
+ def actual = dummyCsvSource. findFirstEntityByUuid(uuid. toString(), entities)
93
+
94
+ then :
95
+ actual. present
96
+ actual. get() == queriedOperator
97
+ }
98
+
69
99
def " A DataSource should contain a valid connector after initialization" () {
70
100
expect :
71
101
dummyCsvSource. connector != null
You can’t perform that action at this time.
0 commit comments