/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.api.server.spi.response;

import static junit.framework.Assert.assertEquals;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.springframework.mock.web.MockHttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Tests of {@link CollectionResponse}.
 */
@RunWith(JUnit4.class)
public class CollectionResponseTest {

  private static class Bean {
    @SuppressWarnings("unused")
    public int getDummy() {
      return 0;
    }
  }

  @Test
  public void testCollectionResponse() throws IOException {
    MockHttpServletResponse servletResponse = new MockHttpServletResponse();
    ServletResponseResultWriter writer = new ServletResponseResultWriter(servletResponse, null);
    writer.write(getBeans(2));

    ObjectNode json = new ObjectMapper().readValue(
        servletResponse.getContentAsString(), ObjectNode.class);
    assertEquals(2, json.path("items").size());
    assertEquals("next", json.path("nextPageToken").asText());
  }

  private CollectionResponse<Bean> getBeans(int beanCount) {
    List<Bean> beans = new ArrayList<Bean>();
    for (int i = 0; i < beanCount; i++) {
      beans.add(new Bean());
    }
    return CollectionResponse.<Bean>builder()
        .setItems(beans)
        .setNextPageToken("next")
        .build();
  }
}

@@ -672,43 +672,48 @@
 tic 
-junit.framework.Assert
+com.google.common.truth.Truth
 .assert
-Equals
+That
 ;%0A%0Ai
@@ -1682,18 +1682,13 @@
 sert
-Equals(2, 
+That(
 json
@@ -1705,15 +1705,19 @@
 ms%22)
-.s
+).hasS
 ize(
-)
+2
 );%0A 
@@ -1729,23 +1729,13 @@
 sert
-Equals(%22next%22, 
+That(
 json
@@ -1766,16 +1766,34 @@
 sText())
+.isEqualTo(%22next%22)
 ;%0A  %7D%0A%0A 

remove old JUnit assertEquals