Skip to content

Commit 470431a

Browse files
committed
Adding a unit test for Command serialization to json
1 parent 73d3a8b commit 470431a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static org.hamcrest.Matchers.not;
5252
import static org.junit.Assert.assertEquals;
5353
import static org.junit.Assert.assertFalse;
54+
import static org.junit.Assert.assertNotNull;
5455
import static org.junit.Assert.assertThat;
5556
import static org.junit.Assert.assertTrue;
5657
import static org.junit.Assert.fail;
@@ -402,6 +403,31 @@ public void testConvertLogEntriesToJson() throws JSONException {
402403
assertEquals("entry2", obj2.get("message"));
403404
}
404405

406+
@Test
407+
public void testShouldBeAbleToConvertACommand() throws JSONException {
408+
SessionId sessionId = new SessionId("some id");
409+
String commandName = "some command";
410+
Map<String, Object> parameters = new HashMap<String, Object>();
411+
parameters.put("param1", "value1");
412+
parameters.put("param2", "value2");
413+
Command command = new Command(sessionId, commandName, parameters);
414+
415+
System.out.println(new BeanToJsonConverter().convert(command));
416+
JSONObject json = new JSONObject(new BeanToJsonConverter().convert(command));
417+
418+
assertNotNull(json.get("sessionId"));
419+
JSONObject sid = (JSONObject) json.get("sessionId");
420+
assertEquals(sid.getString("value"), sessionId.toString());
421+
422+
assertEquals(json.getString("name"), commandName);
423+
424+
assertNotNull(json.get("parameters"));
425+
JSONObject pars = (JSONObject) json.get("parameters");
426+
assertEquals(pars.length(), 2);
427+
assertEquals(pars.getString("param1"), parameters.get("param1"));
428+
assertEquals(pars.getString("param2"), parameters.get("param2"));
429+
}
430+
405431
@SuppressWarnings("unused")
406432
private static class SimpleBean {
407433

0 commit comments

Comments
 (0)