package com.worizon.junit.jsonresponse;

import static org.junit.Assert.*;

import org.junit.Test;

import com.worizon.jsonrpc.JsonRpcResponse;

public class JsonRpcObjectResponseTest {
	
	class Foo{
		
		int dni;
		String name;
		String surname;
		float height;
		
		public Foo( int dni, String name, String surname, float height){
			
			this.dni = dni;
			this.name = name;
			this.surname = surname;
			this.height = height;
		}
		
		public boolean equals( Object obj ){
			Foo foo = (Foo)obj;
			return dni == foo.dni && name.equals(foo.name) && surname.equals(foo.surname) && height == foo.height;
		}
	}

	@Test
	public void testResult() throws Exception {
		
		String message = "{\"jsonrpc\": \"2.0\", \"result\": {\"dni\":46579878,\"name\":\"Enric\",\"surname\":\"Cecilla\",\"height\":1.72}, \"id\": 77684}";		
		JsonRpcResponse<Foo> res = new JsonRpcResponse<Foo>(message, Foo.class);		
		
		Foo result = res.getResult();						
		Foo expected = new Foo(46579878,"Enric","Cecilla",1.72f);
		
		assertEquals( expected, result);
		assertNull(res.getError());
		
		
	}
	
	@Test
	public void testNull() throws Exception{
		
		String message = "{\"jsonrpc\": \"2.0\", \"result\": null, \"id\": 77684}";		
		JsonRpcResponse<Foo> res = new JsonRpcResponse<Foo>(message, Foo.class);
		
		assertNull(res.getResult());
	}
					
		
}

@@ -255,24 +255,44 @@
  height;%0A%09%09%0A
+%09%09public Foo()%7B%7D%0A%09%09%0A
 %09%09public Foo
@@ -346,16 +346,16 @@
 eight)%7B%0A
-
 %09%09%09%0A%09%09%09t
@@ -621,16 +621,77 @@
 ht;%0A%09%09%7D%0A
+%09%09%09%09%0A%09%7D%0A%09%0A%09class Bar extends Foo%7B%0A%09%09%0A%09%09public Bar()%7B%0A%09%09%09%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Te
@@ -1139,20 +1139,534 @@
 rror());
+%09%09
 %0A%09%09%0A
+%09%7D%0A%09%0A%09@Test%0A%09public void testResultExtendedObject() throws Exception %7B%0A%09%09%0A%09%09String message = %22%7B%5C%22jsonrpc%5C%22: %5C%222.0%5C%22, %5C%22result%5C%22: %7B%5C%22dni%5C%22:46579878,%5C%22name%5C%22:%5C%22Enric%5C%22,%5C%22surname%5C%22:%5C%22Cecilla%5C%22,%5C%22height%5C%22:1.72%7D, %5C%22id%5C%22: 77684%7D%22;%09%09%0A%09%09JsonRpcResponse%3CFoo%3E res = new JsonRpcResponse%3CFoo%3E(message, Bar.class);%09%09%0A%09%09%0A%09%09Foo result = res.getResult();%09%09%09%09%09%09%0A%09%09Foo expected = new Foo(46579878,%22Enric%22,%22Cecilla%22,1.72f);%09%09%0A%09%09assertEquals( expected, result);%0A%09%09assertNull(res.getError());%09%0A%09%09assertTrue( result instanceof Bar );%0A
 %09%09%0A%09%7D%0A%09%0A

test added to test for derived class object.