1616package org .openrewrite .java .migrate .util ;
1717
1818import org .junit .jupiter .api .Test ;
19+ import org .openrewrite .DocumentExample ;
1920import org .openrewrite .Issue ;
2021import org .openrewrite .test .RecipeSpec ;
2122import org .openrewrite .test .RewriteTest ;
@@ -31,9 +32,9 @@ public void defaults(RecipeSpec spec) {
3132 spec .recipe (new MigrateCollectionsSingletonMap ());
3233 }
3334
34- @ Issue ( "https://github.com/openrewrite/rewrite-migrate-java/issues/72" )
35+ @ DocumentExample
3536 @ Test
36- void singletonMap () {
37+ void singletonMapAsArgument () {
3738 //language=java
3839 rewriteRun (
3940 version (
@@ -42,14 +43,20 @@ void singletonMap() {
4243 import java.util.*;
4344
4445 class Test {
45- Map<String,String> set = Collections.singletonMap("hello", "world");
46+ void take(Map<String, Object> m) {}
47+ void call(String key, Object value) {
48+ take(Collections.singletonMap(key, value));
49+ }
4650 }
4751 """ ,
4852 """
4953 import java.util.Map;
5054
5155 class Test {
52- Map<String,String> set = Map.of("hello", "world");
56+ void take(Map<String, Object> m) {}
57+ void call(String key, Object value) {
58+ take(Map.of(key, value));
59+ }
5360 }
5461 """
5562 ),
@@ -60,25 +67,23 @@ class Test {
6067
6168 @ Issue ("https://github.com/openrewrite/rewrite-migrate-java/issues/72" )
6269 @ Test
63- void singletonMapCustomType () {
70+ void singletonMap () {
6471 //language=java
6572 rewriteRun (
6673 version (
6774 java (
6875 """
6976 import java.util.*;
70- import java.time.LocalDate;
7177
7278 class Test {
73- Map<String,LocalDate> map = Collections.singletonMap("date ", LocalDate.now() );
79+ Map<String,String> set = Collections.singletonMap("hello ", "world" );
7480 }
7581 """ ,
7682 """
7783 import java.util.Map;
78- import java.time.LocalDate;
7984
8085 class Test {
81- Map<String,LocalDate> map = Map.of("date ", LocalDate.now() );
86+ Map<String,String> set = Map.of("hello ", "world" );
8287 }
8388 """
8489 ),
@@ -87,19 +92,27 @@ class Test {
8792 );
8893 }
8994
90- @ Issue ("https://github.com/openrewrite/rewrite-migrate-java/issues/571 " )
95+ @ Issue ("https://github.com/openrewrite/rewrite-migrate-java/issues/72 " )
9196 @ Test
92- void shouldNotConvertLiteralNull () {
97+ void singletonMapCustomType () {
9398 //language=java
9499 rewriteRun (
95100 version (
96101 java (
97102 """
98103 import java.util.*;
104+ import java.time.LocalDate;
99105
100106 class Test {
101- Map<String, String> mapWithNullKey = Collections.singletonMap(null, "foo");
102- Map<String, String> mapWithNullValue = Collections.singletonMap("bar", null);
107+ Map<String,LocalDate> map = Collections.singletonMap("date", LocalDate.now());
108+ }
109+ """ ,
110+ """
111+ import java.util.Map;
112+ import java.time.LocalDate;
113+
114+ class Test {
115+ Map<String,LocalDate> map = Map.of("date", LocalDate.now());
103116 }
104117 """
105118 ),
@@ -108,8 +121,9 @@ class Test {
108121 );
109122 }
110123
124+ @ Issue ("https://github.com/openrewrite/rewrite-migrate-java/issues/571" )
111125 @ Test
112- void singletonMapAsArgument () {
126+ void shouldNotConvertLiteralNull () {
113127 //language=java
114128 rewriteRun (
115129 version (
@@ -118,20 +132,8 @@ void singletonMapAsArgument() {
118132 import java.util.*;
119133
120134 class Test {
121- void take(Map<String, Object> m) {}
122- void call(String key, Object value) {
123- take(Collections.singletonMap(key, value));
124- }
125- }
126- """ ,
127- """
128- import java.util.Map;
129-
130- class Test {
131- void take(Map<String, Object> m) {}
132- void call(String key, Object value) {
133- take(Map.of(key, value));
134- }
135+ Map<String, String> mapWithNullKey = Collections.singletonMap(null, "foo");
136+ Map<String, String> mapWithNullValue = Collections.singletonMap("bar", null);
135137 }
136138 """
137139 ),
0 commit comments