Add test for Java API built from generated reviewdb.proto

Change-Id: I819954da56ad39845f2439ff6502dbb82f50f34c
This commit is contained in:
Dave Borowitz 2018-08-07 09:14:09 -07:00
parent c5fada5121
commit de020cef59
4 changed files with 67 additions and 0 deletions

View File

@ -3,6 +3,7 @@ java_binary(
srcs = ["ProtoGen.java"], srcs = ["ProtoGen.java"],
resource_strip_prefix = "resources", resource_strip_prefix = "resources",
resources = ["//resources/com/google/gerrit/proto"], resources = ["//resources/com/google/gerrit/proto"],
visibility = ["//proto:__pkg__"],
deps = [ deps = [
"//java/com/google/gerrit/reviewdb:server", "//java/com/google/gerrit/reviewdb:server",
"//lib:args4j", "//lib:args4j",

View File

@ -0,0 +1,17 @@
load("//tools/bzl:junit.bzl", "junit_tests")
junit_tests(
name = "proto_tests",
srcs = glob(["*.java"]),
deps = [
"//lib/truth:truth-proto-extension",
"//proto:reviewdb_java_proto",
# TODO(dborowitz): These are already runtime_deps of
# truth-proto-extension, but either omitting them or adding them as
# runtime_deps to this target fails with:
# class file for com.google.common.collect.Multimap not found
"//lib:guava",
"//lib/truth",
],
)

View File

@ -0,0 +1,31 @@
// Copyright (C) 2018 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.proto;
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
import com.google.gerrit.proto.reviewdb.Reviewdb.Change;
import com.google.gerrit.proto.reviewdb.Reviewdb.Change_Id;
import org.junit.Test;
public class ReviewDbProtoTest {
@Test
public void generatedProtoApi() {
Change c1 = Change.newBuilder().setChangeId(Change_Id.newBuilder().setId(1234).build()).build();
Change c2 = Change.newBuilder().setChangeId(Change_Id.newBuilder().setId(5678).build()).build();
assertThat(c1).isEqualTo(c1);
assertThat(c1).isNotEqualTo(c2);
}
}

View File

@ -8,3 +8,21 @@ java_proto_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [":cache_proto"], deps = [":cache_proto"],
) )
genrule(
name = "gen_reviewdb_proto",
outs = ["reviewdb.proto"],
cmd = "$(location //java/com/google/gerrit/proto:ProtoGen) -o $@",
tools = ["//java/com/google/gerrit/proto:ProtoGen"],
)
proto_library(
name = "reviewdb_proto",
srcs = [":reviewdb.proto"],
)
java_proto_library(
name = "reviewdb_java_proto",
visibility = ["//javatests/com/google/gerrit/proto:__pkg__"],
deps = [":reviewdb_proto"],
)