Skip to content

Commit

Permalink
ci: Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent4vx committed Jul 19, 2024
1 parent bf13054 commit 40c0cd2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public String[] arguments() {
return arguments;
}

@Override
public String toString() {
return "GameActionRequest{type=" + type + ", arguments=" + String.join(";", arguments) + '}';
}

public static final class Parser implements SinglePacketParser<GameActionRequest> {
@Override
public GameActionRequest parse(String input) throws ParsePacketException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ void exceptionConnectionResetShouldBeIgnored() {
Mockito.verifyNoInteractions(logger);
}

@Test
void exceptionIOExceptionNotConnectionResetShouldBeLogged() {
IOException e = new IOException("foo");
session.exception(e);

Mockito.verify(logger).error(MarkerManager.getMarker("NETWORK_ERROR"), "[{}] Uncaught exception", session, e);
}

@Test
void exceptionWithPacket() {
Exception e = new Exception("my error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand All @@ -55,7 +56,7 @@ public Class<Packet> packet() {
};

assertThrows(ErrorPacket.class, () -> handler.handle(session, new Packet() {}));
assertEquals(false, called.get());
assertFalse(called.get());
}

@RepeatedIfExceptionsTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package fr.quatrevieux.araknemu.game.handler.fight;

import fr.quatrevieux.araknemu.core.network.exception.CloseImmediately;
import fr.quatrevieux.araknemu.core.network.exception.ErrorPacket;
import fr.quatrevieux.araknemu.game.fight.Fight;
import fr.quatrevieux.araknemu.game.fight.FightBaseCase;
Expand All @@ -32,8 +31,8 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

class ChangeFighterStartPlaceTest extends FightBaseCase {
private ChangeFighterStartPlace handler;
Expand Down Expand Up @@ -79,6 +78,18 @@ void handleSuccess() throws Exception {
assertEquals(123, fighter.cell().id());
}

@Test
void handleInvalidState() throws Exception {
fight = createFight();
fighter = player.fighter();

fight.nextState();
handler.handle(session, new FighterChangePlace(123));

requestStack.assertLast(new ChangeFighterPlaceError());
assertNotEquals(123, fighter.cell().id());
}

@Test
void functionalNotInFight() {
assertThrows(ErrorPacket.class, () -> handlePacket(new FighterChangePlace(123)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import fr.quatrevieux.araknemu.core.network.exception.CloseWithPacket;
import fr.quatrevieux.araknemu.core.network.exception.ErrorPacket;
import fr.quatrevieux.araknemu.core.network.exception.RateLimitException;
import fr.quatrevieux.araknemu.core.network.exception.WritePacket;
import fr.quatrevieux.araknemu.core.network.session.ConfigurableSession;
import fr.quatrevieux.araknemu.game.GameBaseCase;
import fr.quatrevieux.araknemu.network.game.out.account.LoginTokenError;
Expand Down Expand Up @@ -74,6 +75,26 @@ void exceptionCaughtWritePacket() {
requestStack.assertLast(new LoginTokenError());
}

@Test
void exceptionCaughtWritePacketWithThrowableWillNotLogError() {
class MyFatalError extends Throwable implements WritePacket {
@Override
public String getMessage() {
return "my error message";
}

@Override
public Object packet() {
return "packet";
}
}

gameSession.exception(new MyFatalError());

requestStack.assertLast("packet");
Mockito.verifyNoInteractions(logger);
}

@Test
void exceptionCaughtWritePacketWithMessage() {
gameSession.exception(new ErrorPacket("my error message", new LoginTokenError()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ void parseInvalid() {
GameActionRequest.Parser parser = new GameActionRequest.Parser();

assertThrows(ParsePacketException.class, () -> parser.parse("02"));
}

@Test
void string() {
GameActionRequest ga = new GameActionRequest(1, new String[] {"foo", "bar"});

assertEquals("GameActionRequest{type=1, arguments=foo;bar}", ga.toString());
}
}

0 comments on commit 40c0cd2

Please sign in to comment.