// Copyright (C) 2014 The Android Open Source Project
//
// 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.gerrit.acceptance.rest.change;

import static org.junit.Assert.assertEquals;

import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeStatus;
import com.google.gerrit.server.change.ChangeJson;

import org.apache.http.HttpStatus;
import org.junit.Test;

public class CreateChangeIT extends AbstractDaemonTest {

  @Test
  public void createEmptyChange_MissingBranch() throws Exception {
    ChangeInfo ci = new ChangeInfo();
    ci.project = project.get();
    RestResponse r = adminSession.post("/changes/", ci);
    assertEquals(HttpStatus.SC_BAD_REQUEST, r.getStatusCode());
    r.getEntityContent().contains("branch must be non-empty");
  }

  @Test
  public void createEmptyChange_MissingMessage() throws Exception {
    ChangeInfo ci = new ChangeInfo();
    ci.project = project.get();
    ci.branch = "master";
    RestResponse r = adminSession.post("/changes/", ci);
    assertEquals(HttpStatus.SC_BAD_REQUEST, r.getStatusCode());
    r.getEntityContent().contains("commit message must be non-empty");
  }

  @Test
  public void createEmptyChange_InvalidStatus() throws Exception {
    ChangeInfo ci = newChangeInfo(ChangeStatus.SUBMITTED);
    RestResponse r = adminSession.post("/changes/", ci);
    assertEquals(HttpStatus.SC_BAD_REQUEST, r.getStatusCode());
    r.getEntityContent().contains("unsupported change status");
  }

  @Test
  public void createNewChange() throws Exception {
    assertChange(newChangeInfo(ChangeStatus.NEW));
  }

  @Test
  public void createDraftChange() throws Exception {
    assertChange(newChangeInfo(ChangeStatus.DRAFT));
  }

  private ChangeInfo newChangeInfo(ChangeStatus status) {
    ChangeInfo in = new ChangeInfo();
    in.project = project.get();
    in.branch = "master";
    in.subject = "Empty change";
    in.topic = "support-gerrit-workflow-in-browser";
    in.status = status;
    return in;
  }

  private void assertChange(ChangeInfo in) throws Exception {
    RestResponse r = adminSession.post("/changes/", in);
    assertEquals(HttpStatus.SC_CREATED, r.getStatusCode());

    ChangeJson.ChangeInfo info = newGson().fromJson(r.getReader(),
        ChangeJson.ChangeInfo.class);
    ChangeInfo out = get(info.changeId);

    assertEquals(in.branch, out.branch);
    assertEquals(in.subject, out.subject);
    assertEquals(in.topic, out.topic);
    assertEquals(in.status, out.status);
  }
}

@@ -697,16 +697,59 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -1391,32 +1391,43 @@
 tusCode());%0A    
+assertTrue(
 r.getEntityConte
@@ -1459,32 +1459,33 @@
 t be non-empty%22)
+)
 ;%0A  %7D%0A%0A  @Test%0A 
@@ -1764,32 +1764,43 @@
 tusCode());%0A    
+assertTrue(
 r.getEntityConte
@@ -1848,16 +1848,17 @@
 -empty%22)
+)
 ;%0A  %7D%0A%0A 
@@ -2115,16 +2115,27 @@
 ));%0A    
+assertTrue(
 r.getEnt
@@ -2184,16 +2184,17 @@
 status%22)
+)
 ;%0A  %7D%0A%0A 

Add missing calls to `assertTrue` in CreateChangeIT