13
13
// limitations under the License.
14
14
package com .google .devtools .build .android .desugar .dependencies ;
15
15
16
+ import static com .google .common .collect .ImmutableList .toImmutableList ;
16
17
import static com .google .common .truth .Truth .assertThat ;
17
18
18
- import com .google .common .collect .ImmutableList ;
19
19
import com .google .devtools .build .android .desugar .proto .DesugarDeps ;
20
- import com .google .devtools .build .android .desugar .proto .DesugarDeps .Dependency ;
21
20
import com .google .devtools .build .android .desugar .proto .DesugarDeps .DesugarDepsInfo ;
22
21
import com .google .devtools .build .android .desugar .proto .DesugarDeps .InterfaceDetails ;
23
- import com . google . devtools . build . android . desugar . proto . DesugarDeps . InterfaceWithCompanion ;
22
+ import java . util . Arrays ;
24
23
import org .junit .Test ;
25
24
import org .junit .runner .RunWith ;
26
25
import org .junit .runners .JUnit4 ;
@@ -42,65 +41,79 @@ public void testAssumeCompanionClass() throws Exception {
42
41
collector .assumeCompanionClass ("a" , "a$$CC" );
43
42
44
43
DesugarDepsInfo info = extractProto (collector );
44
+
45
45
assertThat (info .getAssumePresentList ())
46
46
.containsExactly (
47
- Dependency .newBuilder ().setOrigin (wrapType ("a" )).setTarget (wrapType ("b$$CC" )).build (),
48
- Dependency .newBuilder ().setOrigin (wrapType ("b" )).setTarget (wrapType ("b$$CC" )).build (),
49
- Dependency .newBuilder ().setOrigin (wrapType ("a" )).setTarget (wrapType ("a$$CC" )).build ());
47
+ dependency ("a" , "a$$CC" ), dependency ("a" , "b$$CC" ), dependency ("b" , "b$$CC" ));
50
48
}
51
49
52
50
@ Test
53
51
public void testMissingImplementedInterface () throws Exception {
54
52
MetadataCollector collector = new MetadataCollector (true );
55
53
collector .missingImplementedInterface ("a" , "b" );
56
- collector .missingImplementedInterface ("a" , "c" );
57
54
collector .missingImplementedInterface ("c" , "b" );
55
+ collector .missingImplementedInterface ("a" , "c" );
58
56
59
57
DesugarDepsInfo info = extractProto (collector );
60
- assertThat (info .getMissingInterfaceList ())
61
- .containsExactly (
62
- Dependency .newBuilder ().setOrigin (wrapType ("a" )).setTarget (wrapType ("b" )).build (),
63
- Dependency .newBuilder ().setOrigin (wrapType ("a" )).setTarget (wrapType ("c" )).build (),
64
- Dependency .newBuilder ().setOrigin (wrapType ("c" )).setTarget (wrapType ("b" )).build ());
58
+ assertThat (info .getMissingInterfaceList ().get (0 )).isEqualTo (dependency ("a" , "b" ));
59
+ assertThat (info .getMissingInterfaceList ().get (1 )).isEqualTo (dependency ("a" , "c" ));
60
+ assertThat (info .getMissingInterfaceList ().get (2 )).isEqualTo (dependency ("c" , "b" ));
65
61
}
66
62
67
63
@ Test
68
64
public void testRecordExtendedInterfaces () throws Exception {
69
65
MetadataCollector collector = new MetadataCollector (false );
70
- collector .recordExtendedInterfaces ("a" , "b" , "c" );
71
- collector .recordExtendedInterfaces ("b" );
72
66
collector .recordExtendedInterfaces ("c" , "d" );
67
+ collector .recordExtendedInterfaces ("a" , "c" , "b" );
68
+ collector .recordExtendedInterfaces ("b" );
73
69
74
70
DesugarDepsInfo info = extractProto (collector );
75
- assertThat (info .getInterfaceWithSupertypesList ())
76
- .containsExactly (
77
- InterfaceDetails .newBuilder ()
78
- .setOrigin (wrapType ("a" ))
79
- .addAllExtendedInterface (ImmutableList .of (wrapType ("b" ), wrapType ("c" )))
80
- .build (),
81
- InterfaceDetails .newBuilder ()
82
- .setOrigin (wrapType ("c" ))
83
- .addAllExtendedInterface (ImmutableList .of (wrapType ("d" )))
84
- .build ());
71
+
72
+ assertThat (info .getInterfaceWithSupertypesList ().get (0 ))
73
+ .isEqualTo (interfaceDetails ("a" , "b" , "c" ));
74
+ assertThat (info .getInterfaceWithSupertypesList ().get (0 ).getExtendedInterfaceList ().get (0 ))
75
+ .isEqualTo (wrapType ("b" ));
76
+ assertThat (info .getInterfaceWithSupertypesList ().get (0 ).getExtendedInterfaceList ().get (1 ))
77
+ .isEqualTo (wrapType ("c" ));
78
+
79
+ assertThat (info .getInterfaceWithSupertypesList ().get (1 )).isEqualTo (interfaceDetails ("c" , "d" ));
85
80
}
86
81
87
82
@ Test
88
83
public void testRecordDefaultMethods () throws Exception {
89
84
MetadataCollector collector = new MetadataCollector (false );
90
- collector .recordDefaultMethods ("a" , 0 );
91
85
collector .recordDefaultMethods ("b" , 1 );
86
+ collector .recordDefaultMethods ("a" , 0 );
92
87
93
88
DesugarDepsInfo info = extractProto (collector );
94
- assertThat (info .getInterfaceWithCompanionList ())
95
- .containsExactly (
96
- InterfaceWithCompanion .newBuilder ()
97
- .setOrigin (wrapType ("a" ))
98
- .setNumDefaultMethods (0 )
99
- .build (),
100
- InterfaceWithCompanion .newBuilder ()
101
- .setOrigin (wrapType ("b" ))
102
- .setNumDefaultMethods (1 )
103
- .build ());
89
+ assertThat (info .getInterfaceWithCompanionList ().get (0 ))
90
+ .isEqualTo (interfaceWithCompanion ("a" , 0 ));
91
+ assertThat (info .getInterfaceWithCompanionList ().get (1 ))
92
+ .isEqualTo (interfaceWithCompanion ("b" , 1 ));
93
+ }
94
+
95
+ private DesugarDeps .InterfaceWithCompanion interfaceWithCompanion (String origin , int count ) {
96
+ return DesugarDeps .InterfaceWithCompanion .newBuilder ()
97
+ .setOrigin (wrapType (origin ))
98
+ .setNumDefaultMethods (count )
99
+ .build ();
100
+ }
101
+
102
+ private DesugarDeps .InterfaceDetails interfaceDetails (String originName , String ... interfaces ) {
103
+ return InterfaceDetails .newBuilder ()
104
+ .setOrigin (wrapType (originName ))
105
+ .addAllExtendedInterface (
106
+ Arrays .stream (interfaces )
107
+ .map (MetadataCollectorTest ::wrapType )
108
+ .collect (toImmutableList ()))
109
+ .build ();
110
+ }
111
+
112
+ private DesugarDeps .Dependency dependency (String origin , String target ) {
113
+ return DesugarDeps .Dependency .newBuilder ()
114
+ .setOrigin (wrapType (origin ))
115
+ .setTarget (wrapType (target ))
116
+ .build ();
104
117
}
105
118
106
119
private static DesugarDeps .Type wrapType (String name ) {
0 commit comments