Skip to content

Commit f03b838

Browse files
barancevdetro
authored andcommitted
Sorting out some generics-related warnings
1 parent 5c7b761 commit f03b838

File tree

11 files changed

+35
-36
lines changed

11 files changed

+35
-36
lines changed

java/client/test/org/openqa/selenium/ElementAttributeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ public void testShouldCorrectlyReportValueOfColspan() {
280280
}
281281

282282
// This is a test-case re-creating issue 900.
283-
@SuppressWarnings("unchecked")
284283
@Ignore(SELENESE)
285284
@Test
286285
public void testShouldReturnValueOfOnClickAttribute() {

java/client/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void shouldBeAbleToReturnAnArrayLiteralFromAnAsyncScript() {
9797
Object result = executor.executeAsyncScript("arguments[arguments.length - 1]([]);");
9898
assertNotNull("Expected not to be null!", result);
9999
assertThat(result, instanceOf(List.class));
100-
assertTrue(((List) result).isEmpty());
100+
assertTrue(((List<?>) result).isEmpty());
101101
}
102102

103103
@JavascriptEnabled
@@ -108,7 +108,7 @@ public void shouldBeAbleToReturnAnArrayObjectFromAnAsyncScript() {
108108
Object result = executor.executeAsyncScript("arguments[arguments.length - 1](new Array());");
109109
assertNotNull("Expected not to be null!", result);
110110
assertThat(result, instanceOf(List.class));
111-
assertTrue(((List) result).isEmpty());
111+
assertTrue(((List<?>) result).isEmpty());
112112
}
113113

114114
@JavascriptEnabled
@@ -124,7 +124,7 @@ public void shouldBeAbleToReturnArraysOfPrimitivesFromAsyncScripts() {
124124
assertNotNull(result);
125125
assertThat(result, instanceOf(List.class));
126126

127-
Iterator results = ((List) result).iterator();
127+
Iterator<?> results = ((List<?>) result).iterator();
128128
assertNull(results.next());
129129
assertEquals(123, ((Number) results.next()).longValue());
130130
assertEquals("abc", results.next());
@@ -155,7 +155,7 @@ public void shouldBeAbleToReturnArraysOfWebElementsFromAsyncScripts() {
155155
assertNotNull(result);
156156
assertThat(result, instanceOf(List.class));
157157

158-
List list = (List) result;
158+
List<?> list = (List<?>) result;
159159
assertEquals(2, list.size());
160160
assertThat(list.get(0), instanceOf(WebElement.class));
161161
assertThat(list.get(1), instanceOf(WebElement.class));

java/client/test/org/openqa/selenium/environment/GlobalTestEnvironment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static void set(TestEnvironment environment) {
3636
GlobalTestEnvironment.environment = environment;
3737
}
3838

39+
@SuppressWarnings("unchecked")
3940
public static synchronized <T extends TestEnvironment> T get(
4041
Class<T> startThisIfNothingIsAlreadyRunning) {
4142
if (environment == null) {

java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public void testMovingIntoAnImageEnclosedInALink() {
295295
waitFor(pageTitleToBe(driver, "We Arrive Here"));
296296
}
297297

298+
@SuppressWarnings("unchecked")
298299
private Map<String, Object> getElementSize(WebElement element) {
299300
return (Map<String, Object>) ((JavascriptExecutor) driver).executeScript(
300301
"return arguments[0].getBoundingClientRect()", element);

java/client/test/org/openqa/selenium/remote/BeanToJsonConverterTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public void testShouldConvertCollections() throws Exception {
107107
public void testShouldConvertNumbersAsLongs() throws Exception {
108108

109109
String json = new BeanToJsonConverter().convert(new Exception());
110-
Map map = new JsonToBeanConverter().convert(Map.class, json);
110+
Map<?,?> map = new JsonToBeanConverter().convert(Map.class, json);
111111

112-
List stack = (List) map.get("stackTrace");
113-
Map line = (Map) stack.get(0);
112+
List<?> stack = (List<?>) map.get("stackTrace");
113+
Map<?,?> line = (Map<?,?>) stack.get(0);
114114

115115
Object o = line.get("lineNumber");
116116
assertTrue("line number is of type: " + o.getClass(), o instanceof Long);
@@ -423,7 +423,7 @@ public String[] getNames() {
423423
private static class BeanWithCollection {
424424

425425
@SuppressWarnings("unused")
426-
public Set getSomething() {
426+
public Set<?> getSomething() {
427427
Set<Integer> integers = new HashSet<Integer>();
428428
integers.add(1);
429429
integers.add(43);
@@ -434,7 +434,7 @@ public Set getSomething() {
434434
private static class BeanWithNullCollection {
435435

436436
@SuppressWarnings("unused")
437-
public List getList() {
437+
public List<?> getList() {
438438
return null;
439439
}
440440
}

java/client/test/org/openqa/selenium/remote/JsonToBeanConverterTest.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ public void testCanPopulateAMap() throws Exception {
6868
assertThat(map, hasEntry("foodstuff", "cheese"));
6969
}
7070

71-
@SuppressWarnings("unchecked")
7271
@Test
7372
public void testCanPopulateAMapThatContainsNull() throws Exception {
7473
JSONObject toConvert = new JSONObject();
7574
toConvert.put("foo", JSONObject.NULL);
7675

77-
Map converted = new JsonToBeanConverter().convert(Map.class, toConvert.toString());
76+
Map<?,?> converted = new JsonToBeanConverter().convert(Map.class, toConvert.toString());
7877
assertEquals(1, converted.size());
7978
assertTrue(converted.containsKey("foo"));
8079
assertNull(converted.get("foo"));
@@ -101,15 +100,14 @@ public void testWillSilentlyDiscardUnusedFieldsWhenPopulatingABean() throws Exce
101100
assertThat(bean.getValue(), is("time"));
102101
}
103102

104-
@SuppressWarnings("unchecked")
105103
@Test
106104
public void testShouldSetPrimitiveValuesToo() throws Exception {
107105
JSONObject toConvert = new JSONObject();
108106
toConvert.put("magicNumber", 3);
109107

110-
Map map = new JsonToBeanConverter().convert(Map.class, toConvert.toString());
108+
Map<?,?> map = new JsonToBeanConverter().convert(Map.class, toConvert.toString());
111109

112-
assertThat(3L, is(map.get("magicNumber")));
110+
assertEquals(3L, map.get("magicNumber"));
113111
}
114112

115113
@Test
@@ -153,25 +151,23 @@ public void testShouldBeAbleToInstantiateBooleans() throws Exception {
153151
assertFalse(second);
154152
}
155153

156-
@SuppressWarnings("unchecked")
157154
@Test
158155
public void testShouldUseAMapToRepresentComplexObjects() throws Exception {
159156
JSONObject toModel = new JSONObject();
160157
toModel.put("thing", "hairy");
161158
toModel.put("hairy", "true");
162159

163-
Map modelled = (Map) new JsonToBeanConverter().convert(Object.class, toModel);
160+
Map<?,?> modelled = (Map<?,?>) new JsonToBeanConverter().convert(Object.class, toModel);
164161
assertEquals(2, modelled.size());
165162
}
166163

167-
@SuppressWarnings("unchecked")
168164
@Test
169165
public void testShouldConvertAResponseWithAnElementInIt() throws Exception {
170166
String json =
171167
"{\"value\":{\"value\":\"\",\"text\":\"\",\"selected\":false,\"enabled\":true,\"id\":\"three\"},\"context\":\"con\",\"sessionId\":\"sess\",\"error\":false}";
172168
Response converted = new JsonToBeanConverter().convert(Response.class, json);
173169

174-
Map value = (Map) converted.getValue();
170+
Map<?,?> value = (Map<?,?>) converted.getValue();
175171
assertEquals("three", value.get("id"));
176172
}
177173

@@ -205,7 +201,6 @@ public void testShouldBeAbleToSetAnObjectToABoolean() throws Exception {
205201
assertThat((Boolean) response.getValue(), is(true));
206202
}
207203

208-
@SuppressWarnings("unchecked")
209204
@Test
210205
public void testCanHandleValueBeingAnArray() throws Exception {
211206
String[] value = {"Cheese", "Peas"};
@@ -219,7 +214,7 @@ public void testCanHandleValueBeingAnArray() throws Exception {
219214
Response converted = new JsonToBeanConverter().convert(Response.class, json);
220215

221216
assertEquals("bar", response.getSessionId());
222-
assertEquals(2, ((List) converted.getValue()).size());
217+
assertEquals(2, ((List<?>) converted.getValue()).size());
223218
assertEquals(1512, response.getStatus());
224219
}
225220

@@ -229,19 +224,19 @@ public void testShouldConvertObjectsInArraysToMaps() throws Exception {
229224
Cookie cookie = new Cookie("foo", "bar", "/rooted", date);
230225

231226
String rawJson = new BeanToJsonConverter().convert(Collections.singletonList(cookie));
232-
List list = new JsonToBeanConverter().convert(List.class, rawJson);
227+
List<?> list = new JsonToBeanConverter().convert(List.class, rawJson);
233228

234229
Object first = list.get(0);
235230
assertTrue(first instanceof Map);
236231

237-
Map map = (Map) first;
232+
Map<?,?> map = (Map<?,?>) first;
238233
assertMapEntry(map, "name", "foo");
239234
assertMapEntry(map, "value", "bar");
240235
assertMapEntry(map, "path", "/rooted");
241236
assertMapEntry(map, "expiry", TimeUnit.MILLISECONDS.toSeconds(date.getTime()));
242237
}
243238

244-
private void assertMapEntry(Map map, String key, Object expected) {
239+
private void assertMapEntry(Map<?,?> map, String key, Object expected) {
245240
assertTrue("Missing key: " + key, map.containsKey(key));
246241
assertEquals("Wrong value for key: " + key + ": " + map.get(key).getClass().getName(),
247242
expected, map.get(key));
@@ -252,8 +247,8 @@ public void testShouldConvertAnArrayBackIntoAnArray() throws Exception {
252247
Exception e = new Exception();
253248
String converted = new BeanToJsonConverter().convert(e);
254249

255-
Map reconstructed = new JsonToBeanConverter().convert(Map.class, converted);
256-
List trace = (List) reconstructed.get("stackTrace");
250+
Map<?,?> reconstructed = new JsonToBeanConverter().convert(Map.class, converted);
251+
List<?> trace = (List<?>) reconstructed.get("stackTrace");
257252

258253
assertTrue(trace.get(0) instanceof Map);
259254
}
@@ -331,7 +326,7 @@ public void testShouldNotParseQuotedJsonObjectsAsActualJsonObjects() throws JSON
331326
Object convertedOuter = new JsonToBeanConverter().convert(Map.class, jsonStr);
332327
assertThat(convertedOuter, instanceOf(Map.class));
333328

334-
Object convertedInner = ((Map) convertedOuter).get("inner");
329+
Object convertedInner = ((Map<?,?>) convertedOuter).get("inner");
335330
assertNotNull(convertedInner);
336331
assertThat(convertedInner, instanceOf(String.class));
337332
assertThat(convertedInner.toString(), equalTo(inner.toString()));

java/client/test/org/openqa/selenium/remote/internal/WebElementToJsonConverterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public void unwrapsWrappedElements_multipleLevelsOfWrapping() {
9292
assertIsWebElementObject(value, "abc123");
9393
}
9494

95+
@SuppressWarnings("unchecked")
9596
@Test
9697
public void convertsSimpleCollections() {
9798
Object converted = CONVERTER.apply(Lists.newArrayList(null, "abc", true, 123, Math.PI));
@@ -101,6 +102,7 @@ public void convertsSimpleCollections() {
101102
assertContentsInOrder(list, null, "abc", true, 123, Math.PI);
102103
}
103104

105+
@SuppressWarnings("unchecked")
104106
@Test
105107
public void convertsNestedCollections_simpleValues() {
106108
List<?> innerList = Lists.newArrayList(123, "abc");
@@ -211,26 +213,24 @@ public void convertsAMapWithAWebElement() {
211213
assertIsWebElementObject(map.get("one"), "abc123");
212214
}
213215

214-
@SuppressWarnings("unchecked")
215216
@Test
216217
public void convertsAnArray() {
217218
Object value = CONVERTER.apply(new Object[] {
218219
"abc123", true, 123, Math.PI
219220
});
220221

221222
assertThat(value, instanceOf(Collection.class));
222-
assertContentsInOrder(Lists.newArrayList((Collection) value),
223+
assertContentsInOrder(Lists.newArrayList((Collection<?>) value),
223224
"abc123", true, 123, Math.PI);
224225
}
225226

226-
@SuppressWarnings("unchecked")
227227
@Test
228228
public void convertsAnArrayWithAWebElement() {
229229
RemoteWebElement element = new RemoteWebElement();
230230
element.setId("abc123");
231231

232232
Object value = CONVERTER.apply(new Object[] { element });
233-
assertContentsInOrder(Lists.newArrayList((Collection) value),
233+
assertContentsInOrder(Lists.newArrayList((Collection<?>) value),
234234
ImmutableMap.of("ELEMENT", "abc123"));
235235
}
236236

java/client/test/org/openqa/selenium/support/PageFactoryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public static class GrottyPage2 {
231231
public static class UnmarkedListPage {
232232
private List<WebElement> elements;
233233
private List<Object> objects;
234+
@SuppressWarnings("rawtypes")
234235
private List untyped; // This list deliberately left untyped
235236
}
236237

java/client/test/org/openqa/selenium/support/events/EventFiringWebDriverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public void shouldUnpackElementArgsWhenCallingScripts() {
285285
@Test
286286
public void testShouldUnpackListOfElementArgsWhenCallingScripts() {
287287
final ExececutingDriver mockedDriver = mock(ExececutingDriver.class);
288-
final List<Object> aList = mock(List.class);
288+
final List<?> aList = mock(List.class);
289289

290290
checking(new Expectations() {{
291291
one(aList).size();
@@ -306,7 +306,7 @@ public void testShouldUnpackListOfElementArgsWhenCallingScripts() {
306306
@Test
307307
public void testShouldUnpackMapOfElementArgsWhenCallingScripts() {
308308
final ExececutingDriver mockedDriver = mock(ExececutingDriver.class);
309-
final Map<Object, Object> aMap = mock(Map.class);
309+
final Map<?,?> aMap = mock(Map.class);
310310

311311
checking(new Expectations() {{
312312
one(aMap).keySet();

java/client/test/org/openqa/selenium/support/pagefactory/internal/LocatingElementListHandlerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.util.List;
3838

3939
public class LocatingElementListHandlerTest extends MockTestBase {
40+
41+
@SuppressWarnings("unchecked")
4042
@Test
4143
public void shouldAlwaysLocateTheElementPerCall() {
4244
final ElementLocator locator = mock(ElementLocator.class);

0 commit comments

Comments
 (0)