Skip to content

Commit

Permalink
Merge pull request MovingBlocks#3112 by @theobisproject - Checkstyle …
Browse files Browse the repository at this point in the history
…fixes

Fixes various infos, warnings and errors from the checkstyle analysis
  • Loading branch information
oniatus committed Sep 30, 2017
2 parents 9ac9240 + bac835b commit 799ba94
Show file tree
Hide file tree
Showing 86 changed files with 266 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
*/
public class HeadlessEnvironment extends Environment {

protected static final WorldTime worldTime = new WorldTimeImpl();
protected static final WorldTime WORLD_TIME = new WorldTimeImpl();
private static final Logger logger = LoggerFactory.getLogger(HeadlessEnvironment.class);

/**
Expand Down Expand Up @@ -314,7 +314,7 @@ protected void setupComponentManager() {
protected void setupWorldProvider() {
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
when(worldProvider.getTime()).thenReturn(worldTime);
when(worldProvider.getTime()).thenReturn(WORLD_TIME);
context.put(WorldProvider.class, worldProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public abstract class TerasologyTestingEnvironment {

private static HeadlessEnvironment env;

protected EngineTime mockTime;
private EngineEntityManager engineEntityManager;
private ComponentSystemManager componentSystemManager;
protected EngineTime mockTime;

@BeforeClass
public static void setupEnvironment() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public void testSubscribedRemove() throws Exception {
SimpleUri id = new SimpleUri("engine-tests:TestSetting");
Setting setting = new MockSetting(id);
config.add(setting);
setting.subscribe(propertyChangeEvent -> {});
setting.subscribe(propertyChangeEvent -> {
});

assertFalse(config.remove(id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class MockSetting<T> implements Setting<T> {
private final SimpleUri id;
private boolean isSubscribedTo = false;
private boolean isSubscribedTo;

MockSetting(SimpleUri id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public void testSetEventCall() {

Random random = new FastRandom();

final int MAX_SET_VALUE_COUNT = 50;
final int maxSetValueCount = 50;
int expectedEventCallCount = 0;

for (int i = 0; i < MAX_SET_VALUE_COUNT; i++) {
for (int i = 0; i < maxSetValueCount; i++) {
int randomInt = random.nextInt(-50, 150);
expectedEventCallCount += setting.setValue(randomInt) ? 1 : 0;
}
Expand All @@ -109,15 +109,15 @@ public void testSetEventCall() {

@Test
public void testSubscribe() {
final int SUBSCRIBER_COUNT = 10;
final int subscriberCount = 10;

for (int i = 0; i < SUBSCRIBER_COUNT; i++) {
for (int i = 0; i < subscriberCount; i++) {
setting.subscribe(propertyChangeEvent -> eventCallCount++);
}

setting.setValue(30);

assertEquals(SUBSCRIBER_COUNT, eventCallCount);
assertEquals(subscriberCount, eventCallCount);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@

public class ServiceApiRequestTests {

static class DummySerializableObject {
@Test
public void testRequest() throws IOException, StorageServiceException {
Gson gson = new Gson();
HttpURLConnection mockedConn = mock(HttpURLConnection.class);
ByteArrayOutputStream receivedRequest = new ByteArrayOutputStream();
ByteArrayInputStream response = new ByteArrayInputStream("{\"fieldA\":\"response\", \"fieldB\": 1}".getBytes());

when(mockedConn.getOutputStream()).thenReturn(receivedRequest);
when(mockedConn.getInputStream()).thenReturn(response);
when(mockedConn.getResponseCode()).thenReturn(200);

DummySerializableObject reqData = new DummySerializableObject("request", 0);
DummySerializableObject resData = ServiceApiRequest.request(mockedConn, HttpMethod.GET, null, reqData, DummySerializableObject.class);
assertEquals(gson.toJson(reqData), receivedRequest.toString());
assertEquals(new DummySerializableObject("response", 1), resData);
}

static final class DummySerializableObject {
private String fieldA;
private int fieldB;

Expand All @@ -48,21 +65,4 @@ public boolean equals(Object other) {
return fieldA.equals(o.fieldA) && fieldB == o.fieldB;
}
}

@Test
public void testRequest() throws IOException, StorageServiceException {
Gson gson = new Gson();
HttpURLConnection mockedConn = mock(HttpURLConnection.class);
ByteArrayOutputStream receivedRequest = new ByteArrayOutputStream();
ByteArrayInputStream response = new ByteArrayInputStream("{\"fieldA\":\"response\", \"fieldB\": 1}".getBytes());

when(mockedConn.getOutputStream()).thenReturn(receivedRequest);
when(mockedConn.getInputStream()).thenReturn(response);
when(mockedConn.getResponseCode()).thenReturn(200);

DummySerializableObject reqData = new DummySerializableObject("request", 0);
DummySerializableObject resData = ServiceApiRequest.request(mockedConn, HttpMethod.GET, null, reqData, DummySerializableObject.class);
assertEquals(gson.toJson(reqData), receivedRequest.toString());
assertEquals(new DummySerializableObject("response", 1), resData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public void testNetwork() throws Exception {
EngineEntityManager entityManager = getEntityManager();
EngineTime time = mock(EngineTime.class);
NetworkSystem server = new NetworkSystemImpl(time, context);
server.setStateContext(context);
server.setContext(context);
netSystems.add(server);
server.connectToEntitySystem(entityManager, context.get(EventLibrary.class), null);
server.host(7777, true);

Thread.sleep(500);

NetworkSystem client = new NetworkSystemImpl(time, context);
client.setStateContext(context);
client.setContext(context);
netSystems.add(client);
client.join("localhost", 7777);

Expand All @@ -88,7 +88,7 @@ public void testEntityNetworkIdChangedOnServerStart() throws HostingFailedExcept
EntityRef entity = entityManager.create(netComp);
EngineTime time = mock(EngineTime.class);
NetworkSystem server = new NetworkSystemImpl(time, context);
server.setStateContext(context);
server.setContext(context);
netSystems.add(server);
server.connectToEntitySystem(entityManager, context.get(EventLibrary.class), null);
server.host(7777, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setup() throws Exception {
context.put(ModuleManager.class, moduleManager);
EngineTime mockTime = mock(EngineTime.class);
networkSystem = new NetworkSystemImpl(mockTime, context);
networkSystem.setStateContext(context);
networkSystem.setContext(context);
context.put(NetworkSystem.class, networkSystem);

EntitySystemSetupUtil.addReflectionBasedLibraries(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ public void testConstructorInjectionNoDefaultConstructorForFallback() {

//test classes and interfaces for injection

private static interface ServiceA {
private interface ServiceA {

}

private static interface ServiceB {
private interface ServiceB {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testReducePersistingStateChangesEcho() {

@SuppressWarnings("static-access") // actual node classes are not meant to be static
private class AlphaNode extends AbstractNode {
public AlphaNode() {
AlphaNode() {
addDesiredStateChange(new SetName("foo"));
}

Expand All @@ -110,7 +110,7 @@ public void process() { }

@SuppressWarnings("static-access") // actual node classes are not meant to be static
private class BravoNode extends AbstractNode {
public BravoNode() {
BravoNode() {
addDesiredStateChange(new SetName("foo"));
}

Expand All @@ -120,7 +120,7 @@ public void process() { }

@SuppressWarnings("static-access") // actual node classes are not meant to be static
private class CharlieNode extends AbstractNode {
public CharlieNode() {
CharlieNode() {
addDesiredStateChange(new SetName("foo"));
}

Expand All @@ -130,7 +130,7 @@ public void process() { }

@SuppressWarnings("static-access") // actual node classes are not meant to be static
private class DeltaNode extends AbstractNode {
public DeltaNode() {
DeltaNode() {
addDesiredStateChange(new SetName("delta"));
}

Expand All @@ -140,7 +140,7 @@ public void process() { }

@SuppressWarnings("static-access") // actual node classes are not meant to be static
private class EchoNode extends AbstractNode {
public EchoNode() { }
EchoNode() { }

@Override
public void process() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public void testAllRelativeWidths() throws Exception {

//Width split according to the relative widths of the widgets
// Gets 4/10 of the entire area
final int WIDTH_1 = CANVAS_WIDTH * 4 / 10;
final int width1 = CANVAS_WIDTH * 4 / 10;
// Gets 1/2 of the entire area
final int WIDTH_2 = CANVAS_WIDTH / 2;
final int width2 = CANVAS_WIDTH / 2;
// Gets 1/10 of the entire area
final int WIDTH_3 = CANVAS_WIDTH / 10;
final int width3 = CANVAS_WIDTH / 10;

verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, WIDTH_1, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(WIDTH_1, 0, WIDTH_2, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(WIDTH_1 + WIDTH_2, 0, WIDTH_3, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, width1, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(width1, 0, width2, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(width1 + width2, 0, width3, CANVAS_HEIGHT));
}

@Test
Expand Down Expand Up @@ -137,12 +137,12 @@ public void testSomeRelativeWidths() throws Exception {
rowLayout.onDraw(canvas);

//Width first determined for widget with relative width, then split equally among remaining widgets
final int WIDTH_1 = CANVAS_WIDTH / 2;
final int WIDTH_2 = (CANVAS_WIDTH - WIDTH_1) / 2;
final int WIDTH_3 = (CANVAS_WIDTH - WIDTH_1) / 2;
final int width1 = CANVAS_WIDTH / 2;
final int width2 = (CANVAS_WIDTH - width1) / 2;
final int width3 = (CANVAS_WIDTH - width1) / 2;

verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, WIDTH_1, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(WIDTH_1, 0, WIDTH_2, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(WIDTH_1 + WIDTH_2, 0, WIDTH_3, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, width1, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(width1, 0, width2, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(width1 + width2, 0, width3, CANVAS_HEIGHT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public BindsConfig() {
* @return True if newInput has been bound. False otherwise.
*/
public boolean isBound(Input newInput) {
return newInput != null && data.containsValue(newInput) ;
return newInput != null && data.containsValue(newInput);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public FlexibleConfigImpl() {
/**
* {@inheritDoc}
*/
@Override
public boolean add(Setting setting) {
SimpleUri id = setting.getId();

Expand All @@ -58,6 +59,7 @@ public boolean add(Setting setting) {
/**
* {@inheritDoc}
*/
@Override
public boolean remove(SimpleUri id) {
Setting setting = get(id);

Expand All @@ -76,6 +78,7 @@ public boolean remove(SimpleUri id) {
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public <V> Setting<V> get(SimpleUri id) {
return (Setting<V>) settingMap.get(id);
Expand All @@ -84,6 +87,7 @@ public <V> Setting<V> get(SimpleUri id) {
/**
* {@inheritDoc}
*/
@Override
public boolean contains(SimpleUri id) {
return settingMap.containsKey(id);
}
Expand Down
Loading

0 comments on commit 799ba94

Please sign in to comment.