package de.accso.flexinale.common.shared_kernel;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

class RawWrapperTest {

    private record  StringWrapper(String raw)  implements RawWrapper<String> {}
    private record IntegerWrapper(Integer raw) implements RawWrapper<Integer> {}

    @Test
    public void testStringWrapperWithString() {
        // arrange
        StringWrapper sut = new StringWrapper("test");

        // act
        String rawOrNull = RawWrapper.getRawOrNull(sut);

        // assert
        assertThat(rawOrNull.getClass()).isEqualTo(String.class);
        assertThat(rawOrNull).isEqualTo("test");
    }

    @Test
    public void testStringWrapperWithNull() {
        // arrange
        StringWrapper sut = new StringWrapper(null);

        // act
        String rawOrNull = RawWrapper.getRawOrNull(sut);

        // assert
        assertThat(rawOrNull).isNull();
    }

    @Test
    public void testIntegerWrapperWithInteger() {
        // arrange
        IntegerWrapper sut = new IntegerWrapper(1);

        // act
        Integer rawOrNull = RawWrapper.getRawOrNull(sut);

        // assert
        assertThat(rawOrNull.getClass()).isEqualTo(Integer.class);
        assertThat(rawOrNull).isEqualTo(1);
    }

    @Test
    public void testIntegerWrapperWithNull() {
        // arrange
        IntegerWrapper sut = new IntegerWrapper(null);

        // act
        Integer rawOrNull = RawWrapper.getRawOrNull(sut);

        // assert
        assertThat(rawOrNull).isNull();
    }
}