Skip to content

Commit

Permalink
merge and test #67
Browse files Browse the repository at this point in the history
  • Loading branch information
roundrop committed Oct 13, 2014
1 parent c41f353 commit 3290a90
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 37 deletions.
4 changes: 2 additions & 2 deletions facebook4j-core/src/main/java/facebook4j/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package facebook4j;

import java.util.ArrayList;
import java.util.List;

/**
* @author Ryuji Yamashita - roundrop at gmail.com
*/
public interface Place extends FacebookResponse {
String getId();
String getName();
ArrayList<Category> getCategories();
List<Category> getCategories();
Place.Location getLocation();

interface Location {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package facebook4j.internal.json;

import static facebook4j.internal.util.z_F4JInternalParseUtil.*;

import java.util.Date;

import facebook4j.Category;
import facebook4j.FacebookException;
import facebook4j.conf.Configuration;
import facebook4j.internal.http.HttpResponse;
import facebook4j.internal.org.json.JSONObject;

import java.util.Date;

import static facebook4j.internal.util.z_F4JInternalParseUtil.*;

/**
* @author Ryuji Yamashita - roundrop at gmail.com
*/
Expand Down Expand Up @@ -101,7 +101,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return "CategorizedEntityJSONImpl [id=" + id + ", name=" + name + ", category="
return "CategoryJSONImpl [id=" + id + ", name=" + name + ", category="
+ category + ", createdTime=" + createdTime + "]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

package facebook4j.internal.json;

import facebook4j.Category;
import facebook4j.FacebookException;
import facebook4j.Place;
import facebook4j.Category;
import facebook4j.internal.json.CategoryJSONImpl;
import facebook4j.ResponseList;
import facebook4j.conf.Configuration;
import facebook4j.internal.http.HttpResponse;
import facebook4j.internal.org.json.JSONArray;
import facebook4j.internal.org.json.JSONException;
import facebook4j.internal.org.json.JSONObject;

import static facebook4j.internal.util.z_F4JInternalParseUtil.*;

import java.util.ArrayList;
import java.util.List;

import static facebook4j.internal.util.z_F4JInternalParseUtil.*;

/**
* @author Ryuji Yamashita - roundrop at gmail.com
Expand All @@ -39,7 +39,7 @@

private String id;
private String name;
private ArrayList<Category> categories;
private List<Category> categories;
private Place.Location location;

/*package*/PlaceJSONImpl(HttpResponse res, Configuration conf) throws FacebookException {
Expand All @@ -65,7 +65,6 @@ private void init(JSONObject json) throws FacebookException {
if (isJSONArray("category_list", json)) {
JSONArray categoriesJSONArray = json.getJSONArray("category_list");
categories = new ArrayList<Category>();

for (int i = 0; i < categoriesJSONArray.length(); i++) {
categories.add(new CategoryJSONImpl(categoriesJSONArray.getJSONObject(i)));
}
Expand All @@ -90,31 +89,10 @@ public String getName() {
return name;
}

public ArrayList<Category> getCategories() {
public List<Category> getCategories() {
return categories;
}

public String getCategoriesToString() {

String listString = null;

if(categories != null)
{
listString = "[";

for (int i = 0; i < categories.size(); i++)
{
Category c = categories.get(i);
listString += c;
if (i != categories.size() - 1) listString += ", ";
}

listString += "]";
}

return listString;
}

public Location getLocation() {
return location;
}
Expand Down Expand Up @@ -173,8 +151,12 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return "PlaceJSONImpl [id=" + id + ", name=" + name + ", location="
+ location + ", categories=" + getCategoriesToString() + "]";
return "PlaceJSONImpl{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", categories=" + categories +
", location=" + location +
'}';
}

/*package*/ static final class LocationJSONImpl implements Location, java.io.Serializable {
Expand Down
21 changes: 21 additions & 0 deletions facebook4j-core/src/test/java/facebook4j/SearchMethodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ public void geoLocation_reading() throws Exception {
assertThat(actual5.getLocation().getCity(), is("San Francisco"));
assertThat(actual5.getName(), is("Peets Coffee, Castro Dist."));
}

@Test
public void categories() throws Exception {
facebook.setMockJSON("mock_json/search/places_with_categories.json");
GeoLocation geoLocation = new GeoLocation(37.7793, -122.419);
int distance = 1000;
ResponseList<Place> actuals = facebook.searchPlaces("San Francisco, California", geoLocation, distance);

Place place1 = actuals.get(0);
assertThat(place1.getCategories().size(), is(1));
assertThat(place1.getCategories().get(0).getId(), is("224455390913969"));
assertThat(place1.getCategories().get(0).getName(), is("City"));
Place place3 = actuals.get(2);
assertThat(place3.getCategories().size(), is(3));
assertThat(place3.getCategories().get(0).getId(), is("115725465228008"));
assertThat(place3.getCategories().get(0).getName(), is("Region"));
assertThat(place3.getCategories().get(1).getId(), is("407338945943828"));
assertThat(place3.getCategories().get(1).getName(), is("River"));
assertThat(place3.getCategories().get(2).getId(), is("215492291888288"));
assertThat(place3.getCategories().get(2).getName(), is("Ocean"));
}
}

public static class searchCheckins extends MockFacebookTestBase {
Expand Down

0 comments on commit 3290a90

Please sign in to comment.