Skip to content

Commit

Permalink
Increase test coverage (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsKev authored Jan 30, 2022
1 parent 94167ef commit e3bfa51
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class PlayerCountManager {

public static final String SET_MAX_PLAYER_COUNT_PERMISSIONS = "player.count.max";
private static final String BYPASS_MAX_PLAYER_COUNT_PERMISSIONS = "player.count.max.bypass";
protected static final String BYPASS_MAX_PLAYER_COUNT_PERMISSIONS = "player.count.max.bypass";

private final Map<String, PlayerCountChanged> servers = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kryonite.kryoproxysync.messaging;

import static org.kryonite.kryoproxysync.messaging.MessagingController.MAINTENANCE_CHANGED_EXCHANGE;
import static org.kryonite.kryoproxysync.messaging.MessagingController.MAX_PLAYER_COUNT_CHANGED_EXCHANGE;
import static org.kryonite.kryoproxysync.messaging.MessagingController.PLAYER_COUNT_CHANGED_EXCHANGE;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -20,6 +21,7 @@
import org.kryonite.kryoproxysync.messaging.consumer.MaintenanceChangedConsumer;
import org.kryonite.kryoproxysync.messaging.consumer.PlayerCountChangedConsumer;
import org.kryonite.kryoproxysync.messaging.message.MaintenanceChanged;
import org.kryonite.kryoproxysync.messaging.message.MaxPlayerCountChanged;
import org.kryonite.kryoproxysync.messaging.message.PlayerCountChanged;
import org.kryonite.kryoproxysync.playercount.PlayerCountManager;
import org.mockito.Answers;
Expand Down Expand Up @@ -100,4 +102,17 @@ void shouldSendMaintenanceChanged() {
verify(messagingServiceMock).sendMessage(Message.create(MAINTENANCE_CHANGED_EXCHANGE,
new MaintenanceChanged(maintenance)));
}

@Test
void shouldSendMaxPlayerCountChanged() {
// Arrange
int count = 5;

// Act
testee.sendMaxPlayerCountChanged(count);

// Assert
verify(messagingServiceMock).sendMessage(Message.create(MAX_PLAYER_COUNT_CHANGED_EXCHANGE,
new MaxPlayerCountChanged(count)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.kryonite.kryoproxysync.persistence.repository.impl.MariaDbConfigRepository.CREATE_CONFIG_TABLE;
import static org.kryonite.kryoproxysync.persistence.repository.impl.MariaDbConfigRepository.GET_CONFIG;
import static org.kryonite.kryoproxysync.persistence.repository.impl.MariaDbConfigRepository.INSERT_INITIAL_ENTRY;
import static org.kryonite.kryoproxysync.persistence.repository.impl.MariaDbConfigRepository.UPDATE_MAX_PLAYER_COUNT;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -77,4 +78,19 @@ void shouldReturnEmptyList_WhenSamplePlayersIsEmpty() throws SQLException {
// Assert
assertEquals(serverPingEntity, result);
}

@Test
void shouldSetMaxPlayerCount() throws SQLException {
// Arrange
int count = 6;

MariaDbConfigRepository testee = new MariaDbConfigRepository(dataSource);

// Act
testee.setMaxPlayerCount(count);

// Assert
verify(dataSource.getConnection().prepareStatement(UPDATE_MAX_PLAYER_COUNT)).setInt(1, count);
verify(dataSource.getConnection().prepareStatement(UPDATE_MAX_PLAYER_COUNT)).executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ void shouldRemoveOldServerEntries() {
assertEquals(count2, testee.getPlayerCount());
}

@Test
void shouldJoinServerWithSpecificPermission() {
// Arrange
testee = new PlayerCountManager(configRepositoryMock);
Player player = mock(Player.class);
when(player.hasPermission(PlayerCountManager.BYPASS_MAX_PLAYER_COUNT_PERMISSIONS)).thenReturn(true);

// Act
boolean result = testee.canJoinServer(player);

// Assert
assertTrue(result);
}

@Test
void shouldUpdateMaxPlayerCount() throws SQLException {
// Arrange
Expand Down

0 comments on commit e3bfa51

Please sign in to comment.