001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2016 Richard "Shred" Körber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.exception;
015
016import static org.assertj.core.api.Assertions.assertThat;
017import static org.mockito.Mockito.mock;
018
019import java.net.URL;
020
021import org.junit.jupiter.api.Test;
022import org.shredzone.acme4j.AcmeResource;
023import org.shredzone.acme4j.Login;
024import org.shredzone.acme4j.toolbox.TestUtils;
025
026/**
027 * Unit tests for {@link AcmeLazyLoadingException}.
028 */
029public class AcmeLazyLoadingExceptionTest {
030
031    private final URL resourceUrl = TestUtils.url("http://example.com/acme/resource/123");
032
033    @Test
034    public void testAcmeLazyLoadingException() {
035        var login = mock(Login.class);
036        var resource = new TestResource(login, resourceUrl);
037
038        var cause = new AcmeException("Something went wrong");
039
040        var ex = new AcmeLazyLoadingException(resource, cause);
041        assertThat(ex).isInstanceOf(RuntimeException.class);
042        assertThat(ex.getMessage()).contains(resourceUrl.toString());
043        assertThat(ex.getMessage()).contains(TestResource.class.getSimpleName());
044        assertThat(ex.getCause()).isEqualTo(cause);
045        assertThat(ex.getType()).isEqualTo(TestResource.class);
046        assertThat(ex.getLocation()).isEqualTo(resourceUrl);
047    }
048
049    private static class TestResource extends AcmeResource {
050        private static final long serialVersionUID = 1023419539450677538L;
051
052        public TestResource(Login login, URL location) {
053            super(login, location);
054        }
055    }
056
057}