Skip to content

Commit 2879746

Browse files
j2objc-copybaracopybara-github
authored andcommitted
Add ImmutableList case.
PiperOrigin-RevId: 889431611
1 parent e8db883 commit 2879746

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ public class ObjectiveCKmpMethodTranslatorTest extends GenerationTest {
2424
@Override
2525
public void setUp() throws IOException {
2626
super.setUp();
27+
addSourceFile(
28+
"""
29+
package com.google.common.collect;
30+
public class ImmutableList<E> extends java.util.AbstractList<E> {
31+
public static <E> ImmutableList<E> of() {
32+
return new ImmutableList<E>();
33+
}
34+
public E get(int index) {
35+
return null;
36+
}
37+
public int size() {
38+
return 0;
39+
}
40+
}
41+
""",
42+
"com/google/common/collect/ImmutableList.java");
2743
addSourceFile("public class Foo {}", "Foo.java");
2844
addSourceFile("public class Bar {}", "Bar.java");
2945
addSourceFile(
@@ -769,6 +785,49 @@ public void setList(List<Bar> list) {}
769785
+ " toGenericWithId:list]]");
770786
}
771787

788+
public void testImmutableListIsNotConverted() throws IOException {
789+
addSourceFile(
790+
"""
791+
import com.google.common.collect.ImmutableList;
792+
import com.google.j2objc.annotations.ObjectiveCKmpMethod;
793+
794+
public class ImmutableListTest {
795+
@ObjectiveCKmpMethod(selector="setListWithImmutableList:", adapter=Adapter.class)
796+
public void setList(ImmutableList<String> list) {
797+
return;
798+
}
799+
800+
@ObjectiveCKmpMethod(selector="getListAsImmutableList", adapter=Adapter.class)
801+
public ImmutableList<String> getList() {
802+
return null;
803+
}
804+
}
805+
""",
806+
"ImmutableListTest.java");
807+
808+
String testHeader = translateSourceFile("ImmutableListTest", "ImmutableListTest.h");
809+
assertInTranslation(
810+
testHeader, "- (void)setListWithImmutableList:(ComGoogleCommonCollectImmutableList *)list;");
811+
assertInTranslation(
812+
testHeader, "- (ComGoogleCommonCollectImmutableList *)getListAsImmutableList;");
813+
814+
String testImplementation = translateSourceFile("ImmutableListTest", "ImmutableListTest.m");
815+
assertInTranslation(
816+
testImplementation,
817+
"""
818+
- (void)setListWithImmutableList:(ComGoogleCommonCollectImmutableList *)list {
819+
[self setListWithComGoogleCommonCollectImmutableList:list];
820+
}
821+
""");
822+
assertInTranslation(
823+
testImplementation,
824+
"""
825+
- (ComGoogleCommonCollectImmutableList *)getListAsImmutableList {
826+
return [self getList];
827+
}
828+
""");
829+
}
830+
772831
public void testNoMethodFoundThrowsException() throws IOException {
773832
addSourceFile(
774833
"""

0 commit comments

Comments
 (0)