Skip to content

Commit

Permalink
JSON writing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMkrage committed Jun 18, 2017
1 parent 74c6dc6 commit cd386bf
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 197 deletions.
14 changes: 14 additions & 0 deletions src/codeu/chat/server/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import codeu.chat.common.Message;
import codeu.chat.common.User;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
Expand Down Expand Up @@ -106,6 +108,18 @@ private void save(Object obj, String arrayName) {
e.printStackTrace();
}
}

/**
* Used to erase all saved content and place a blank array
*/
public void clearFile() {
JsonNode blankNode = createNodeWithBlankArrays();
try {
new ObjectMapper().writer(new DefaultPrettyPrinter()).writeValue(new File(fileName), blankNode);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Appends a user to the json file
Expand Down
19 changes: 19 additions & 0 deletions test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"users" : [ {
"name" : "Krager",
"uuid" : "1.1074501217",
"creationTime" : "31-Dec-1969 17:11:49.509"
} ],
"conversations" : [ {
"title" : "Chat1",
"uuid" : "1.3959833157",
"ownerUUID" : "1.1074501217",
"creationTime" : "01-Jan-1970 08:30:08.509"
} ],
"messages" : [ {
"content" : "I'm so alone",
"authorUUID" : "1.1074501217",
"uuid" : "1.3928689216",
"creationTime" : "01-Jan-1970 05:46:24.908"
} ]
}
Loading

0 comments on commit cd386bf

Please sign in to comment.