Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wegrata committed Jun 5, 2014
1 parent 1379e54 commit 23641f2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/gov/adlnet/xapi/ActorAdapterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gov.adlnet.xapi;

import gov.adlnet.xapi.model.Actor;
import gov.adlnet.xapi.model.Agent;
import gov.adlnet.xapi.model.Group;
import gov.adlnet.xapi.model.IStatementObject;
import gov.adlnet.xapi.model.adapters.ActorAdapter;
import gov.adlnet.xapi.model.adapters.StatementObjectAdapter;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import junit.framework.TestCase;

public class ActorAdapterTest extends TestCase {
private Gson gson;
public ActorAdapterTest(){
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Actor.class, new ActorAdapter());
gson = builder.create();
}
public void testDeserializeActor() {
String data = "{\"mbox\": \"mailto:[email protected]\",\"name\": \"test user\",\"objectType\": \"Agent\"}";
Actor a = gson.fromJson(data, Actor.class);
assert a.getClass() == Agent.class;
}
public void testDeserializeActorNoType() {
String data = "{\"mbox\": \"mailto:[email protected]\",\"name\": \"test user\"}";
Actor a = gson.fromJson(data, Actor.class);
assert a.getClass() == Agent.class;
}
public void testDeserializeActorGroup() {
String data = "{\"mbox\": \"mailto:[email protected]\",\"name\": \"test user\",\"objectType\": \"Group\"}";
Actor a = gson.fromJson(data, Actor.class);
assert a.getClass() == Group.class;
}
}
31 changes: 31 additions & 0 deletions src/test/java/gov/adlnet/xapi/StatementAdapterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gov.adlnet.xapi;

import gov.adlnet.xapi.model.Actor;
import gov.adlnet.xapi.model.Agent;
import gov.adlnet.xapi.model.IStatementObject;
import gov.adlnet.xapi.model.Statement;
import gov.adlnet.xapi.model.Verbs;
import gov.adlnet.xapi.model.adapters.*;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import junit.framework.TestCase;

public class StatementAdapterTest extends TestCase {
private String testString = "{\"actor\":{\"mbox\":\"mailto:[email protected]\"}, \"verb\":{\"id\":\"http://adlnet.gov/expapi/verbs/asked\"}, \"object\":{\"id\":\"q://do/you/like/green-eggs-n-ham\"}}";

private Gson gson;
public StatementAdapterTest(){
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Actor.class, new ActorAdapter());
builder.registerTypeAdapter(IStatementObject.class, new StatementObjectAdapter());
gson = builder.create();
}
public void testDeserializeStatement() {
Statement a = gson.fromJson(testString, Statement.class);
assert a.getActor().getClass() == Agent.class;
assert a.getActor().getMbox().equals("mailto:[email protected]");
assert a.getVerb().getId().equals("http://adlnet.gov/expapi/verbs/asked");
}
}

0 comments on commit 23641f2

Please sign in to comment.