package com.github.nylle.javafixture;

import com.github.nylle.javafixture.testobjects.TestObjectWithGenericConstructor;
import com.github.nylle.javafixture.testobjects.TestObjectWithoutDefaultConstructor;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;

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

class InstanceFactoryTest {

    @Test
    void canCreateInstanceFromConstructor() {

        var sut = new InstanceFactory(new SpecimenFactory(new Context(Configuration.configure().useRandomConstructor(true))));

        TestObjectWithoutDefaultConstructor result = sut.construct(SpecimenType.fromClass(TestObjectWithoutDefaultConstructor.class));

        assertThat(result).isInstanceOf(TestObjectWithoutDefaultConstructor.class);
        assertThat(result.getStrings()).isInstanceOf(List.class);
        assertThat(result.getStrings()).isNotEmpty();
        assertThat(result.getStrings().get(0)).isInstanceOf(String.class);
    }

    @Test
    void optionalsAreNeverPresent() {

        var sut = new InstanceFactory(new SpecimenFactory(new Context(Configuration.configure().useRandomConstructor(true))));

        TestObjectWithGenericConstructor result = sut.construct(SpecimenType.fromClass(TestObjectWithGenericConstructor.class));

        assertThat(result).isInstanceOf(TestObjectWithGenericConstructor.class);
        assertThat(result.getInteger()).isInstanceOf(Optional.class);
        assertThat(result.getInteger()).isNotPresent();
    }

    @Test
    void fieldsNotSetByConstructorAreNull() {

        var sut = new InstanceFactory(new SpecimenFactory(new Context(Configuration.configure().useRandomConstructor(true))));

        TestObjectWithGenericConstructor result = sut.construct(SpecimenType.fromClass(TestObjectWithGenericConstructor.class));

        assertThat(result).isInstanceOf(TestObjectWithGenericConstructor.class);
        assertThat(result.getPrivateField()).isNull();
    }
}
@@ -118,93 +118,8 @@
 or;%0A
-import com.github.nylle.javafixture.testobjects.TestObjectWithoutDefaultConstructor;%0A
 impo
@@ -154,31 +154,8 @@
 t;%0A%0A
-import java.util.List;%0A
 impo
@@ -422,634 +422,8 @@
 re()
-.useRandomConstructor(true))));%0A%0A        TestObjectWithoutDefaultConstructor result = sut.construct(SpecimenType.fromClass(TestObjectWithoutDefaultConstructor.class));%0A%0A        assertThat(result).isInstanceOf(TestObjectWithoutDefaultConstructor.class);%0A        assertThat(result.getStrings()).isInstanceOf(List.class);%0A        assertThat(result.getStrings()).isNotEmpty();%0A        assertThat(result.getStrings().get(0)).isInstanceOf(String.class);%0A    %7D%0A%0A    @Test%0A    void optionalsAreNeverPresent() %7B%0A%0A        var sut = new InstanceFactory(new SpecimenFactory(new Context(Configuration.configure().useRandomConstructor(true)
 )));
@@ -627,32 +627,98 @@
 tructor.class);%0A
+        assertThat(result.getValue()).isInstanceOf(String.class);%0A
         assertTh
@@ -813,19 +813,16 @@
 er()).is
-Not
 Present(
@@ -820,24 +820,99 @@
 sPresent();%0A
+        assertThat(result.getInteger().get()).isInstanceOf(Integer.class);%0A
     %7D%0A%0A    @
@@ -1062,35 +1062,8 @@
 re()
-.useRandomConstructor(true)
 )));

Fix a compile error introduced by another unfinished feature