diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/PubSubExample.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/PubSubExample.java
index a7bec6424cfe..13368d65a2f8 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/PubSubExample.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/PubSubExample.java
@@ -19,7 +19,6 @@
import com.google.cloud.Identity;
import com.google.cloud.Policy;
import com.google.cloud.Role;
-import com.google.cloud.pubsub.Message;
import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSubOptions;
import com.google.cloud.pubsub.PushConfig;
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PubSubSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PubSubSnippets.java
index bac2e1d3d999..7b278f06e2e7 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PubSubSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/PubSubSnippets.java
@@ -27,7 +27,6 @@
import com.google.cloud.Page;
import com.google.cloud.Policy;
import com.google.cloud.Role;
-import com.google.cloud.pubsub.Message;
import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSub.ListOption;
import com.google.cloud.pubsub.PushConfig;
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionSnippets.java
index c5506d573c76..fb408f53b0b4 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriptionSnippets.java
@@ -25,7 +25,6 @@
import com.google.cloud.Identity;
import com.google.cloud.Policy;
import com.google.cloud.Role;
-import com.google.cloud.pubsub.Message;
import com.google.cloud.pubsub.PushConfig;
import com.google.cloud.pubsub.Subscription;
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicSnippets.java
index 6d0c4548da7c..6e7ffc4ac2f1 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/TopicSnippets.java
@@ -27,7 +27,6 @@
import com.google.cloud.Page;
import com.google.cloud.Policy;
import com.google.cloud.Role;
-import com.google.cloud.pubsub.Message;
import com.google.cloud.pubsub.PubSub.ListOption;
import com.google.cloud.pubsub.SubscriptionId;
import com.google.cloud.pubsub.Topic;
diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionSnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionSnippets.java
index c471909b64ae..07e456aaafb8 100644
--- a/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionSnippets.java
+++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/pubsub/snippets/ITSubscriptionSnippets.java
@@ -25,7 +25,6 @@
import com.google.cloud.Identity;
import com.google.cloud.Policy;
import com.google.cloud.Role;
-import com.google.cloud.pubsub.Message;
import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSubOptions;
import com.google.cloud.pubsub.Subscription;
@@ -47,8 +46,6 @@ public class ITSubscriptionSnippets {
"it-subscription-snippets-topic-" + UUID.randomUUID().toString();
private static final String SUBSCRIPTION =
"it-subscription-snippets-subscription-" + UUID.randomUUID().toString();
- private static final Message MESSAGE1 = Message.of("message1");
- private static final Message MESSAGE2 = Message.of("message2");
private static PubSub pubsub;
private static Topic topic;
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/Message.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/Message.java
deleted file mode 100644
index d728dad43aea..000000000000
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/Message.java
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * Copyright 2016 Google Inc. All Rights Reserved.
- *
- * 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.cloud.pubsub;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.cloud.ByteArray;
-import com.google.common.base.Function;
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableMap;
-import com.google.protobuf.ByteString;
-import com.google.protobuf.Timestamp;
-import com.google.pubsub.v1.PubsubMessage;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * A Google Cloud Pub/Sub message. A message is the combination of data and (optional) attributes
- * that a publisher sends to a topic and is eventually delivered to subscribers.
- *
- *
Message attributes are key-value pairs that a publisher can define for a message. For example,
- * a key {@code iana.org/language_tag} and value {@code en} could be added to messages to mark them
- * as readable by an English-speaking subscriber.
- *
- *
To be published, a message must have a non-empty payload, or at least one attribute.
- *
- * @see Pub/Sub Data Model
- */
-public class Message implements Serializable {
-
- static final Function TO_PB_FUNCTION =
- new Function() {
- @Override
- public PubsubMessage apply(Message message) {
- return message.toPb();
- }
- };
-
- private static final long serialVersionUID = -1436515787233340634L;
- private static final long NANOS_PER_MILLISECOND = 1000000;
- private static final long MILLIS_PER_SECOND = 1000;
-
- private final String id;
- private final InternalByteArray payload;
- private final ImmutableMap attributes;
- private final Long publishTime;
-
- private static final class InternalByteArray extends ByteArray {
-
- private static final long serialVersionUID = -3330181485911805428L;
-
- InternalByteArray(ByteString byteString) {
- super(byteString);
- }
-
- InternalByteArray(ByteArray byteArray) {
- super(byteArray);
- }
-
- @Override
- protected ByteString getByteString() {
- return super.getByteString();
- }
- }
-
- /**
- * Builder for {@code Message} objects.
- */
- public abstract static class Builder {
-
- abstract Builder setId(String id);
-
- /**
- * Sets the message payload to the provided string. The string is enconded {@code UTF-8}.
- */
- @Deprecated
- public abstract Builder payload(String payload);
-
- /**
- * Sets the message payload to the provided string. The string is enconded {@code UTF-8}.
- */
- public abstract Builder setPayload(String payload);
-
- /**
- * Sets the message payload to the provided {@link ByteArray}.
- */
- @Deprecated
- public abstract Builder payload(ByteArray payload);
-
- /**
- * Sets the message payload to the provided {@link ByteArray}.
- */
- public abstract Builder setPayload(ByteArray payload);
-
- /**
- * Sets the message attributes to the provided map. Message attributes are key-value pairs that
- * a publisher can define for a message. For example, a key {@code iana.org/language_tag} and
- * value {@code en} could be added to messages to mark them as readable by an English-speaking
- * subscriber.
- */
- @Deprecated
- public abstract Builder attributes(Map attributes);
-
- /**
- * Sets the message attributes to the provided map. Message attributes are key-value pairs that
- * a publisher can define for a message. For example, a key {@code iana.org/language_tag} and
- * value {@code en} could be added to messages to mark them as readable by an English-speaking
- * subscriber.
- */
- public abstract Builder setAttributes(Map attributes);
-
- /**
- * Adds a new attribute to the message attributes. If an attribute with name {@code name} was
- * already set, its value is updated.
- */
- public abstract Builder addAttribute(String name, String value);
-
- /**
- * Removes an attribute give its name from the message attributes.
- */
- public abstract Builder removeAttribute(String name);
-
- /**
- * Clears all message attributes.
- */
- public abstract Builder clearAttributes();
-
- abstract Builder setPublishTime(long publishTime);
-
- /**
- * Creates a message object.
- */
- public abstract Message build();
- }
-
- static final class BuilderImpl extends Builder {
-
- private String id;
- private ByteArray payload;
- private Map attributes = new HashMap<>();
- private Long publishTime;
-
- private BuilderImpl() {}
-
- BuilderImpl(Message message) {
- id = message.id;
- payload = message.payload;
- attributes = new HashMap<>(message.attributes);
- publishTime = message.publishTime;
- }
-
- @Override
- BuilderImpl setId(String id) {
- this.id = checkNotNull(id);
- return this;
- }
-
- @Override
- @Deprecated
- public Builder payload(String payload) {
- return setPayload(payload);
- }
-
- @Override
- public Builder setPayload(String payload) {
- return setPayload(ByteArray.copyFrom(payload));
- }
-
- @Override
- @Deprecated
- public Builder payload(ByteArray payload) {
- return setPayload(payload);
- }
-
- @Override
- public Builder setPayload(ByteArray payload) {
- this.payload = payload;
- return this;
- }
-
- @Override
- public Builder addAttribute(String name, String value) {
- attributes.put(name, value);
- return this;
- }
-
- @Override
- @Deprecated
- public Builder attributes(Map attributes) {
- return setAttributes(attributes);
- }
-
- @Override
- public Builder setAttributes(Map attributes) {
- this.attributes = new HashMap<>(attributes);
- return this;
- }
-
- @Override
- public Builder removeAttribute(String name) {
- attributes.remove(name);
- return this;
- }
-
- @Override
- public Builder clearAttributes() {
- attributes.clear();
- return this;
- }
-
- @Override
- Builder setPublishTime(long publishTime) {
- this.publishTime = publishTime;
- return this;
- }
-
- @Override
- public Message build() {
- return new Message(this);
- }
- }
-
- Message(BuilderImpl builder) {
- id = builder.id;
- payload = new InternalByteArray(checkNotNull(builder.payload));
- attributes = ImmutableMap.copyOf(builder.attributes);
- publishTime = builder.publishTime;
- }
-
- /**
- * Returns the time in milliseconds at which the message was published. This value is set by the
- * server when it receives the publish call. If not set, this method returns {@code null}.
- */
- @Deprecated
- public Long publishTime() {
- return getPublishTime();
- }
-
- /**
- * Returns the time in milliseconds at which the message was published. This value is set by the
- * server when it receives the publish call. If not set, this method returns {@code null}.
- */
- public Long getPublishTime() {
- return publishTime;
- }
-
- /**
- * Returns the message attributes. Message attributes are key-value pairs that a publisher can
- * define for a message. For example, a key {@code iana.org/language_tag} and value {@code en}
- * could be added to messages to mark them as readable by an English-speaking subscriber.
- */
- @Deprecated
- public Map attributes() {
- return getAttributes();
- }
-
- /**
- * Returns the message attributes. Message attributes are key-value pairs that a publisher can
- * define for a message. For example, a key {@code iana.org/language_tag} and value {@code en}
- * could be added to messages to mark them as readable by an English-speaking subscriber.
- */
- public Map getAttributes() {
- return attributes;
- }
-
- /**
- * Returns the id of this message, set by the server when the message is published. The id is
- * guaranteed to be unique within the topic. This value may be read by a subscriber that receives
- * a Pub/Sub message via a pull call or a push delivery. If not set, this method returns
- * {@code null}.
- */
- @Deprecated
- public String id() {
- return getId();
- }
-
- /**
- * Returns the id of this message, set by the server when the message is published. The id is
- * guaranteed to be unique within the topic. This value may be read by a subscriber that receives
- * a Pub/Sub message via a pull call or a push delivery. If not set, this method returns
- * {@code null}.
- */
- public String getId() {
- return id;
- }
-
- /**
- * Returns the message payload as a string, decoded using {@code UTF-8}.
- */
- @Deprecated
- public String payloadAsString() {
- return getPayloadAsString();
- }
-
- /**
- * Returns the message payload as a string, decoded using {@code UTF-8}.
- */
- public String getPayloadAsString() {
- return payload.toStringUtf8();
- }
-
- /**
- * Returns the message payload.
- */
- @Deprecated
- public ByteArray payload() {
- return getPayload();
- }
-
- /**
- * Returns the message payload.
- */
- public ByteArray getPayload() {
- return payload;
- }
-
- final boolean baseEquals(Message message) {
- return Objects.equals(id, message.id)
- && Objects.equals(payload, message.payload)
- && Objects.equals(attributes, message.attributes)
- && Objects.equals(publishTime, message.publishTime);
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj == this
- || obj != null
- && obj.getClass().equals(Message.class)
- && baseEquals((Message) obj);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(id, payload, attributes, publishTime);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("id", id)
- .add("payload", payload)
- .add("attributes", attributes)
- .add("publishTime", publishTime)
- .toString();
- }
-
- PubsubMessage toPb() {
- PubsubMessage.Builder builder = PubsubMessage.newBuilder();
- if (id != null) {
- builder.setMessageId(id);
- }
- builder.setData(payload.getByteString());
- builder.putAllAttributes(attributes);
- Timestamp.Builder tsBuilder = Timestamp.newBuilder();
- if (publishTime != null) {
- tsBuilder.setSeconds(publishTime / MILLIS_PER_SECOND);
- tsBuilder.setNanos((int) (publishTime % MILLIS_PER_SECOND * NANOS_PER_MILLISECOND));
- }
- builder.setPublishTime(tsBuilder);
- return builder.build();
- }
-
- static Message fromPb(PubsubMessage messagePb) {
- Builder builder = newBuilder(new InternalByteArray(messagePb.getData()));
- if (messagePb.hasPublishTime()) {
- Timestamp ts = messagePb.getPublishTime();
- Long millis = ts.getSeconds() * MILLIS_PER_SECOND + ts.getNanos() / NANOS_PER_MILLISECOND;
- if (millis != 0) {
- builder.setPublishTime(millis);
- }
- }
- if (!Objects.equals(messagePb.getMessageId(), "")) {
- builder.setId(messagePb.getMessageId());
- }
- for (Map.Entry entry : messagePb.getAttributesMap().entrySet()) {
- builder.addAttribute(entry.getKey(), entry.getValue());
- }
- return builder.build();
- }
-
- /**
- * Returns a builder for the message object.
- */
- public Builder toBuilder() {
- return new BuilderImpl(this);
- }
-
- /**
- * Creates a {@code Message} object given the payload as a string. The string is enconded using
- * {@code UTF-8}.
- */
- public static Message of(String payload) {
- return newBuilder(payload).build();
- }
-
- /**
- * Creates a {@code Message} object given the payload as a {@link ByteArray}. To be published a
- * message must have a non-empty payload.
- */
- public static Message of(ByteArray payload) {
- return newBuilder(payload).build();
- }
-
- /**
- * Creates a builder for {@code Message} objects given the payload as a string. The string is
- * enconded using {@code UTF-8}. To be published a message must have a non-empty payload.
- */
- @Deprecated
- public static Builder builder(String payload) {
- return newBuilder(payload);
- }
-
- /**
- * Creates a builder for {@code Message} objects given the payload as a string. The string is
- * enconded using {@code UTF-8}. To be published a message must have a non-empty payload.
- */
- public static Builder newBuilder(String payload) {
- return new BuilderImpl().setPayload(payload);
- }
-
- /**
- * Creates a builder for {@code Message} objects given the payload as a {@link ByteArray}. To be
- * published a message must have a non-empty payload, or at least one attribute.
- */
- @Deprecated
- public static Builder builder(ByteArray payload) {
- return newBuilder(payload);
- }
-
- /**
- * Creates a builder for {@code Message} objects given the payload as a {@link ByteArray}. To be
- * published a message must have a non-empty payload, or at least one attribute.
- */
- public static Builder newBuilder(ByteArray payload) {
- return new BuilderImpl().setPayload(payload);
- }
-}
diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSub.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSub.java
index 9439e4665baf..d58234a4a45b 100644
--- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSub.java
+++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PubSub.java
@@ -77,9 +77,7 @@ public static ListOption pageToken(String pageToken) {
}
}
- /**
- * Class for specifying options for pulling messages.
- */
+ /** Class for specifying options for pulling messages. */
final class PullOption extends Option {
private static final long serialVersionUID = 4792164134340316582L;
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/MessageTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/MessageTest.java
deleted file mode 100644
index ee4fe3055a10..000000000000
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/MessageTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright 2016 Google Inc. All Rights Reserved.
- *
- * 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.cloud.pubsub;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import com.google.cloud.ByteArray;
-import com.google.common.collect.ImmutableMap;
-
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-
-public class MessageTest {
-
- private static final String MESSAGE_ID = "messageId";
- private static final String PAYLOAD_STRING = "payload";
- private static final ByteArray PAYLOAD =
- ByteArray.copyFrom("payload".getBytes(StandardCharsets.UTF_8));
- private static final Map ATTRIBUTES =
- ImmutableMap.of("key1", "value1", "key2", "value2");
- private static final Long PUBLISH_TIME = 42L;
- private static final Message MESSAGE_STRING = Message.newBuilder(PAYLOAD_STRING)
- .setId(MESSAGE_ID)
- .setAttributes(ATTRIBUTES)
- .setPublishTime(PUBLISH_TIME)
- .build();
- private static final Message MESSAGE = Message.newBuilder(PAYLOAD)
- .setId(MESSAGE_ID)
- .setAttributes(ATTRIBUTES)
- .setPublishTime(PUBLISH_TIME)
- .build();
- private static final Message DEPRECATED_MESSAGE_STRING = Message.builder(PAYLOAD_STRING)
- .setId(MESSAGE_ID)
- .attributes(ATTRIBUTES)
- .setPublishTime(PUBLISH_TIME)
- .build();
- private static final Message DEPRECATED_MESSAGE = Message.builder(PAYLOAD)
- .setId(MESSAGE_ID)
- .attributes(ATTRIBUTES)
- .setPublishTime(PUBLISH_TIME)
- .build();
-
- @Test
- public void testToBuilder() {
- compareMessage(MESSAGE, MESSAGE.toBuilder().build());
- Message message = MESSAGE.toBuilder()
- .setPayload("newPayload")
- .clearAttributes()
- .addAttribute("key1", "value1")
- .build();
- assertEquals("newPayload", message.getPayloadAsString());
- assertEquals(ImmutableMap.of("key1", "value1"), message.getAttributes());
- message = message.toBuilder()
- .setPayload(PAYLOAD_STRING)
- .removeAttribute("key1")
- .setAttributes(ATTRIBUTES)
- .build();
- compareMessage(MESSAGE, message);
- }
-
- @Test
- public void testBuilder() {
- assertEquals(MESSAGE_ID, MESSAGE.getId());
- assertEquals(PAYLOAD, MESSAGE.getPayload());
- assertEquals(PAYLOAD_STRING, MESSAGE.getPayloadAsString());
- assertEquals(ATTRIBUTES, MESSAGE.getAttributes());
- assertEquals(PUBLISH_TIME, MESSAGE.getPublishTime());
- assertEquals(MESSAGE_ID, MESSAGE_STRING.getId());
- assertEquals(PAYLOAD, MESSAGE_STRING.getPayload());
- assertEquals(PAYLOAD_STRING, MESSAGE_STRING.getPayloadAsString());
- assertEquals(ATTRIBUTES, MESSAGE_STRING.getAttributes());
- assertEquals(PUBLISH_TIME, MESSAGE_STRING.getPublishTime());
- compareMessage(MESSAGE, MESSAGE_STRING);
- Message message = Message.newBuilder(PAYLOAD)
- .setId(MESSAGE_ID)
- .setAttributes(ATTRIBUTES)
- .clearAttributes()
- .addAttribute("key1", "value1")
- .addAttribute("key2", "value2")
- .setPublishTime(PUBLISH_TIME)
- .build();
- assertEquals(MESSAGE_ID, message.getId());
- assertEquals(PAYLOAD, message.getPayload());
- assertEquals(PAYLOAD_STRING, message.getPayloadAsString());
- assertEquals(ATTRIBUTES, message.getAttributes());
- assertEquals(PUBLISH_TIME, message.getPublishTime());
- compareMessage(MESSAGE, message);
- }
-
- @Test
- public void testBuilderDeprecated() {
- assertEquals(MESSAGE_ID, DEPRECATED_MESSAGE.id());
- assertEquals(PAYLOAD, DEPRECATED_MESSAGE.payload());
- assertEquals(PAYLOAD_STRING, DEPRECATED_MESSAGE.payloadAsString());
- assertEquals(ATTRIBUTES, DEPRECATED_MESSAGE.attributes());
- assertEquals(PUBLISH_TIME, DEPRECATED_MESSAGE.publishTime());
- assertEquals(MESSAGE_ID, DEPRECATED_MESSAGE_STRING.id());
- assertEquals(PAYLOAD, DEPRECATED_MESSAGE_STRING.payload());
- assertEquals(PAYLOAD_STRING, DEPRECATED_MESSAGE_STRING.payloadAsString());
- assertEquals(ATTRIBUTES, DEPRECATED_MESSAGE_STRING.attributes());
- assertEquals(PUBLISH_TIME, DEPRECATED_MESSAGE_STRING.publishTime());
- compareMessage(MESSAGE, DEPRECATED_MESSAGE_STRING);
- Message message = Message.builder(PAYLOAD)
- .setId(MESSAGE_ID)
- .attributes(ATTRIBUTES)
- .clearAttributes()
- .addAttribute("key1", "value1")
- .addAttribute("key2", "value2")
- .setPublishTime(PUBLISH_TIME)
- .build();
- assertEquals(MESSAGE_ID, message.id());
- assertEquals(PAYLOAD, message.payload());
- assertEquals(PAYLOAD_STRING, message.payloadAsString());
- assertEquals(ATTRIBUTES, message.attributes());
- assertEquals(PUBLISH_TIME, message.publishTime());
- compareMessage(MESSAGE, message);
- }
-
- @Test
- public void testOf() {
- Message message1 = Message.of(PAYLOAD_STRING);
- assertNull(message1.getId());
- assertEquals(PAYLOAD, message1.getPayload());
- assertEquals(PAYLOAD_STRING, message1.getPayloadAsString());
- assertEquals(ImmutableMap.of(), message1.getAttributes());
- assertNull(message1.getPublishTime());
- Message message2 = Message.of(PAYLOAD);
- assertNull(message2.getId());
- assertEquals(PAYLOAD, message2.getPayload());
- assertEquals(PAYLOAD_STRING, message2.getPayloadAsString());
- assertEquals(ImmutableMap.of(), message2.getAttributes());
- assertNull(message2.getPublishTime());
- compareMessage(message1 ,message2);
- }
-
- @Test
- public void testToAndFromPb() {
- compareMessage(MESSAGE, Message.fromPb(MESSAGE.toPb()));
- compareMessage(MESSAGE_STRING, Message.fromPb(MESSAGE_STRING.toPb()));
- }
-
- @Test
- public void testToAndFromPbIncomplete() {
- Message message = Message.of(PAYLOAD_STRING);
- compareMessage(message, Message.fromPb(message.toPb()));
- message = Message.of(PAYLOAD);
- compareMessage(message, Message.fromPb(message.toPb()));
- }
-
- private void compareMessage(Message expected, Message value) {
- assertEquals(expected, value);
- assertEquals(expected.getId(), value.getId());
- assertEquals(expected.getPayload(), value.getPayload());
- assertEquals(expected.getPayloadAsString(), value.getPayloadAsString());
- assertEquals(expected.getAttributes(), value.getAttributes());
- assertEquals(expected.getPublishTime(), value.getPublishTime());
- assertEquals(expected.hashCode(), value.hashCode());
- }
-}
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java
index 3f02a7628805..e314c720761f 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/PubSubImplTest.java
@@ -80,7 +80,6 @@ public com.google.pubsub.v1.Topic apply(TopicInfo topicInfo) {
return topicInfo.toPb(PROJECT);
}
};
- private static final Message MESSAGE = Message.of("payload");
private static final String SUBSCRIPTION = "subscription";
private static final String SUBSCRIPTION_NAME_PB = "projects/project/subscriptions/subscription";
private static final PushConfig PUSH_CONFIG = PushConfig.of("endpoint");
@@ -94,18 +93,6 @@ public com.google.pubsub.v1.Topic apply(TopicInfo topicInfo) {
.setAckDeadLineSeconds(42)
.setPushConfig(PUSH_CONFIG)
.build();
- private static final Message MESSAGE1 = Message.of("payload1");
- private static final com.google.pubsub.v1.ReceivedMessage MESSAGE_PB1 =
- com.google.pubsub.v1.ReceivedMessage.newBuilder()
- .setMessage(MESSAGE1.toPb())
- .setAckId("ackId1")
- .build();
- private static final Message MESSAGE2 = Message.of("payload2");
- private static final com.google.pubsub.v1.ReceivedMessage MESSAGE_PB2 =
- com.google.pubsub.v1.ReceivedMessage.newBuilder()
- .setMessage(MESSAGE2.toPb())
- .setAckId("ackId2")
- .build();
private static final Policy POLICY = Policy.newBuilder()
.addIdentity(Role.viewer(), Identity.allAuthenticatedUsers())
.build();
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SerializationTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SerializationTest.java
index d22940800a29..30c7e1ea5685 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SerializationTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SerializationTest.java
@@ -32,12 +32,6 @@ public class SerializationTest extends BaseSerializationTest {
.setCredentials(NoCredentials.getInstance())
.setHost("localhost")
.build().getService();
- private static final Message MESSAGE = Message.of("payload");
- private static final com.google.pubsub.v1.ReceivedMessage RECEIVED_MESSAGE_PB =
- com.google.pubsub.v1.ReceivedMessage.newBuilder()
- .setMessage(MESSAGE.toPb())
- .setAckId("ackId")
- .build();
private static final SubscriptionInfo SUBSCRIPTION_INFO = SubscriptionInfo.of("topic", "sub");
private static final Subscription SUBSCRIPTION =
new Subscription(PUB_SUB, new SubscriptionInfo.BuilderImpl(SUBSCRIPTION_INFO));
@@ -90,7 +84,6 @@ protected Serializable[] serializableObjects() {
return new Serializable[] {
options,
otherOptions,
- MESSAGE,
SUBSCRIPTION_INFO,
SUBSCRIPTION,
SUBSCRIPTION_ID,
diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SubscriptionTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SubscriptionTest.java
index 979732f9b06d..a70ab0efcd87 100644
--- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SubscriptionTest.java
+++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/SubscriptionTest.java
@@ -54,18 +54,6 @@ public class SubscriptionTest {
.setPushConfig(PUSH_CONFIG)
.setAckDeadLineSeconds(ACK_DEADLINE)
.build();
- private static final Message MESSAGE1 = Message.of("payload1");
- private static final com.google.pubsub.v1.ReceivedMessage MESSAGE_PB1 =
- com.google.pubsub.v1.ReceivedMessage.newBuilder()
- .setMessage(MESSAGE1.toPb())
- .setAckId("ackId1")
- .build();
- private static final Message MESSAGE2 = Message.of("payload2");
- private static final com.google.pubsub.v1.ReceivedMessage MESSAGE_PB2 =
- com.google.pubsub.v1.ReceivedMessage.newBuilder()
- .setMessage(MESSAGE2.toPb())
- .setAckId("ackId2")
- .build();
private static final Policy POLICY = Policy.newBuilder()
.addIdentity(Role.viewer(), Identity.allAuthenticatedUsers())
.build();