Add unit tests for Comment.Range#isValid
In order to use the RangeSubject within gerrit-extension-api as well as gerrit-acceptance-tests, a new Bazel/Buck package is introduced. The purpose of this package is to bundle test helper classes which are shared by different packages. Change-Id: I59aa42d89c06f4de60a2a05d41a72653eba268de
This commit is contained in:
@@ -18,6 +18,7 @@ java_library(
|
||||
'//gerrit-server:testutil',
|
||||
'//gerrit-server/src/main/prolog:common',
|
||||
'//gerrit-sshd:sshd',
|
||||
'//gerrit-test-util:test_util',
|
||||
|
||||
'//lib:args4j',
|
||||
'//lib:gson',
|
||||
|
@@ -21,6 +21,7 @@ java_library2(
|
||||
"//gerrit-server:testutil",
|
||||
"//gerrit-server/src/main/prolog:common",
|
||||
"//gerrit-sshd:sshd",
|
||||
"//gerrit-test-util:test_util",
|
||||
"//lib:args4j",
|
||||
"//lib:gson",
|
||||
"//lib:gwtjsonrpc",
|
||||
|
@@ -21,7 +21,7 @@ import com.google.common.truth.StringSubject;
|
||||
import com.google.common.truth.Subject;
|
||||
import com.google.common.truth.SubjectFactory;
|
||||
import com.google.common.truth.Truth;
|
||||
import com.google.gerrit.acceptance.RangeSubject;
|
||||
import com.google.gerrit.extensions.client.RangeSubject;
|
||||
import com.google.gerrit.extensions.common.FixReplacementInfo;
|
||||
|
||||
public class FixReplacementInfoSubject
|
||||
|
@@ -61,9 +61,10 @@ java_sources(
|
||||
|
||||
java_test(
|
||||
name = 'api_tests',
|
||||
srcs = glob(['src/test/java/**/*.java']),
|
||||
srcs = glob(['src/test/java/**/*Test.java']),
|
||||
deps = [
|
||||
':api',
|
||||
'//gerrit-test-util:test_util',
|
||||
'//lib:truth',
|
||||
'//lib/guice:guice',
|
||||
],
|
||||
|
@@ -1,6 +1,7 @@
|
||||
load("//lib:guava.bzl", "GUAVA_DOC_URL")
|
||||
load("//lib/jgit:jgit.bzl", "JGIT_DOC_URL")
|
||||
load("//tools/bzl:gwt.bzl", "gwt_module")
|
||||
load("//tools/bzl:junit.bzl", "junit_tests")
|
||||
|
||||
SRC = "src/main/java/com/google/gerrit/extensions/"
|
||||
|
||||
@@ -48,6 +49,17 @@ java_library(
|
||||
],
|
||||
)
|
||||
|
||||
junit_tests(
|
||||
name = "api_tests",
|
||||
srcs = glob(["src/test/java/**/*Test.java"]),
|
||||
deps = [
|
||||
":api",
|
||||
"//gerrit-test-util:test_util",
|
||||
"//lib:truth",
|
||||
"//lib/guice",
|
||||
],
|
||||
)
|
||||
|
||||
load("//tools/bzl:javadoc.bzl", "java_doc")
|
||||
|
||||
java_doc(
|
||||
|
@@ -0,0 +1,87 @@
|
||||
// Copyright (C) 2016 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.extensions.client;
|
||||
|
||||
|
||||
import static com.google.gerrit.extensions.client.RangeSubject.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RangeTest {
|
||||
|
||||
@Test
|
||||
public void rangeOverMultipleLinesWithSmallerEndCharacterIsValid() {
|
||||
Comment.Range range = createRange(13, 31, 19, 10);
|
||||
assertThat(range).isValid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rangeInOneLineIsValid() {
|
||||
Comment.Range range = createRange(13, 2, 13, 10);
|
||||
assertThat(range).isValid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startPositionEqualToEndPositionIsValidRange() {
|
||||
Comment.Range range = createRange(13, 11, 13, 11);
|
||||
assertThat(range).isValid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeStartLineResultsInInvalidRange() {
|
||||
Comment.Range range = createRange(-1, 2, 19, 10);
|
||||
assertThat(range).isInvalid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeEndLineResultsInInvalidRange() {
|
||||
Comment.Range range = createRange(13, 2, -1, 10);
|
||||
assertThat(range).isInvalid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeStartCharacterResultsInInvalidRange() {
|
||||
Comment.Range range = createRange(13, -1, 19, 10);
|
||||
assertThat(range).isInvalid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeEndCharacterResultsInInvalidRange() {
|
||||
Comment.Range range = createRange(13, 2, 19, -1);
|
||||
assertThat(range).isInvalid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startLineGreaterThanEndLineResultsInInvalidRange() {
|
||||
Comment.Range range = createRange(20, 2, 19, 10);
|
||||
assertThat(range).isInvalid();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startCharGreaterThanEndCharForSameLineResultsInInvalidRange() {
|
||||
Comment.Range range = createRange(13, 11, 13, 10);
|
||||
assertThat(range).isInvalid();
|
||||
}
|
||||
|
||||
private Comment.Range createRange(int startLine, int startCharacter,
|
||||
int endLine, int endCharacter) {
|
||||
Comment.Range range = new Comment.Range();
|
||||
range.startLine = startLine;
|
||||
range.startCharacter = startCharacter;
|
||||
range.endLine = endLine;
|
||||
range.endCharacter = endCharacter;
|
||||
return range;
|
||||
}
|
||||
}
|
9
gerrit-test-util/BUCK
Normal file
9
gerrit-test-util/BUCK
Normal file
@@ -0,0 +1,9 @@
|
||||
java_library(
|
||||
name = 'test_util',
|
||||
srcs = glob(['src/main/java/**/*.java']),
|
||||
visibility = ['PUBLIC'],
|
||||
deps = [
|
||||
'//gerrit-extension-api:api',
|
||||
'//lib:truth',
|
||||
],
|
||||
)
|
10
gerrit-test-util/BUILD
Normal file
10
gerrit-test-util/BUILD
Normal file
@@ -0,0 +1,10 @@
|
||||
java_library(
|
||||
name = "test_util",
|
||||
testonly = 1,
|
||||
srcs = glob(["src/main/java/**/*.java"]),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//gerrit-extension-api:api",
|
||||
"//lib:truth",
|
||||
],
|
||||
)
|
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
package com.google.gerrit.extensions.client;
|
||||
|
||||
import static com.google.common.truth.Truth.assertAbout;
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.common.truth.IntegerSubject;
|
||||
import com.google.common.truth.Subject;
|
||||
import com.google.common.truth.SubjectFactory;
|
||||
import com.google.common.truth.Truth;
|
||||
import com.google.gerrit.extensions.client.Comment;
|
||||
|
||||
public class RangeSubject extends Subject<RangeSubject, Comment.Range> {
|
||||
|
||||
@@ -59,4 +58,18 @@ public class RangeSubject extends Subject<RangeSubject, Comment.Range> {
|
||||
public IntegerSubject endCharacter() {
|
||||
return Truth.assertThat(actual().endCharacter).named("endCharacter");
|
||||
}
|
||||
|
||||
public void isValid() {
|
||||
isNotNull();
|
||||
if (!actual().isValid()) {
|
||||
fail("is valid");
|
||||
}
|
||||
}
|
||||
|
||||
public void isInvalid() {
|
||||
isNotNull();
|
||||
if (actual().isValid()) {
|
||||
fail("is invalid");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user