1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 package com.google.protobuf.kotlin 9 10 import com.google.common.truth.Truth.assertThat 11 import com.google.protobuf.Any as ProtoAny 12 import com.google.protobuf.InvalidProtocolBufferException 13 import protobuf_unittest.UnittestProto.BoolMessage 14 import protobuf_unittest.UnittestProto.Int32Message 15 import protobuf_unittest.int32Message 16 import kotlin.test.assertFailsWith 17 import org.junit.Test 18 import org.junit.runner.RunWith 19 import org.junit.runners.JUnit4 20 21 /** Tests for extension methods on [ProtoAny]. */ 22 @RunWith(JUnit4::class) 23 class AniesTest { 24 companion object { <lambda>null25 val anAny = ProtoAny.pack(int32Message { data = 5 }) 26 } 27 28 @Test isA_Positivenull29 fun isA_Positive() { 30 assertThat(anAny.isA<Int32Message>()).isTrue() 31 } 32 33 @Test isA_Negativenull34 fun isA_Negative() { 35 assertThat(anAny.isA<BoolMessage>()).isFalse() 36 } 37 38 @Test unpackValidnull39 fun unpackValid() { 40 assertThat(anAny.unpack<Int32Message>().data).isEqualTo(5) 41 } 42 43 @Test unpackInvalidnull44 fun unpackInvalid() { 45 assertFailsWith<InvalidProtocolBufferException> { anAny.unpack<BoolMessage>() } 46 } 47 } 48