File tree Expand file tree Collapse file tree 2 files changed +14
-35
lines changed
src/test/java/org/baeldung/guava/collections Expand file tree Collapse file tree 2 files changed +14
-35
lines changed Original file line number Diff line number Diff line change 6565 <groupId >org.apache.maven.plugins</groupId >
6666 <artifactId >maven-surefire-plugin</artifactId >
6767 <version >${maven-surefire-plugin.version} </version >
68- <configuration >
69- <excludes >
70- <!-- <exclude>**/*ProductionTest.java</exclude> -->
71- </excludes >
72- <systemPropertyVariables >
73- <!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
74- </systemPropertyVariables >
75- </configuration >
76- </plugin >
77-
78- <plugin >
79- <groupId >org.codehaus.cargo</groupId >
80- <artifactId >cargo-maven2-plugin</artifactId >
81- <version >${cargo-maven2-plugin.version} </version >
82- <configuration >
83- <wait >true</wait >
84- <container >
85- <containerId >jetty8x</containerId >
86- <type >embedded</type >
87- <systemProperties >
88- <!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
89- </systemProperties >
90- </container >
91- <configuration >
92- <properties >
93- <cargo .servlet.port>8082</cargo .servlet.port>
94- </properties >
95- </configuration >
96- </configuration >
9768 </plugin >
9869
9970 </plugins >
Original file line number Diff line number Diff line change 77import com .google .common .base .Function ;
88import com .google .common .collect .Lists ;
99
10- public class GuavaCollectionsExamples {
10+ public class GuavaCollectionsExamplesTest {
11+
12+ // tests
1113
12- @ SuppressWarnings ({ "unused" , "unchecked" })
1314 @ Test
14- public final void whenCastingAllElementsOfACollectionToSubtype_thenCastIsOK () {
15+ public final void whenDowncastingGenerifiedCollectionToNewGenerifiedCollection_thenCastIsOK () {
1516 final class CastFunction <F , T extends F > implements Function <F , T > {
16- @ Override
1717 @ SuppressWarnings ("unchecked" )
18+ @ Override
1819 public final T apply (final F from ) {
1920 return (T ) from ;
2021 }
2122 }
2223
2324 final List <Number > originalList = Lists .newArrayList ();
24- final List <Integer > selectedProductsQuick = (List <Integer >) (List <? extends Number >) originalList ;
2525 final List <Integer > selectedProducts = Lists .transform (originalList , new CastFunction <Number , Integer >());
2626 System .out .println (selectedProducts );
2727 }
2828
29+ @ SuppressWarnings ({ "unchecked" })
2930 @ Test
30- public final void when_then () {
31+ public final void whenDowncastingGenerifiedCollectionToNewGenerifiedCollection_thenCastIsOK2 () {
32+ final List <Number > originalList = Lists .newArrayList ();
33+ final List <Integer > selectedProducts = (List <Integer >) (List <? extends Number >) originalList ;
34+ System .out .println (selectedProducts );
35+ }
3136
37+ @ Test
38+ public final void when_then () {
39+ //
3240 }
3341
3442}
You can’t perform that action at this time.
0 commit comments