com.almondtools.testrecorder.ContextSnapshotFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testrecorder Show documentation
Show all versions of testrecorder Show documentation
Recording test data from running program.
The newest version!
package com.almondtools.testrecorder;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.List;
import com.almondtools.testrecorder.profile.DefaultSerializationProfile;
public class ContextSnapshotFactory {
private SerializationProfile profile;
private Class> declaringClass;
private Type resultType;
private String methodName;
private Type[] argumentTypes;
public ContextSnapshotFactory(Class> declaringClass, Snapshot snapshot, Type resultType, String methodName, Type... argumentTypes) {
this.declaringClass = declaringClass;
this.profile = instantiate(snapshot.profile());
this.resultType = resultType;
this.methodName = methodName;
this.argumentTypes = argumentTypes;
}
private SerializationProfile instantiate(Class extends SerializationProfile> profile) {
try {
return profile.newInstance();
} catch (InstantiationException | IllegalAccessException | NullPointerException e) {
return new DefaultSerializationProfile();
}
}
public SerializationProfile profile() {
return profile;
}
public List getGlobalFields() {
return profile.getGlobalFields();
}
public ContextSnapshot createSnapshot() {
return new ContextSnapshot(declaringClass, resultType, methodName, argumentTypes);
}
}