Skip to content

Commit 38fc4dd

Browse files
kluevercopybara-github
authored andcommitted
Fix a buggy call to String.join() where no joining is performed:
* `String.join(CharSequence delimiter)` always returns the empty string (`""`) because no tokens are given (only a delimiter!). * `String.join(CharSequence delimiter, CharSequence token)` always returns `token`, because joining does not occur for < 2 tokens. PiperOrigin-RevId: 797867624
1 parent 23f943a commit 38fc4dd

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

translator/src/test/java/com/google/devtools/j2objc/translate/LogSiteInjectorTest.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ public void testConvenienceMethods() throws IOException {
100100
String source =
101101
String.join(
102102
"\n",
103-
"package test;"
104-
+ "import java.util.logging.Logger;"
105-
+ "public class Hello3 {"
106-
+ " private static final Logger logger=Logger.getLogger(Hello3.class.getName());"
107-
+ " public static void f(Throwable t, String msg, Object arg, Object... args) {"
108-
+ " logger.finest(msg);"
109-
+ " logger.fine(msg);"
110-
+ " logger.finer(msg);"
111-
+ " logger.severe(msg);"
112-
+ " logger.warning(msg);"
113-
+ " logger.config(msg);"
114-
+ " logger.info(msg);"
115-
+ " }"
116-
+ "}");
103+
"package test;",
104+
"import java.util.logging.Logger;",
105+
"public class Hello3 {",
106+
" private static final Logger logger=Logger.getLogger(Hello3.class.getName());",
107+
" public static void f(Throwable t, String msg, Object arg, Object... args) {",
108+
" logger.finest(msg);",
109+
" logger.fine(msg);",
110+
" logger.finer(msg);",
111+
" logger.severe(msg);",
112+
" logger.warning(msg);",
113+
" logger.config(msg);",
114+
" logger.info(msg);",
115+
" }",
116+
"}");
117117
String translation = translateSourceFile(source, "test.Hello3", "test/Hello3.m");
118118
assertTranslatedLines(
119119
translation,
@@ -181,19 +181,19 @@ public void testCustomLogger() throws IOException {
181181
String source =
182182
String.join(
183183
"\n",
184-
"package test;"
185-
+ "import java.util.logging.Logger;"
186-
+ "public class Hello4 {"
187-
+ " static class MyLogger extends Logger {"
188-
+ " protected MyLogger(String name, String resourceBundleName) {"
189-
+ " super(name, resourceBundleName);"
190-
+ " }"
191-
+ " public void log() {}"
192-
+ " }"
193-
+ " public static void f(MyLogger l) {"
194-
+ " l.log();"
195-
+ " }"
196-
+ "}");
184+
"package test;",
185+
"import java.util.logging.Logger;",
186+
"public class Hello4 {",
187+
" static class MyLogger extends Logger {",
188+
" protected MyLogger(String name, String resourceBundleName) {",
189+
" super(name, resourceBundleName);",
190+
" }",
191+
" public void log() {}",
192+
" }",
193+
" public static void f(MyLogger l) {",
194+
" l.log();",
195+
" }",
196+
"}");
197197
String translation = translateSourceFile(source, "test.Hello4", "test/Hello4.m");
198198
assertTranslation(translation, "[((TestHello4_MyLogger *) nil_chk(l)) log];");
199199
}
@@ -202,17 +202,17 @@ public void testInnerClass() throws IOException {
202202
String source =
203203
String.join(
204204
"\n",
205-
"package test;"
206-
+ "import java.util.logging.Logger;"
207-
+ "import java.util.logging.Level;"
208-
+ "public class Hello5 {"
209-
+ " private static final Logger logger = Logger.getLogger(Hello5.class.getName());"
210-
+ " public static class Inner {"
211-
+ " public static void f(String msg) {"
212-
+ " logger.info(msg);"
213-
+ " }"
214-
+ " }"
215-
+ "}");
205+
"package test;",
206+
"import java.util.logging.Logger;",
207+
"import java.util.logging.Level;",
208+
"public class Hello5 {",
209+
" private static final Logger logger = Logger.getLogger(Hello5.class.getName());",
210+
" public static class Inner {",
211+
" public static void f(String msg) {",
212+
" logger.info(msg);",
213+
" }",
214+
" }",
215+
"}");
216216
String translation = translateSourceFile(source, "test.Hello5", "test/Hello5.m");
217217
assertTranslation(
218218
translation,

0 commit comments

Comments
 (0)