

package com.restfb;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.restfb.types.Post;

/**
 * Facebook can return Post comment fields as an empty array instead of an empty object. These tests ensure our JSON
 * mapper correctly handles the different forms of comments FB supports.
 * 
 * @author <a href="http://restfb.com">Mark Allen</a>
 * @since 1.5.4
 */
public class SpecialCommentHandlingTest extends AbstractJsonMapperTests {
  /**
   * Can we handle comments that are empty arrays?
   */
  @Test
  public void emptyArrayTest() {
    Post post = createJsonMapper().toJavaObject(jsonFromClasspath("post-with-empty-comments"), Post.class);
    assertTrue(post.getComments().getTotalCount() == 0);
    assertTrue(post.getComments().getData().size() == 0);
  }

  /**
   * Can we handle comments that are objects with only a count and no data?
   */
  @Test
  public void onlyCountTest() {
    Post post = createJsonMapper().toJavaObject(jsonFromClasspath("post-with-comment-count-only"), Post.class);
    assertTrue(post.getComments().getTotalCount() == 3);
  }

  /**
   * Can we handle comments that are objects with only a count and no data?
   */
  @Test
  public void normalTest() {
    Post post = createJsonMapper().toJavaObject(jsonFromClasspath("post-with-normal-comments"), Post.class);
    assertTrue(post.getComments().getData().size() == 1);
  }
}