Skip to content

Commit

Permalink
Improve code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
gfinocchiaro committed Sep 21, 2017
1 parent 06d5a67 commit ab75f17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
30 changes: 14 additions & 16 deletions src/test/java/cool/mqtt/hooks/SimpleCoolHookTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package cool.mqtt.hooks;

import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;

import static org.junit.Assert.assertThat;

import java.util.HashMap;

import org.junit.Before;
import org.junit.Test;

public class SimpleCoolHookTest {

private SimpleCoolHook simpleCoolHook;
Expand All @@ -27,32 +26,31 @@ public void shouldNotResoleAliass() throws HookException {
@Test
public void shouldAllowSessionOpen() throws HookException {
/*
* For simplicity'sake, just pass simple values as clientContext and
* clientPrincipal
* For simplicity'sake, just pass simple values as clientContext and clientPrincipal
*/
assertThat(simpleCoolHook.canOpenSession("sessionId", "user",
"password", new HashMap<>(), ""), is(true));
assertThat(simpleCoolHook.canOpenSession("sessionId", "user", "password", new HashMap<>(), ""),
is(true));
}

@Test
public void shoulwAllowConnection() throws HookException {
// For simplicity'sake, just pass null as MqttConnectionOptions
assertThat(simpleCoolHook.canConnect("sessionId", "clientId",
"tcp://localhost:1883", null), is(true));
assertThat(simpleCoolHook.canConnect("sessionId", "clientId", "tcp://localhost:1883", null),
is(true));
}

@Test
public void shoulwAllowPublishing() throws HookException {
// For simplicity'sake, just pass null as MqttMessage
assertThat(simpleCoolHook.canPublish("sessionId", "clientId",
"tcp://localhost:1883", null), is(true));
assertThat(simpleCoolHook.canPublish("sessionId", "clientId", "tcp://localhost:1883", null),
is(true));
}

@Test
public void shoulwAllowSubscription() throws HookException {
// For simplicity'sake, just pass null as MqttSubscription
assertThat(simpleCoolHook.canSubscribe("sessionId", "clientId",
"tcp://localhost:1883", null), is(true));
assertThat(simpleCoolHook.canSubscribe("sessionId", "clientId", "tcp://localhost:1883", null),
is(true));
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package cool.mqtt.hooks.utils;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -13,7 +8,11 @@
import cool.mqtt.hooks.MqttBrokerConfig;
import cool.mqtt.hooks.MqttMessage;
import cool.mqtt.hooks.QoS;
import cool.mqtt.hooks.utils.MqttBrokerConfigBuilder;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class MqttBrokerConfigBuilderTest {

Expand Down Expand Up @@ -42,15 +41,9 @@ public void shouldBuildConfigWithDefaultValues() {

@Test
public void shouldBuildConfigWithCustomValues() {
MqttBrokerConfig config = builder
.username("username")
.password("password")
.clientIdPrefix("client_id_prefix")
.connectionTimeout(5)
.keepAlive(10)
.willMessage("topic", new byte[] { 1, 2, 3 }, QoS.AT_MOST_ONCE,
true)
.build();
MqttBrokerConfig config = builder.username("username").password("password")
.clientIdPrefix("client_id_prefix").connectionTimeout(5).keepAlive(10)
.willMessage("topic", new byte[] {1, 2, 3}, QoS.AT_MOST_ONCE, true).build();

assertThat(config.getAddress(), is("tcp://localhost:1883"));
assertThat(config.getClientIdPrefix(), is("client_id_prefix"));
Expand All @@ -63,26 +56,23 @@ public void shouldBuildConfigWithCustomValues() {
assertThat(willMessage, notNullValue());
assertThat(willMessage.getTopicName(), is("topic"));
assertThat(willMessage.getQos(), is(QoS.AT_MOST_ONCE));
assertThat(willMessage.getApplicationMessage(),
is(new byte[] { 1, 2, 3 }));
assertThat(willMessage.getApplicationMessage(), is(new byte[] {1, 2, 3}));
}

@Test
public void shouldThrowIllegalArgumentExceptionForInvalidNullTopic() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(is("Invalid topic"));

builder.willMessage(null, new byte[] { 1, 2, 3 }, QoS.AT_MOST_ONCE,
true);
builder.willMessage(null, new byte[] {1, 2, 3}, QoS.AT_MOST_ONCE, true);
}

@Test
public void shouldThrowIllegalArgumentExceptionForInvalidEmptyTopic() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(is("Invalid topic"));

builder.willMessage("", new byte[] { 1, 2, 3 }, QoS.AT_MOST_ONCE,
true);
builder.willMessage("", new byte[] {1, 2, 3}, QoS.AT_MOST_ONCE, true);
}

@Test
Expand All @@ -91,7 +81,7 @@ public void shouldThrowIllegalArgumentExceptionForInvalidQoS() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(is("Invalid QoS"));

builder.willMessage("topic", new byte[] { 1, 2, 3 }, null, false);
builder.willMessage("topic", new byte[] {1, 2, 3}, null, false);
}

}

0 comments on commit ab75f17

Please sign in to comment.