Skip to content

Commit

Permalink
Sorting out some generics-related warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev authored and detro committed Mar 19, 2013
1 parent 5c7b761 commit f03b838
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ public void testShouldCorrectlyReportValueOfColspan() {
}

// This is a test-case re-creating issue 900.
@SuppressWarnings("unchecked")
@Ignore(SELENESE)
@Test
public void testShouldReturnValueOfOnClickAttribute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void shouldBeAbleToReturnAnArrayLiteralFromAnAsyncScript() {
Object result = executor.executeAsyncScript("arguments[arguments.length - 1]([]);");
assertNotNull("Expected not to be null!", result);
assertThat(result, instanceOf(List.class));
assertTrue(((List) result).isEmpty());
assertTrue(((List<?>) result).isEmpty());
}

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

@JavascriptEnabled
Expand All @@ -124,7 +124,7 @@ public void shouldBeAbleToReturnArraysOfPrimitivesFromAsyncScripts() {
assertNotNull(result);
assertThat(result, instanceOf(List.class));

Iterator results = ((List) result).iterator();
Iterator<?> results = ((List<?>) result).iterator();
assertNull(results.next());
assertEquals(123, ((Number) results.next()).longValue());
assertEquals("abc", results.next());
Expand Down Expand Up @@ -155,7 +155,7 @@ public void shouldBeAbleToReturnArraysOfWebElementsFromAsyncScripts() {
assertNotNull(result);
assertThat(result, instanceOf(List.class));

List list = (List) result;
List<?> list = (List<?>) result;
assertEquals(2, list.size());
assertThat(list.get(0), instanceOf(WebElement.class));
assertThat(list.get(1), instanceOf(WebElement.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static void set(TestEnvironment environment) {
GlobalTestEnvironment.environment = environment;
}

@SuppressWarnings("unchecked")
public static synchronized <T extends TestEnvironment> T get(
Class<T> startThisIfNothingIsAlreadyRunning) {
if (environment == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public void testMovingIntoAnImageEnclosedInALink() {
waitFor(pageTitleToBe(driver, "We Arrive Here"));
}

@SuppressWarnings("unchecked")
private Map<String, Object> getElementSize(WebElement element) {
return (Map<String, Object>) ((JavascriptExecutor) driver).executeScript(
"return arguments[0].getBoundingClientRect()", element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public void testShouldConvertCollections() throws Exception {
public void testShouldConvertNumbersAsLongs() throws Exception {

String json = new BeanToJsonConverter().convert(new Exception());
Map map = new JsonToBeanConverter().convert(Map.class, json);
Map<?,?> map = new JsonToBeanConverter().convert(Map.class, json);

List stack = (List) map.get("stackTrace");
Map line = (Map) stack.get(0);
List<?> stack = (List<?>) map.get("stackTrace");
Map<?,?> line = (Map<?,?>) stack.get(0);

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

@SuppressWarnings("unused")
public Set getSomething() {
public Set<?> getSomething() {
Set<Integer> integers = new HashSet<Integer>();
integers.add(1);
integers.add(43);
Expand All @@ -434,7 +434,7 @@ public Set getSomething() {
private static class BeanWithNullCollection {

@SuppressWarnings("unused")
public List getList() {
public List<?> getList() {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ public void testCanPopulateAMap() throws Exception {
assertThat(map, hasEntry("foodstuff", "cheese"));
}

@SuppressWarnings("unchecked")
@Test
public void testCanPopulateAMapThatContainsNull() throws Exception {
JSONObject toConvert = new JSONObject();
toConvert.put("foo", JSONObject.NULL);

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

@SuppressWarnings("unchecked")
@Test
public void testShouldSetPrimitiveValuesToo() throws Exception {
JSONObject toConvert = new JSONObject();
toConvert.put("magicNumber", 3);

Map map = new JsonToBeanConverter().convert(Map.class, toConvert.toString());
Map<?,?> map = new JsonToBeanConverter().convert(Map.class, toConvert.toString());

assertThat(3L, is(map.get("magicNumber")));
assertEquals(3L, map.get("magicNumber"));
}

@Test
Expand Down Expand Up @@ -153,25 +151,23 @@ public void testShouldBeAbleToInstantiateBooleans() throws Exception {
assertFalse(second);
}

@SuppressWarnings("unchecked")
@Test
public void testShouldUseAMapToRepresentComplexObjects() throws Exception {
JSONObject toModel = new JSONObject();
toModel.put("thing", "hairy");
toModel.put("hairy", "true");

Map modelled = (Map) new JsonToBeanConverter().convert(Object.class, toModel);
Map<?,?> modelled = (Map<?,?>) new JsonToBeanConverter().convert(Object.class, toModel);
assertEquals(2, modelled.size());
}

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

Map value = (Map) converted.getValue();
Map<?,?> value = (Map<?,?>) converted.getValue();
assertEquals("three", value.get("id"));
}

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

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

assertEquals("bar", response.getSessionId());
assertEquals(2, ((List) converted.getValue()).size());
assertEquals(2, ((List<?>) converted.getValue()).size());
assertEquals(1512, response.getStatus());
}

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

String rawJson = new BeanToJsonConverter().convert(Collections.singletonList(cookie));
List list = new JsonToBeanConverter().convert(List.class, rawJson);
List<?> list = new JsonToBeanConverter().convert(List.class, rawJson);

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

Map map = (Map) first;
Map<?,?> map = (Map<?,?>) first;
assertMapEntry(map, "name", "foo");
assertMapEntry(map, "value", "bar");
assertMapEntry(map, "path", "/rooted");
assertMapEntry(map, "expiry", TimeUnit.MILLISECONDS.toSeconds(date.getTime()));
}

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

Map reconstructed = new JsonToBeanConverter().convert(Map.class, converted);
List trace = (List) reconstructed.get("stackTrace");
Map<?,?> reconstructed = new JsonToBeanConverter().convert(Map.class, converted);
List<?> trace = (List<?>) reconstructed.get("stackTrace");

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

Object convertedInner = ((Map) convertedOuter).get("inner");
Object convertedInner = ((Map<?,?>) convertedOuter).get("inner");
assertNotNull(convertedInner);
assertThat(convertedInner, instanceOf(String.class));
assertThat(convertedInner.toString(), equalTo(inner.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void unwrapsWrappedElements_multipleLevelsOfWrapping() {
assertIsWebElementObject(value, "abc123");
}

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

@SuppressWarnings("unchecked")
@Test
public void convertsNestedCollections_simpleValues() {
List<?> innerList = Lists.newArrayList(123, "abc");
Expand Down Expand Up @@ -211,26 +213,24 @@ public void convertsAMapWithAWebElement() {
assertIsWebElementObject(map.get("one"), "abc123");
}

@SuppressWarnings("unchecked")
@Test
public void convertsAnArray() {
Object value = CONVERTER.apply(new Object[] {
"abc123", true, 123, Math.PI
});

assertThat(value, instanceOf(Collection.class));
assertContentsInOrder(Lists.newArrayList((Collection) value),
assertContentsInOrder(Lists.newArrayList((Collection<?>) value),
"abc123", true, 123, Math.PI);
}

@SuppressWarnings("unchecked")
@Test
public void convertsAnArrayWithAWebElement() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static class GrottyPage2 {
public static class UnmarkedListPage {
private List<WebElement> elements;
private List<Object> objects;
@SuppressWarnings("rawtypes")
private List untyped; // This list deliberately left untyped
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void shouldUnpackElementArgsWhenCallingScripts() {
@Test
public void testShouldUnpackListOfElementArgsWhenCallingScripts() {
final ExececutingDriver mockedDriver = mock(ExececutingDriver.class);
final List<Object> aList = mock(List.class);
final List<?> aList = mock(List.class);

checking(new Expectations() {{
one(aList).size();
Expand All @@ -306,7 +306,7 @@ public void testShouldUnpackListOfElementArgsWhenCallingScripts() {
@Test
public void testShouldUnpackMapOfElementArgsWhenCallingScripts() {
final ExececutingDriver mockedDriver = mock(ExececutingDriver.class);
final Map<Object, Object> aMap = mock(Map.class);
final Map<?,?> aMap = mock(Map.class);

checking(new Expectations() {{
one(aMap).keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.List;

public class LocatingElementListHandlerTest extends MockTestBase {

@SuppressWarnings("unchecked")
@Test
public void shouldAlwaysLocateTheElementPerCall() {
final ElementLocator locator = mock(ElementLocator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void shouldSilentlyCaptureNoSuchElementExceptions() {
}});

TickingClock clock = new TickingClock(500);
Wait wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
Wait<WebDriver> wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
assertSame(element, wait.until(condition));
}

Expand All @@ -84,7 +84,7 @@ public void shouldSilentlyCaptureNoSuchFrameExceptions() {
}});

TickingClock clock = new TickingClock(500);
Wait wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
Wait<WebDriver> wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
wait.until(condition);
}

Expand All @@ -101,7 +101,7 @@ public void shouldSilentlyCaptureNoSuchWindowExceptions() {
}});

TickingClock clock = new TickingClock(500);
Wait wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
Wait<WebDriver> wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
wait.until(condition);
}

Expand Down

0 comments on commit f03b838

Please sign in to comment.