Skip to content

Commit

Permalink
Adjusted code formatting of StopStreaming and added null checks for…
Browse files Browse the repository at this point in the history
… constructor arguments. Added unit tests for `StopStreaming`.

Signed-off-by: Juergen Fickel <juergen.fickel@bosch-si.com>
  • Loading branch information
Juergen Fickel committed Oct 16, 2019
1 parent e9783ba commit 1ea3991
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,34 @@
*/
package org.eclipse.ditto.services.gateway.streaming;

import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull;

import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.services.models.concierge.streaming.StreamingType;

/**
* Message indicating a demand to receive entities of a specified {@link StreamingType} via a "streaming" connection.
*/
@Immutable
public final class StopStreaming {

private final StreamingType streamingType;
private final String connectionCorrelationId;

/**
* Constructs a new {@link StopStreaming} instance.
* Constructs a new {@code StopStreaming} object.
*
* @param streamingType the type of entity to start the streaming for.
* @param connectionCorrelationId the correlationId of the connection/session.
* @param connectionCorrelationId the correlation ID of the connection/session.
* @throws NullPointerException if any argument is {@code null}.
*/
public StopStreaming(final StreamingType streamingType, final String connectionCorrelationId) {
this.streamingType = streamingType;
this.connectionCorrelationId = connectionCorrelationId;
this.streamingType = checkNotNull(streamingType, "streamingType");
this.connectionCorrelationId = checkNotNull(connectionCorrelationId, "connectionCorrelationId");
}

/**
Expand All @@ -47,9 +54,13 @@ public String getConnectionCorrelationId() {
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final StopStreaming that = (StopStreaming) o;
return streamingType == that.streamingType &&
Objects.equals(connectionCorrelationId, that.connectionCorrelationId);
Expand All @@ -67,4 +78,5 @@ public String toString() {
", connectionCorrelationId=" + connectionCorrelationId +
"]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.gateway.streaming;

import static org.assertj.core.api.Assertions.assertThatNullPointerException;
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.assertj.core.api.SoftAssertions;
import org.eclipse.ditto.services.models.concierge.streaming.StreamingType;
import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

/**
* Unit test for {@link StopStreaming}.
*/
public final class StopStreamingTest {

@Test
public void assertImmutability() {
assertInstancesOf(StopStreaming.class, areImmutable());
}

@Test
public void testHashCodeAndEquals() {
EqualsVerifier.forClass(StopStreaming.class)
.usingGetClass()
.verify();
}

@Test
public void tryToCreateInstanceWithNullStreamingType() {
assertThatNullPointerException()
.isThrownBy(() -> new StopStreaming(null, "my-correlation-id"))
.withMessage("The streamingType must not be null!")
.withNoCause();
}

@Test
public void tryToCreateInstanceWithNullCorrelationId() {
assertThatNullPointerException()
.isThrownBy(() -> new StopStreaming(StreamingType.LIVE_COMMANDS, null))
.withMessage("The connectionCorrelationId must not be null!")
.withNoCause();
}

@Test
public void gettersReturnExpected() {
final StreamingType streamingType = StreamingType.EVENTS;
final String connectionCorrelationId = "my-correlation-id";

final StopStreaming underTest = new StopStreaming(streamingType, connectionCorrelationId);

final SoftAssertions softly = new SoftAssertions();
softly.assertThat(underTest.getStreamingType()).isEqualTo(streamingType);
softly.assertThat(underTest.getConnectionCorrelationId()).isEqualTo(connectionCorrelationId);
softly.assertAll();
}

}

0 comments on commit 1ea3991

Please sign in to comment.