Skip to content

Commit

Permalink
refactor: Added assertEqualsMessage()
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed May 30, 2024
1 parent 7276c18 commit 046f119
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;

import com.tsurugidb.iceaxe.TsurugiConnector;
import com.tsurugidb.iceaxe.session.TgSessionOption;
Expand All @@ -36,12 +35,7 @@ void connectError() throws Exception {
thread.start();

var e = assertThrowsExactly(IOException.class, () -> connect(port));
try {
assertEquals("lost connection", e.getMessage());
} catch (AssertionFailedError t) {
t.addSuppressed(e);
throw t;
}
assertEqualsMessage("lost connection", e);
}
}

Expand Down Expand Up @@ -77,11 +71,7 @@ void recvIllegalMessage() throws Exception {
thread.start();

var e = assertThrowsExactly(IOException.class, () -> connect(port));
try {
assertEquals("lost connection", e.getMessage());
} catch (AssertionFailedError t) {
throw e;
}
assertEqualsMessage("lost connection", e);
}
}

Expand Down Expand Up @@ -138,7 +128,7 @@ void sendIllegalMessage() throws Exception {
int len = is.read(buf);
assertEquals(-1, len);
} catch (SocketException e) {
assertEquals("Connection reset", e.getMessage());
assertEqualsMessage("Connection reset", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void selectAsGeneratedRowid() throws Exception {
var e = assertThrowsExactly(IllegalArgumentException.class, () -> {
entity.getInt(GENERATED_KEY);
});
assertEquals("not found column. name=__generated_rowid___test", e.getMessage());
assertEqualsMessage("not found column. name=__generated_rowid___test", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tsurugidb.iceaxe.test.select;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;

import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -44,7 +43,7 @@ void getInt_null() throws Exception {
transaction.executeAndFindRecord(ps);
});
});
assertEquals("TsurugiResultRecord.getInt(foo) is null", e.getMessage());
assertEqualsMessage("TsurugiResultRecord.getInt(foo) is null", e);
}
}

Expand All @@ -61,7 +60,7 @@ void nextInt_null() throws Exception {
transaction.executeAndFindRecord(ps);
});
});
assertEquals("TsurugiResultRecord.nextInt(0) is null", e.getMessage());
assertEqualsMessage("TsurugiResultRecord.nextInt(0) is null", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tsurugidb.iceaxe.test.select;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;

Expand Down Expand Up @@ -133,7 +132,7 @@ private void ps0ExecuteAfterTxClose(boolean getLow) throws IOException, Interrup
transaction.executeAndGetList(ps);
});
assertEqualsCode(IceaxeErrorCode.TX_ALREADY_CLOSED, e);
assertEquals("transaction already closed", e.getMessage());
assertEqualsMessage("transaction already closed", e);
}
}

Expand All @@ -150,7 +149,7 @@ void selectAfterTransactionClose() throws Exception {
var e = assertThrowsExactly(IOException.class, () -> {
result.getRecordList();
});
assertEquals("resultSet already closed", e.getMessage());
assertEqualsMessage("resultSet already closed", e);
}
}

Expand All @@ -170,7 +169,7 @@ void selectInTransactionClose() throws Exception {
i.next();
}
});
assertEquals("resultSet already closed", e.getMessage());
assertEqualsMessage("resultSet already closed", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void limit() throws Exception {
try {
session = DbTestConnector.createSession();
} catch (IOException e) {
assertEquals("the server has declined the connection request", e.getMessage());
assertEqualsMessage("the server has declined the connection request", e);
int count = sessionList.size();
if (count < EXPECTED_SESSION_SIZE) {
fail(MessageFormat.format("less session.size expected: {1} but was: {0}", count, EXPECTED_SESSION_SIZE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.opentest4j.AssertionFailedError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -580,6 +581,15 @@ protected static void assertMatches(String expectedRegexp, String actual) {
assertEquals(expectedRegexp, actual, "unmatched");
}

protected static void assertEqualsMessage(String expected, Throwable actual) {
try {
assertEquals(expected, actual.getMessage());
} catch (AssertionFailedError e) {
e.addSuppressed(actual);
throw e;
}
}

protected static void assertUpdateCount(int expected, int actual) {
assertEquals(expected, actual);
}
Expand Down

0 comments on commit 046f119

Please sign in to comment.