MessageBuilder { public T build() { if (anonymousId == null && userId == null) { throw new IllegalStateException("Either anonymousId or userId must be provided."); } Date timestamp = this.timestamp; if (timestamp == null) { timestamp = new Date(); } String messageId = this.messageId; if (messageId == null) { messageId = UUID.randomUUID().toString(); } Map<String, Object> integrations; if (this.integrations == null) { integrations = Collections.emptyMap(); } else { integrations = ImmutableMap.copyOf(this.integrations); } return realBuild(type, messageId, timestamp, context, anonymousId, userId, integrations); } MessageBuilder(Message.Type type);   MessageBuilder(Message message); V messageId(UUID messageId); V messageId(String messageId); V timestamp(Date timestamp); V context(Map<String, ?> context); V anonymousId(UUID anonymousId); V anonymousId(String anonymousId); V userId(String userId); V enableIntegration(String key, boolean enable); V integrationOptions(String key, Map<String, ? super Object> options); T build(); Message.Type type();  }
@Test public void missingUserIdAndAnonymousIdThrowsException(TestUtils.MessageBuilderFactory builder) { try { builder.get().build(); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage("Either anonymousId or userId must be provided."); } }