File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
main/java/org/springframework/data/repository/util
test/java/org/springframework/data/repository/util Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2014-2015 the original author or authors.
2
+ * Copyright 2014-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .springframework .data .repository .util ;
17
17
18
+ import scala .Function0 ;
18
19
import scala .Option ;
20
+ import scala .runtime .AbstractFunction0 ;
19
21
20
22
import java .util .Collections ;
21
23
import java .util .HashSet ;
48
50
* </ul>
49
51
*
50
52
* @author Oliver Gierke
53
+ * @author Mark Paluch
51
54
* @since 1.8
52
55
*/
53
56
public abstract class QueryExecutionConverters {
@@ -416,19 +419,32 @@ public Object convert(Object source) {
416
419
* A {@link Converter} to unwrap a Scala {@link Option} instance.
417
420
*
418
421
* @author Oliver Gierke
422
+ * @author Mark Paluch
419
423
* @author 1.13
420
424
*/
421
425
private static enum ScalOptionUnwrapper implements Converter <Object , Object > {
422
426
423
427
INSTANCE ;
424
428
425
- /*
429
+ private final Function0 <Object > alternative = new AbstractFunction0 <Object >() {
430
+
431
+ /*
432
+ * (non-Javadoc)
433
+ * @see scala.Function0#apply()
434
+ */
435
+ @ Override
436
+ public Option <Object > apply () {
437
+ return null ;
438
+ }
439
+ };
440
+
441
+ /*
426
442
* (non-Javadoc)
427
443
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
428
444
*/
429
445
@ Override
430
446
public Object convert (Object source ) {
431
- return source instanceof Option ? ((Option <?>) source ).orNull ( null ) : source ;
447
+ return source instanceof Option ? ((Option <?>) source ).getOrElse ( alternative ) : source ;
432
448
}
433
449
}
434
450
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2014-2015 the original author or authors.
2
+ * Copyright 2014-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
37
37
* Unit tests for {@link QueryExecutionConverters}.
38
38
*
39
39
* @author Oliver Gierke
40
+ * @author Mark Paluch
40
41
*/
41
42
public class QueryExecutionConvertersUnitTests {
42
43
@@ -163,4 +164,12 @@ public void turnsNullIntoScalaOptionEmpty() {
163
164
public void unwrapsScalaOption () {
164
165
assertThat (QueryExecutionConverters .unwrap (Option .apply ("foo" )), is ((Object ) "foo" ));
165
166
}
167
+
168
+ /**
169
+ * @see DATACMNS-874
170
+ */
171
+ @ Test
172
+ public void unwrapsEmptyScalaOption () {
173
+ assertThat (QueryExecutionConverters .unwrap (Option .empty ()), is ((Object ) null ));
174
+ }
166
175
}
You can’t perform that action at this time.
0 commit comments