Skip to content

Commit

Permalink
#30 code style
Browse files Browse the repository at this point in the history
  • Loading branch information
kpavlov committed Jan 14, 2017
1 parent ae51de8 commit 540c37b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 29 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/fixio/AbstractFixConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
*
* @author Konstantin Pavlov
*/
@SuppressWarnings("WeakerAccess")
public abstract class AbstractFixConnector {

private final FixApplication fixApplication;
private final SessionRepository sessionRepository;

public AbstractFixConnector(FixApplication fixApplication, SessionRepository sessionRepository) {
protected AbstractFixConnector(FixApplication fixApplication, SessionRepository sessionRepository) {
this.fixApplication = fixApplication;
this.sessionRepository = sessionRepository;
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/fixio/FixClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,20 @@ public void setAuthenticationProvider(AuthenticationProvider authenticationProvi
/**
* Connect and start FIX session to specified host and port.
*/
@SuppressWarnings("WeakerAccess")
public ChannelFuture connect(String host, int port) throws InterruptedException {
return connect(new InetSocketAddress(host, port));
}

@SuppressWarnings("WeakerAccess")
public ChannelFuture connect(SocketAddress serverAddress) throws InterruptedException {
final Channel channel = connectAsync(serverAddress).sync().await().channel();
assert (channel != null) : "Channel must be set";
LOGGER.info("FixClient is started and connected to {}", channel.remoteAddress());
return channel.closeFuture();
}

@SuppressWarnings("WeakerAccess")
public ChannelFuture connectAsync(SocketAddress serverAddress) {
LOGGER.info("FixClient is starting");
final Bootstrap b = new Bootstrap();
Expand All @@ -116,6 +119,7 @@ public ChannelFuture connectAsync(SocketAddress serverAddress) {
return connectFuture.addListener(future -> channel = connectFuture.channel());
}

@SuppressWarnings("WeakerAccess")
public ChannelFuture disconnectAsync() {
LOGGER.info("Closing connection to {}", channel.remoteAddress());
return channel.close().addListener(future -> {
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/java/fixio/fixprotocol/FieldListBuilderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,80 +30,80 @@ private FieldListBuilderHelper() {

// From Int

static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, int value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, int value) {
assert (tagNum > 0) : "Tag must be positive.";
map.put(tagNum, FieldFactory.fromIntValue(type, tagNum, value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, int value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, int value) {
assert (tagNum > 0) : "Tag must be positive.";
map.put(tagNum, FieldFactory.fromIntValue(tagNum, value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, int value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, int value) {
assert (fieldType != null) : "Tag must be specified.";
map.put(fieldType.tag(), FieldFactory.fromIntValue(fieldType.type(), fieldType.tag(), value));
}

// From Long

static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, long value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, long value) {
assert (tagNum > 0) : "Tag must be positive.";
map.put(tagNum, FieldFactory.fromLongValue(type, tagNum, value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, long value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, long value) {
assert (tagNum > 0) : "Tag must be positive.";
map.put(tagNum, FieldFactory.fromLongValue(tagNum, value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, long value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, long value) {
assert (fieldType != null) : "Tag must be specified.";
map.put(fieldType.tag(), FieldFactory.fromLongValue(fieldType.type(), fieldType.tag(), value));
}

// From String

static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, String value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, String value) {
assert (fieldType != null) : "Tag must be specified.";
assert (value != null) : "Value must be specified.";
map.put(fieldType.tag(), FieldFactory.fromStringValue(fieldType.type(), fieldType.tag(), value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, char value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, char value) {
if (fieldType.type() != DataType.CHAR) {
throw new IllegalArgumentException("FieldType " + fieldType + " must be CHAR");
}
map.put(fieldType.tag(), new CharField(fieldType.tag(), value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, String value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, String value) {
assert (tagNum > 0) : "TagNum must be positive. Got " + tagNum;
assert (value != null) : "Value must be specified.";
map.put(tagNum, FieldFactory.fromStringValue(tagNum, value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, String value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, String value) {
assert (tagNum > 0) : "TagNum must be positive. Got " + tagNum;
assert (value != null) : "Value must be specified.";
map.put(tagNum, FieldFactory.fromStringValue(type, tagNum, value));
}

// From FixedPointNumber

static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, FixedPointNumber value) {
public static void add(Int2ObjectArrayMap<FixMessageFragment> map, FieldType fieldType, FixedPointNumber value) {
assert (fieldType != null) : "Tag must be specified.";
assert (value != null) : "Value must be specified.";
map.put(fieldType.tag(), FieldFactory.fromFixedPointValue(fieldType.type(), fieldType.tag(), value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, FixedPointNumber value) {
public void add(Int2ObjectArrayMap<FixMessageFragment> map, int tagNum, FixedPointNumber value) {
assert (tagNum > 0) : "TagNum must be positive. Got " + tagNum;
assert (value != null) : "Value must be specified.";
map.put(tagNum, FieldFactory.fromFixedPointValue(tagNum, value));
}

static void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, FixedPointNumber value) {
public void add(Int2ObjectArrayMap<FixMessageFragment> map, DataType type, int tagNum, FixedPointNumber value) {
assert (tagNum > 0) : "TagNum must be positive. Got " + tagNum;
assert (value != null) : "Value must be specified.";
map.put(tagNum, FieldFactory.fromFixedPointValue(type, tagNum, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class PropertyFixSessionSettingsProviderImpl implements FixSessionSettingsProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(PropertyFixSessionSettingsProviderImpl.class);
private final java.util.Properties properties;
private final Properties properties;

public PropertyFixSessionSettingsProviderImpl(Properties properties) {
this.properties = properties;
Expand All @@ -37,7 +37,7 @@ public PropertyFixSessionSettingsProviderImpl(String resource) {
loadProperties(resource);
}

public java.util.Properties getProperties() {
public Properties getProperties() {
return properties;
}

Expand Down
22 changes: 17 additions & 5 deletions core/src/test/java/fixio/FixConversationIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,38 @@
package fixio;

import fixio.events.LogonEvent;
import fixio.fixprotocol.*;
import fixio.fixprotocol.DataType;
import fixio.fixprotocol.FixMessage;
import fixio.fixprotocol.FixMessageBuilder;
import fixio.fixprotocol.FixMessageBuilderImpl;
import fixio.fixprotocol.MessageTypes;
import fixio.handlers.FixApplicationAdapter;
import fixio.netty.pipeline.InMemorySessionRepository;
import fixio.netty.pipeline.client.PropertyAuthenticationProvider;
import fixio.netty.pipeline.client.PropertyFixSessionSettingsProviderImpl;
import fixio.netty.pipeline.server.AcceptAllAuthenticator;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static fixio.fixprotocol.FieldType.*;
import static fixio.fixprotocol.FieldType.UserRequestID;
import static fixio.fixprotocol.FieldType.UserRequestType;
import static fixio.fixprotocol.FieldType.UserStatus;
import static fixio.fixprotocol.FieldType.UserStatusText;
import static fixio.fixprotocol.FieldType.Username;
import static org.junit.Assert.assertEquals;

public class FixConversationIT {

public static final int TEST_TIMEOUT = 5000;
public static final int PORT = 10453;
private static final int TEST_TIMEOUT = 5000;
private static final int PORT = 10453;
private static final List<FixMessage> conversation = new ArrayList<>();
private static FixServer server;
private FixClient client;
Expand Down
3 changes: 1 addition & 2 deletions core/src/test/java/fixio/FixServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
@RunWith(org.mockito.junit.MockitoJUnitRunner.class)
public class FixServerTest {

private FixServer server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.ArrayList;
import java.util.Arrays;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.same;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@RunWith(org.mockito.junit.MockitoJUnitRunner.class)
public class CompositeFixApplicationAdapterTest {

private CompositeFixApplicationAdapter adapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -49,7 +48,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@RunWith(org.mockito.junit.MockitoJUnitRunner.class)
public class AbstractSessionHandlerTest {

private static final Random RANDOM = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private void stopStreaming(ChannelHandlerContext ctx) {
@Override
public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List<Object> out) throws Exception {
String reqId;
switch (msg.getMessageType()) {
final String messageType = msg.getMessageType();
switch (messageType) {
case MessageTypes.QUOTE_REQUEST:
reqId = msg.getString(FieldType.QuoteReqID);
subscriptions.put(reqId, ctx);
Expand All @@ -90,6 +91,8 @@ public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List<Object> ou
subscriptions.remove(reqId);
LOGGER.debug("Unsubscribed with QuoteReqID={}", reqId);
break;
default:
LOGGER.debug("Unsupported message type: {}", messageType);
}
}

Expand Down

0 comments on commit 540c37b

Please sign in to comment.