Skip to content

Commit

Permalink
Merge pull request #931 from the-thing/fix-test-assertion
Browse files Browse the repository at this point in the history
Fixing test assertion for different JVM's
  • Loading branch information
chrjohn authored Jan 17, 2025
2 parents 8bfaf28 + 369e783 commit 9e81970
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
import org.junit.After;
import quickfix.mina.SocksProxyServer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

public class SSLCertificateTest {

Expand Down Expand Up @@ -191,7 +191,7 @@ public void shouldAuthenticateServerNameUsingServerCommonName() throws Exception

TestInitiator initiator = new TestInitiator(
createInitiatorSettings("single-session/empty.keystore", "single-session/client-cn.truststore",
CIPHER_SUITES_TLS, "TLSv1.2", "ZULU", "ALFA", Integer.toString(freePort), "JKS", "JKS"));
CIPHER_SUITES_TLS, "TLSv1.2", "ZULU", "ALFA", Integer.toString(freePort), "JKS", "JKS", "HTTPS"));

try {
initiator.start();
Expand Down Expand Up @@ -226,7 +226,7 @@ public void shouldAuthenticateServerNameUsingSNIExtension() throws Exception {

TestInitiator initiator = new TestInitiator(
createInitiatorSettings("single-session/empty.keystore", "single-session/client-sni.truststore",
CIPHER_SUITES_TLS, "TLSv1.2", "ZULU", "ALFA", Integer.toString(freePort), "JKS", "JKS"));
CIPHER_SUITES_TLS, "TLSv1.2", "ZULU", "ALFA", Integer.toString(freePort), "JKS", "JKS", "HTTPS"));

try {
initiator.start();
Expand Down Expand Up @@ -786,7 +786,7 @@ public void assertSslExceptionThrown() throws Exception {
assertSslExceptionThrown(null, null);
}

public void assertSslExceptionThrown(String errorMessage, Class<?> errorType) throws Exception {
public void assertSslExceptionThrown(String expectedErrorMessage, Class<?> expectedErrorType) throws Exception {
boolean reachedZero = exceptionThrownLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);

if (!reachedZero) {
Expand All @@ -795,12 +795,14 @@ public void assertSslExceptionThrown(String errorMessage, Class<?> errorType) th

Throwable throwable = exception.get();

if (errorMessage != null) {
assertEquals(errorMessage, throwable.getMessage());
if (expectedErrorMessage != null) {
String thrownErrorMessage = throwable.getMessage();
assertTrue("Thrown error message: " + thrownErrorMessage + " does not contain: " + expectedErrorMessage,
thrownErrorMessage != null && thrownErrorMessage.contains(expectedErrorMessage));
}

if (errorType != null) {
assertSame(errorType, throwable.getClass());
if (expectedErrorType != null) {
assertSame(expectedErrorType, throwable.getClass());
}
}

Expand Down

0 comments on commit 9e81970

Please sign in to comment.