Package com.pawelmaslyk.gerritintegration4sonar.gerrit

Source Code of com.pawelmaslyk.gerritintegration4sonar.gerrit.GerritCommandTest

package com.pawelmaslyk.gerritintegration4sonar.gerrit;

import static org.mockito.Mockito.*;

import static org.junit.Assert.*;

import org.junit.Test;

import com.pawelmaslyk.gerritintegration4sonar.sonar.SonarAnalysisResult;
import com.pawelmaslyk.gerritintegration4sonar.sonar.SonarAnalysisStatus;

public class GerritCommandTest {

  @Test
  public void testApprovalWithPositiveValue() {
    // given
    GerritCommit commit = mock(GerritCommit.class);

    // when
    when(commit.getProjectName()).thenReturn("projectname");
    when(commit.getChange()).thenReturn("1");
    when(commit.getPatch()).thenReturn("2");
    String command = GerritCommand.createCodeReview(commit, new SonarAnalysisResult("Sonar analysis",
        SonarAnalysisStatus.NO_PROBLEMS));

    // then
    assertEquals("gerrit approve --project projectname --message \"Sonar analysis\" --code-review 1 1,2", command);
  }

  @Test
  public void testApprovalWithWarning() {
    // given
    GerritCommit commit = mock(GerritCommit.class);

    // when
    when(commit.getProjectName()).thenReturn("projectname");
    when(commit.getChange()).thenReturn("1");
    when(commit.getPatch()).thenReturn("2");
    String command = GerritCommand.createCodeReview(commit, new SonarAnalysisResult("Some\n message",
        SonarAnalysisStatus.WARNINGS));

    // then
    assertEquals("gerrit approve --project projectname --message \"Some\n message\" --code-review -1 1,2", command);
  }

  @Test
  public void testApprovalWithError() {
    // given
    GerritCommit commit = mock(GerritCommit.class);

    // when
    when(commit.getProjectName()).thenReturn("projectname");
    when(commit.getChange()).thenReturn("1");
    when(commit.getPatch()).thenReturn("2");
    String command = GerritCommand.createCodeReview(commit, new SonarAnalysisResult("Error message",
        SonarAnalysisStatus.ERRORS));

    // then
    assertEquals("gerrit approve --project projectname --message \"Error message\" --code-review -2 1,2", command);
  }

}
TOP

Related Classes of com.pawelmaslyk.gerritintegration4sonar.gerrit.GerritCommandTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.