use of org.json.JSONStringer in project mobile-center-sdk-android by Microsoft.
the class AbstractLogTest method writeNullDeviceTest.
@Test
public void writeNullDeviceTest() throws JSONException {
JSONStringer mockJsonStringer = mock(JSONStringer.class);
when(mockJsonStringer.key(anyString())).thenReturn(mockJsonStringer);
when(mockJsonStringer.value(anyString())).thenReturn(mockJsonStringer);
AbstractLog mockLog = new MockLog();
mockLog.setTimestamp(new Date());
mockLog.write(mockJsonStringer);
verify(mockJsonStringer, never()).key(AbstractLog.DEVICE);
}
use of org.json.JSONStringer in project mobile-center-sdk-android by Microsoft.
the class DefaultLogSerializerTest method failToUsePrettyJson.
@Test
public void failToUsePrettyJson() throws Exception {
/* Mock logs to verify interactions. */
mockStatic(AppCenterLog.class);
when(AppCenterLog.getLogLevel()).thenReturn(Log.VERBOSE);
/* Mock stub JSONStringer. */
JSONStringer stringer = mock(JSONStringer.class);
whenNew(JSONStringer.class).withAnyArguments().thenReturn(stringer);
when(stringer.key(anyString())).thenReturn(stringer);
when(stringer.toString()).thenReturn("{}");
/*
* We are in test folder so the stub does not contain the private methods,
* this test thus simulates what happens if we can't access the private methods
* via reflection to use pretty json. We check it serializes gracefully.
*/
assertEquals("{}", new DefaultLogSerializer().serializeContainer(mock(LogContainer.class)));
/* And that it logs why the pretty json could not be used. */
verifyStatic();
AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(NoSuchMethodError.class));
}
use of org.json.JSONStringer in project quickstart by wildfly.
the class RESTTest method testAddContact.
@Test
@InSequence(2)
public void testAddContact() throws Exception {
HttpPost post = new HttpPost(contextPath.toString() + API_PATH);
post.setHeader("Content-Type", "application/json");
String newContactJSON = new JSONStringer().object().key("firstName").value(NEW_CONTACT_FIRSTNAME).key("lastName").value(NEW_CONTACT_LASTNAME).key("email").value(NEW_CONTACT_EMAIL).key("phoneNumber").value(NEW_CONTACT_PHONE).key("birthDate").value(NEW_CONTACT_BIRTHDATE).endObject().toString();
post.setEntity(new StringEntity(newContactJSON));
HttpResponse response = httpClient.execute(post);
assertEquals(201, response.getStatusLine().getStatusCode());
}
use of org.json.JSONStringer in project quickstart by wildfly.
the class RESTTest method testAddMember.
@Test
@InSequence(2)
public void testAddMember() throws Exception {
HttpPost post = new HttpPost(contextPath.toString() + API_PATH);
post.setHeader("Content-Type", "application/json");
String newMemberJSON = new JSONStringer().object().key("name").value(NEW_MEMBER_NAME).key("email").value(NEW_MEMBER_EMAIL).key("phoneNumber").value(NEW_MEMBER_PHONE).endObject().toString();
post.setEntity(new StringEntity(newMemberJSON));
HttpResponse response = httpClient.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
}
Aggregations