i have a test class for salesforce
@IsTest
public class JsonGCloudApiApex_TEST {
// This test method should give 100% coveragex
static testMethod void testParse() {
JsonGCloudApiApex objItems;
List<JsonGCloudApiApex.Item> listItems;
JsonGCloudApiApex objItems2;
List<JsonGCloudApiApex.Item> listItems2;
String json = '{"items":[{"coverage": "test","name":"test","id":"test","contentType":"test","fileName":"test","updated":"test","generation":"test","mediaLink":"test"},{"coverage": "test", "name":"test","id":"test","contentType":"test","fileName":"test","updated":"test","generation":"test","mediaLink":"test"}, {"name":"test","id":"test","contentType":"test","fileName":"test","updated":"test","generation":"test","mediaLink":"test"}]}';
objItems = parse(json);
listItems = new List<JsonGCloudApiApex.Item>();
for(JsonGCloudApiApex.Item i : objItems.items){
i.timestamp = 16002;
System.assert(i.name != null);
System.assert(i.id != null);
System.assert(i.mediaLink != null);
System.assert(i.contentType != null);
System.assert(i.fileName != null);
System.assert(i.updated != null);
System.assert(i.timestamp != null);
}
listItems.sort();
}
static JsonGCloudApiApex parse(String json) {
return (JsonGCloudApiApex) System.JSON.deserialize(json, JsonGCloudApiApex.class);
}
}
and i have a my apex class
public class JsonGCloudApiApex {
public class Item implements Comparable{
public string name {get; set;}
public string id {get; set;}
public string mediaLink {get; set;}
public string contentType {get; set;}
public string fileName {get; set;}
public string updated {get; set;}
public string generation {get; set;}
public Integer timestamp {get; set;}
public Integer compareTo(Object other) {
return (Integer)(((Item)other).timestamp - this.timestamp);
}
}
public List<Item> items {get; set;}
public static JsonGCloudApiApex parse(String json) {
return (JsonGCloudApiApex) System.JSON.deserialize(json, JsonGCloudApiApex.class);
}
}
On my salesforce page i see 61% (8/13) code coverage, but i don't know what another extra assert add to my test class up to 75% coverage code any idea?
JsonGCloudApiApex.parse()
, so it won't be covered.