Skip to content

Commit

Permalink
json: fromJson does not need to be public
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Sep 11, 2018
1 parent 507fc3b commit fa704b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public BiFunction<JsonInput, PropertySetting, Object> apply(Type type) {

private Method getStaticMethod(String name, Class<?> aClass) {
try {
Method method = aClass.getMethod(name, String.class);
Method method = aClass.getDeclaredMethod(name, String.class);
if (!Modifier.isStatic(method.getModifiers())) {
return null;
}
Expand Down
24 changes: 20 additions & 4 deletions java/client/test/org/openqa/selenium/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.openqa.selenium.json;

import static org.assertj.core.api.Assertions.assertThat;
import static java.util.logging.Level.ALL;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.OFF;
import static java.util.logging.Level.WARNING;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.byLessThan;
import static org.openqa.selenium.Proxy.ProxyType.PAC;
import static org.openqa.selenium.json.Json.MAP_TYPE;
Expand Down Expand Up @@ -81,7 +81,6 @@ public void canRoundTripNumbers() {

Json json = new Json();
String converted = json.toJson(original);
System.out.println("converted = " + converted);
Object remade = json.toType(converted, MAP_TYPE);

assertThat(remade).isEqualTo(original);
Expand Down Expand Up @@ -110,7 +109,6 @@ public void shouldCoerceAListOfCapabilitiesIntoSomethingMutable() {

Json json = new Json();
String raw = json.toJson(expected);
System.out.println("raw = " + raw);
List<Capabilities> seen = json.toType(raw, new TypeToken<List<Capabilities>>(){}.getType());

assertThat(seen).isEqualTo(expected);
Expand Down Expand Up @@ -415,11 +413,17 @@ public void shouldBeAbleToConvertASelenium3CommandToASelenium2Command() {
}

@Test
public void testShouldCallFromJsonMethodIfPresent() {
public void shouldCallFromJsonMethodIfPresent() {
JsonAware res = new Json().toType("\"converted\"", JsonAware.class);
assertThat(res.convertedValue).isEqualTo("\"converted\"");
}

@Test
public void fromJsonMethodNeedNotBePublic() {
JsonAware res = new Json().toType("\"converted\"", PrivatelyAware.class);
assertThat(res.convertedValue).isEqualTo("\"converted\"");
}

// Test for issue 8187
@Test
public void testDecodingResponseWithNumbersInValueObject() {
Expand Down Expand Up @@ -555,4 +559,16 @@ public static JsonAware fromJson(String json) {
return new JsonAware(json);
}
}

public static class PrivatelyAware {
private String convertedValue;

public PrivatelyAware(String convertedValue) {
this.convertedValue = convertedValue;
}

private static JsonAware fromJson(String json) {
return new JsonAware(json);
}
}
}

0 comments on commit fa704b9

Please sign in to comment.