mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
chore: suppress some of "unchecked cast" warnings (#25)
This commit is contained in:
parent
75a4c8adfc
commit
28a4be86a4
@ -68,6 +68,7 @@ class ChannelOwner {
|
|||||||
connection.sendMessageNoWait(guid, method, params);
|
connection.sendMessageNoWait(guid, method, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
<T> Deferred<T> toDeferred(Waitable waitable) {
|
<T> Deferred<T> toDeferred(Waitable waitable) {
|
||||||
return () -> {
|
return () -> {
|
||||||
while (!waitable.isDone()) {
|
while (!waitable.isDone()) {
|
||||||
|
@ -79,6 +79,7 @@ class Serialization {
|
|||||||
result.a = list.toArray(new SerializedValue[0]);
|
result.a = list.toArray(new SerializedValue[0]);
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map) {
|
||||||
List<SerializedValue.O> list = new ArrayList<>();
|
List<SerializedValue.O> list = new ArrayList<>();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> map = (Map<String, Object>) value;
|
Map<String, Object> map = (Map<String, Object>) value;
|
||||||
for (Map.Entry<String, Object> e : map.entrySet()) {
|
for (Map.Entry<String, Object> e : map.entrySet()) {
|
||||||
SerializedValue.O o = new SerializedValue.O();
|
SerializedValue.O o = new SerializedValue.O();
|
||||||
@ -113,6 +114,7 @@ class Serialization {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static <T> T deserialize(SerializedValue value) {
|
static <T> T deserialize(SerializedValue value) {
|
||||||
if (value.n != null) {
|
if (value.n != null) {
|
||||||
if (value.n.doubleValue() == (double) value.n.intValue()) {
|
if (value.n.doubleValue() == (double) value.n.intValue()) {
|
||||||
@ -142,14 +144,14 @@ class Serialization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value.a != null) {
|
if (value.a != null) {
|
||||||
List list = new ArrayList();
|
List<Object> list = new ArrayList<>();
|
||||||
for (SerializedValue v : value.a) {
|
for (SerializedValue v : value.a) {
|
||||||
list.add(deserialize(v));
|
list.add(deserialize(v));
|
||||||
}
|
}
|
||||||
return (T) list;
|
return (T) list;
|
||||||
}
|
}
|
||||||
if (value.o != null) {
|
if (value.o != null) {
|
||||||
Map map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
for (SerializedValue.O o : value.o) {
|
for (SerializedValue.O o : value.o) {
|
||||||
map.put(o.k, deserialize(o.v));
|
map.put(o.k, deserialize(o.v));
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ class WaitableEvent<EventType, ResultType> implements Waitable<ResultType>, List
|
|||||||
listeners.remove(type, this);
|
listeners.remove(type, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public ResultType get() {
|
public ResultType get() {
|
||||||
return (ResultType) event.data();
|
return (ResultType) event.data();
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,7 @@ public class TestPageExposeFunction {
|
|||||||
" }\n" +
|
" }\n" +
|
||||||
"}");
|
"}");
|
||||||
assertTrue(result instanceof Map);
|
assertTrue(result instanceof Map);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, String> m = (Map<String, String>) result;
|
Map<String, String> m = (Map<String, String>) result;
|
||||||
assertEquals("WOOF WOOF", m.get("message"));
|
assertEquals("WOOF WOOF", m.get("message"));
|
||||||
assertTrue(m.get("stack").contains("shouldThrowExceptionInPageContext"));
|
assertTrue(m.get("stack").contains("shouldThrowExceptionInPageContext"));
|
||||||
@ -202,7 +203,9 @@ public class TestPageExposeFunction {
|
|||||||
@Test
|
@Test
|
||||||
void shouldWorkWithComplexObjects() {
|
void shouldWorkWithComplexObjects() {
|
||||||
page.exposeFunction("complexObject", args -> {
|
page.exposeFunction("complexObject", args -> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Integer> a = (Map<String, Integer>) args[0];
|
Map<String, Integer> a = (Map<String, Integer>) args[0];
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Integer> b = (Map<String, Integer>) args[1];
|
Map<String, Integer> b = (Map<String, Integer>) args[1];
|
||||||
int sum = a.get("x") + b.get("x");
|
int sum = a.get("x") + b.get("x");
|
||||||
return mapOf("x", sum);
|
return mapOf("x", sum);
|
||||||
|
@ -106,6 +106,7 @@ public class TestPopup {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInheritExtraHeadersFromBrowserContext() throws ExecutionException, InterruptedException {
|
void shouldInheritExtraHeadersFromBrowserContext() throws ExecutionException, InterruptedException {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||||
.withExtraHTTPHeaders(mapOf("foo", "bar")));
|
.withExtraHTTPHeaders(mapOf("foo", "bar")));
|
||||||
Page page = context.newPage();
|
Page page = context.newPage();
|
||||||
|
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static Map mapOf(Object... entries) {
|
static Map mapOf(Object... entries) {
|
||||||
Map result = new HashMap();
|
Map result = new HashMap();
|
||||||
for (int i = 0; i + 1 < entries.length; i += 2) {
|
for (int i = 0; i + 1 < entries.length; i += 2) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user