content: package net.amygdalum.testrecorder.deserializers.builder;
  
  import static net.amygdalum.testrecorder.TestAgentConfiguration.defaultConfig;
  import static net.amygdalum.testrecorder.values.SerializedLiteral.literal;
  import static org.assertj.core.api.Assertions.assertThat;
  
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  
  import net.amygdalum.testrecorder.deserializers.Adaptors;
  import net.amygdalum.testrecorder.deserializers.DefaultDeserializerContext;
  import net.amygdalum.testrecorder.deserializers.Deserializer;
  import net.amygdalum.testrecorder.profile.AgentConfiguration;
  import net.amygdalum.testrecorder.types.Computation;
  import net.amygdalum.testrecorder.types.DeserializerContext;
  import net.amygdalum.testrecorder.types.FieldSignature;
  import net.amygdalum.testrecorder.types.SerializedField;
  import net.amygdalum.testrecorder.util.testobjects.Simple;
  import net.amygdalum.testrecorder.values.SerializedObject;
  
  public class DefaultObjectAdaptorTest {
  
  	private AgentConfiguration config;
  	private DefaultObjectAdaptor adaptor;
  	private DeserializerContext context;
  
  	@BeforeEach
  	public void before() throws Exception {
  		config = defaultConfig();
  		adaptor = new DefaultObjectAdaptor();
  		context = new DefaultDeserializerContext();
  	}
  
  	@Test
  	public void testParentNull() throws Exception {
  		assertThat(adaptor.parent()).isNull();
  	}
  
  	@Test
  	public void testMatchesAnyObject() throws Exception {
  		assertThat(adaptor.matches(Object.class)).isTrue();
  		assertThat(adaptor.matches(new Object() {
  		}.getClass())).isTrue();
  	}
  
  	@Test
  	public void testTryDeserializeWithNonBean() throws Exception {
  		SerializedObject value = new SerializedObject(Simple.class);
  		value.addField(new SerializedField(new FieldSignature(String.class, String.class, "str"), literal("Hello World")));
  		Deserializer generator = generator();
  
  		Computation result = adaptor.tryDeserialize(value, generator);
  
  		assertThat(result.getStatements().toString()).containsSubsequence(
  			"Simple simple1 = new GenericObject",
  			"String str = \"Hello World\"",
  			"as(Simple.class)");
  		assertThat(result.getValue()).isEqualTo("simple1");
  	}
  
  	private Deserializer generator() {
  		return new SetupGenerators(new Adaptors().load(config.loadConfigurations(SetupGenerator.class))).newGenerator(context);
  	}
  
  }
  