- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestJSONObject.java
More file actions
Latest commit
51 lines (39 loc) · 1.43 KB
/
Copy pathTestJSONObject.java
File metadata and controls
51 lines (39 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
importstaticorg.junit.Assert.*;
importorg.junit.Before;
importorg.junit.Test;
importorg.json.JSONException;
importorg.json.JSONObject;
importjava.io.BufferedReader;
importjava.io.FileReader;
importjava.io.File;
publicclassTestJSONObject {
privateStringjsonSource;
@Before
publicvoidsetUp() throwsException {
StringfixtName = "fixtures/post.json";
Filefile = newFile(fixtName);
FileReaderfr = newFileReader(file);
BufferedReaderbr = newBufferedReader(fr);
jsonSource = "";
Stringtext = null;
while ((text = br.readLine()) != null)
jsonSource += text;
}
@Test
publicvoidtestEmptyJsonReturnsAnEmptyJSONObject() throwsJSONException {
JSONObjecth = newJSONObject("{}");
assertEquals(0, h.length());
}
@Test
publicvoidtestAssinaturaJSON() throwsJSONException {
StringexpectedTitle = "My Test Post";
StringexpectedBody = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
JSONObjectpost = newJSONObject(jsonSource);
assertEquals(4, post.length());
assertEquals(123456789, post.getDouble("id"), 0);
assertEquals(expectedTitle, post.get("title"));
assertEquals(expectedBody, post.get("body"));
JSONObjectauthor = post.getJSONObject("author");
assertEquals("John", author.get("name"));
}
}