Skip to content

Commit

Permalink
Adds some proto3 java tests for Empty (square#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod authored Jul 17, 2020
1 parent 1e0e2b6 commit 303e04b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2020 Square Inc.
*
* 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.
*/
syntax = "proto3";
package squareup.proto3.java.alltypes;

import "google/protobuf/empty.proto";

message AllEmpty {
google.protobuf.Empty empty = 1;

repeated google.protobuf.Empty rep_empty = 201;

oneof choice {
google.protobuf.Empty oneof_empty = 402;
}

map<int32, google.protobuf.Empty> map_int32_empty = 501;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import squareup.proto3.kotlin.alltypes.AllEmptyOuterClass
import squareup.proto3.kotlin.alltypes.AllEmpty as AllEmptyK
import squareup.proto3.java.alltypes.AllEmpty as AllEmptyJ

class EmptyRoundTripTest {
@Test fun empty() {
Expand All @@ -42,18 +43,30 @@ class EmptyRoundTripTest {
.setOneofEmpty(Empty.newBuilder().build())
.build()

val wireMessage = AllEmptyK(
val wireMessageJava = AllEmptyJ.Builder()
.empty(Unit)
.rep_empty(listOf(Unit, Unit))
.map_int32_empty(mapOf(1 to Unit))
.oneof_empty(Unit)
.build()

val wireMessageKotlin = AllEmptyK(
empty = Unit,
rep_empty = listOf(Unit, Unit),
map_int32_empty = mapOf(1 to Unit),
oneof_empty = Unit
)

val googleMessageBytes = googleMessage.toByteArray()
val wireMessageBytes = AllEmptyK.ADAPTER.encode(wireMessage)
assertThat(AllEmptyOuterClass.AllEmpty.parseFrom(wireMessageBytes)).isEqualTo(googleMessage)
assertThat(AllEmptyK.ADAPTER.decode(wireMessageBytes)).isEqualTo(wireMessage)
assertThat(AllEmptyK.ADAPTER.decode(googleMessageBytes)).isEqualTo(wireMessage)
assertThat(AllEmptyK.ADAPTER.encodedSize(wireMessage)).isEqualTo(googleMessageBytes.size)
val wireMessageJavaBytes = AllEmptyJ.ADAPTER.encode(wireMessageJava)
assertThat(AllEmptyOuterClass.AllEmpty.parseFrom(wireMessageJavaBytes)).isEqualTo(googleMessage)
assertThat(AllEmptyJ.ADAPTER.decode(wireMessageJavaBytes)).isEqualTo(wireMessageJava)
assertThat(AllEmptyJ.ADAPTER.decode(googleMessageBytes)).isEqualTo(wireMessageJava)
assertThat(AllEmptyJ.ADAPTER.encodedSize(wireMessageJava)).isEqualTo(googleMessageBytes.size)
val wireMessageKotlinBytes = AllEmptyK.ADAPTER.encode(wireMessageKotlin)
assertThat(AllEmptyOuterClass.AllEmpty.parseFrom(wireMessageKotlinBytes)).isEqualTo(googleMessage)
assertThat(AllEmptyK.ADAPTER.decode(wireMessageKotlinBytes)).isEqualTo(wireMessageKotlin)
assertThat(AllEmptyK.ADAPTER.decode(googleMessageBytes)).isEqualTo(wireMessageKotlin)
assertThat(AllEmptyK.ADAPTER.encodedSize(wireMessageKotlin)).isEqualTo(googleMessageBytes.size)
}
}

0 comments on commit 303e04b

Please sign in to comment.