package com.github.ggeorgovassilis.springjsonmapper.googlebooks;

import org.junit.runner.RunWith;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.*;

/**
 * Integration test with the google books API
 * @author george georgovassilis
 */
@RunWith(value=SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-context-googlebooks.xml")
public class GoogleBooksApiTest {

    @Autowired
    BookService bookService;

    @Test
    public void testFindBooksByTitle(){
	QueryResult result = bookService.findBooksByTitle("\"Philosophiae naturalis principia mathematica\"");
	assertTrue(result.getItems().size()>0);
	VolumeInfo info = result.getItems().get(0).getVolumeInfo();
	assertEquals("Philosophiae naturalis principia mathematica", info.getTitle());
	assertEquals("Isaac Newton", info.getAuthors().get(0));
    }

    @Test
    public void testFindBooksByid(){
	Item item = bookService.findBookById("3h9_GY8v-hgC");
	VolumeInfo info = item.getVolumeInfo();
	assertEquals("Philosophiae naturalis principia mathematica", info.getTitle());
	assertEquals("Isaac Newton", info.getAuthors().get(0));
    }

}

@@ -449,17 +449,19 @@
 th(value
-=
+ = 
 SpringJU
@@ -582,20 +582,17 @@
 Test %7B%0A%0A
-    
+%09
 @Autowir
@@ -594,20 +594,17 @@
 towired%0A
-    
+%09
 BookServ
@@ -621,30 +621,24 @@
 rvice;%0A%0A
-    
+%09
 @Test%0A
-    
+%09
 public v
@@ -663,18 +663,20 @@
 yTitle()
+ 
 %7B%0A
+%09
 %09QueryRe
@@ -771,16 +771,17 @@
 ca%5C%22%22);%0A
+%09
 %09assertT
@@ -812,56 +812,105 @@
 ze()
-%3E
+ %3E 
 0);%0A%09
-VolumeInfo info = result.getItems().get(0)
+%09boolean found = false;%0A%09%09for (Item item : result.getItems()) %7B%0A%09%09%09VolumeInfo info = item
 .get
@@ -920,36 +920,35 @@
 umeInfo();%0A%09
-assertEquals
+%09%09found %7C= 
 (%22Philosophi
@@ -974,34 +974,40 @@
 pia mathematica%22
-, 
+.equals(
 info.getTitle())
@@ -1006,32 +1006,20 @@
 Title())
-;%0A%09assertEquals(
+ && 
 %22Isaac N
@@ -1016,34 +1016,40 @@
 & %22Isaac Newton%22
-, 
+.equals(
 info.getAuthors(
@@ -1045,32 +1045,38 @@
 getAuthors()
+%0A%09%09%09%09%09
 .get(0))
 ;%0A    %7D%0A%0A   
@@ -1067,31 +1067,48 @@
 (0))
+)
 ;%0A
-    %7D%0A%0A    
+%09%09%7D%0A%09%09assertTrue(found);%0A%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 publ
@@ -1134,18 +1134,20 @@
 ksByid()
+ 
 %7B%0A
+%09
 %09Item it
@@ -1193,16 +1193,17 @@
 -hgC%22);%0A
+%09
 %09VolumeI
@@ -1235,16 +1235,17 @@
 Info();%0A
+%09
 %09assertE
@@ -1316,16 +1316,17 @@
 tle());%0A
+%09
 %09assertE
@@ -1378,12 +1378,9 @@
 ));%0A
-    
+%09
 %7D%0A%0A%7D

Test more robust to changing result order