Skip to content

Commit

Permalink
Rename class
Browse files Browse the repository at this point in the history
  • Loading branch information
odenix committed Feb 22, 2024
1 parent 5127f4c commit a01b108
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions pkl-core/src/main/java/org/pkl/core/http/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManagerFactory;
import org.pkl.core.util.ErrorMessages;
import org.pkl.core.util.ExceptionUtils;
import org.pkl.core.util.Exceptions;

@ThreadSafe
final class JdkHttpClient implements HttpClient {
Expand Down Expand Up @@ -94,7 +94,7 @@ public <T> HttpResponse<T> send(HttpRequest request, BodyHandler<T> responseBody
} catch (SSLHandshakeException e) {
throw new SSLHandshakeException(
ErrorMessages.create(
"errorSslHandshake", request.uri().getHost(), ExceptionUtils.getRootReason(e)));
"errorSslHandshake", request.uri().getHost(), Exceptions.getRootReason(e)));
} catch (InterruptedException e) {
// next best thing after letting (checked) InterruptedException bubble up
Thread.currentThread().interrupt();
Expand Down Expand Up @@ -140,7 +140,7 @@ private static SSLContext createSslContext(
return sslContext;
} catch (GeneralSecurityException e) {
throw new HttpClientInitException(
ErrorMessages.create("cannotInitHttpClient", ExceptionUtils.getRootReason(e)), e);
ErrorMessages.create("cannotInitHttpClient", Exceptions.getRootReason(e)), e);
}
}

Expand All @@ -155,7 +155,7 @@ private static Set<TrustAnchor> createTrustAnchors(
throw new HttpClientInitException(ErrorMessages.create("cannotFindCertFile", file));
} catch (IOException e) {
throw new HttpClientInitException(
ErrorMessages.create("cannotReadCertFile", ExceptionUtils.getRootReason(e)));
ErrorMessages.create("cannotReadCertFile", Exceptions.getRootReason(e)));
}
}

Expand All @@ -164,7 +164,7 @@ private static Set<TrustAnchor> createTrustAnchors(
collectTrustAnchors(anchors, factory, stream, url);
} catch (IOException e) {
throw new HttpClientInitException(
ErrorMessages.create("cannotReadCertFile", ExceptionUtils.getRootReason(e)));
ErrorMessages.create("cannotReadCertFile", Exceptions.getRootReason(e)));
}
}

Expand All @@ -182,7 +182,7 @@ private static void collectTrustAnchors(
certificates = (Collection<X509Certificate>) factory.generateCertificates(stream);
} catch (CertificateException e) {
throw new HttpClientInitException(
ErrorMessages.create("cannotParseCertFile", source, ExceptionUtils.getRootReason(e)));
ErrorMessages.create("cannotParseCertFile", source, Exceptions.getRootReason(e)));
}
if (certificates.isEmpty()) {
throw new HttpClientInitException(ErrorMessages.create("emptyCertFile", source));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.pkl.core.util;

public final class ExceptionUtils {
private ExceptionUtils() {}
public final class Exceptions {
private Exceptions() {}

public static Throwable getRootCause(Throwable t) {
var result = t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import org.junit.jupiter.api.Test
import java.io.IOException
import java.lang.Error

class ExceptionUtilsTest {
class ExceptionsTest {
@Test
fun `get root cause of simple exception`() {
val e = IOException("io")
assertThat(ExceptionUtils.getRootCause(e)).isSameAs(e)
assertThat(Exceptions.getRootCause(e)).isSameAs(e)
}

@Test
Expand All @@ -19,30 +19,30 @@ class ExceptionUtilsTest {
val e3 = Error("error")
e.initCause(e2)
e2.initCause(e3)
assertThat(ExceptionUtils.getRootCause(e)).isSameAs(e3)
assertThat(Exceptions.getRootCause(e)).isSameAs(e3)
}

@Test
fun `get root reason`() {
val e = IOException("io")
val e2 = RuntimeException("the root reason")
e.initCause(e2)
assertThat(ExceptionUtils.getRootReason(e)).isEqualTo("the root reason")
assertThat(Exceptions.getRootReason(e)).isEqualTo("the root reason")
}

@Test
fun `get root reason if null`() {
val e = IOException("io")
val e2 = RuntimeException(null as String?)
e.initCause(e2)
assertThat(ExceptionUtils.getRootReason(e)).isEqualTo("(unknown reason)")
assertThat(Exceptions.getRootReason(e)).isEqualTo("(unknown reason)")
}

@Test
fun `get root reason if empty`() {
val e = IOException("io")
val e2 = RuntimeException("")
e.initCause(e2)
assertThat(ExceptionUtils.getRootReason(e)).isEqualTo("(unknown reason)")
assertThat(Exceptions.getRootReason(e)).isEqualTo("(unknown reason)")
}
}

0 comments on commit a01b108

Please sign in to comment.