package io.ljunggren.usps.api.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class HttpStatusCodeTest {

    @Test
    void getByCodeReturnsMatchingEnum() {
        assertEquals(HttpStatusCode.NOT_FOUND, HttpStatusCode.getByCode(404));
    }

    @Test
    void getByCodeReturnsNullForUnknownCode() {
        assertNull(HttpStatusCode.getByCode(999));
    }

    @Test
    void getTextByCodeReturnsTextForKnownCode() {
        assertEquals("Forbidden", HttpStatusCode.getTextByCode(403));
    }

    @Test
    void getTextByCodeReturnsNullForUnknownCode() {
        assertNull(HttpStatusCode.getTextByCode(999));
    }

    @Test
    void isRetryableTrueForThrottlingServerErrorAndUnavailable() {
        assertTrue(HttpStatusCode.THROTTLING.isRetryable());
        assertTrue(HttpStatusCode.SERVER_ERROR.isRetryable());
        assertTrue(HttpStatusCode.SERVICE_UNAVAILABLE.isRetryable());
    }

    @Test
    void isRetryableFalseForOkAndBadRequest() {
        assertFalse(HttpStatusCode.OK.isRetryable());
        assertFalse(HttpStatusCode.BAD_REQUEST.isRetryable());
    }

}
