title: How to do Junit Test with Google Cloud Pub/Sub
body: <p>I'm using push pub/sub of Google Cloud Pub/Sub in my system,and I want to build my CI test code but I don't know how to do it.For example,some codes are like this:</p>
  
  <pre><code>final Pubsub pubsub = PubsubUtils.getClient();
  final PubsubMessage pubsubMessage = new PubsubMessage();
  
  pubsubMessage.encodeData(message.getBytes(StandardCharsets.UTF_8));
  Map&lt;String, String&gt; attrs = new HashMap&lt;String, String&gt;();
  attrs.put("key", "value");
  pubsubMessage.setAttributes(attrs);
  
  final List&lt;PubsubMessage&gt; messages = ImmutableList.of(pubsubMessage);
  final PublishRequest publishRequest = new PublishRequest().setMessages(messages);
          final PublishResponse publishResponse = pubsub.projects().topics().publish(topic, publishRequest).execute();
          final List&lt;String&gt; messageIds = publishResponse.getMessageIds();
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>final ServletInputStream reader = request.getInputStream();
          try {
              // Parse the JSON message to the POJO model class.
              final JsonParser parser = JacksonFactory.getDefaultInstance().createJsonParser(reader);
  
              parser.skipToKey("message");
  
              final PubsubMessage message = parser.parseAndClose(PubsubMessage.class);
  
              Map&lt;String, String&gt; attrs = message.getAttributes();
              String value = attrs.get("key");
  
              // Base64-decode the data and work with it.
              final String data = new String(message.decodeData(), StandardCharsets.UTF_8);
              if (data != null || StringUtils.isNotEmpty(data)) {
                  Logger.getLogger("logger").info(data);
              }
              // Work with your message
              // Respond with a 20X to acknowledge receipt of the message.
              response.setStatus(HttpServletResponse.SC_OK);
          } finally {
              reader.close();
          }
  </code></pre>
  
  <p>How to write a normally Junit test case for the two parts of code? and also,I'm using PowerMockito to mock the objects.</p>
  
  <p>Hope someone can help me.</p>