Skip to content

Commit

Permalink
Cleanup (#87)
Browse files Browse the repository at this point in the history
* 🧽 Removed unused imports

* 🧽 Removed unused imports

* 🧽 typos
  • Loading branch information
JanSchankin committed Nov 28, 2021
1 parent 8a1dfea commit 622838c
Show file tree
Hide file tree
Showing 26 changed files with 51 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* There are two things you have to care about when using matchers:
* </p>
* <ul>
* <li>You cant't mix matchers and normal parameters when defining a sample.</li>
* <li>You can't mix matchers and normal parameters when defining a sample.</li>
* <li>The order of method calls when defining a sample matters! So you have to call it within the method invocation you want to stub!</li>
* </ul>
* To use your own matcher you have to implement {@link ParameterMatcher} and call {@link Matchers#matcher(ParameterMatcher)} withing the method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* the Sampler manually and to distribute the Sampler into the objects that will be tested. The distribution is done by a Dependency Injection Framework like Spring or Guice.
*
* Methods of the class {@link Object} are ignored. Otherwise strange effects might appear, e.g. if Object::finalize is
* called by the garbage collactor.
* called by the garbage collector.
*
* @author Jan Schankin, Rico Schrage
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import de.ppi.deepsampler.core.model.SampledMethod;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class SampleExecutionInformation {

private SampleDefinition sampleDefinition;
private final SampleDefinition sampleDefinition;
private final List<MethodCall> methodCallList = new ArrayList<>();

public SampleExecutionInformation(SampleDefinition sampleDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package de.ppi.deepsampler.junit;

import de.ppi.deepsampler.core.api.Sampler;
import de.ppi.deepsampler.core.model.SampleRepository;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
/**
* A simple {@link JsonDeserializer} that is used to test the annotations {@link UseJsonSerializer} and {@link UseJsonDeserializer}
* <p>
* {@link MyInstantSerializer} writes an {@link Instant} in a JSON-file and adds a suffix {@link MyInstantSerializer#TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED}
* {@link MyInstantSerializer} writes an {@link Instant} in a JSON-file and adds a suffix {@link MyInstantSerializer#TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED}
* to the persistent Instant. This suffix is used by this {@link MyInstantDeserializer} to ensure that the {@link Instant} was saved by {@link MyInstantSerializer}
* and not by the standard Jackson-Serializer or a standard {@link de.ppi.deepsampler.persistence.model.PersistentBean}.
*/
public class MyInstantDeserializer extends JsonDeserializer<Instant> {

@Override
public Instant deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
if (!p.getValueAsString().contains(MyInstantSerializer.TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED)) {
if (!p.getValueAsString().contains(MyInstantSerializer.TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED)) {
throw new IllegalStateException("The deserialized value was not written by MyInstantSerializer, because the suffix "
+ MyInstantSerializer.TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED
+ MyInstantSerializer.TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED
+ " is missing.");
}

final String cleanedInstant = p.getValueAsString().replaceAll(MyInstantSerializer.TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED, "");
final String cleanedInstant = p.getValueAsString().replaceAll(MyInstantSerializer.TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED, "");
return Instant.from(MyInstantSerializer.ISO_LOCAL_DATE.parse(cleanedInstant));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
/**
* A simple {@link JsonSerializer} that is used to test the annotations {@link UseJsonSerializer} and {@link UseJsonDeserializer}
* <p>
* The serialzer writes an {@link Instant} in a JSON-file and adds a suffix {@link MyInstantSerializer#TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED}
* The serializer writes an {@link Instant} in a JSON-file and adds a suffix {@link MyInstantSerializer#TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED}
* to the persistent Instant. This suffix is used by {@link MyInstantDeserializer} to ensure that the {@link Instant} was saved by this {@link JsonSerializer}
* and not by the standard Jackson-Serializer or a standard {@link de.ppi.deepsampler.persistence.model.PersistentBean}.
*/
public class MyInstantSerializer extends JsonSerializer<Instant> {

public static final String TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED = "_Test";
public static final String TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED = "_Test";
public static final DateTimeFormatter ISO_LOCAL_DATE = DateTimeFormatter.ISO_LOCAL_DATE_TIME
.withLocale(Locale.GERMANY)
.withZone(ZoneId.of("UTC"));

@Override
public void serialize(final Instant value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException {
final String formattedDate = ISO_LOCAL_DATE.format(value);
gen.writeString(formattedDate + TEST_SUFFIX_TO_ENSURE_THAT_SERIALZER_WAS_USED);
gen.writeString(formattedDate + TEST_SUFFIX_TO_ENSURE_THAT_SERIALIZER_WAS_USED);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BeanExtensionTest {
public static final Path EXPECTED_SAVED_SAMPLER = Paths.get(SAVED_SAMPLER_FILE);

public static final String CATS_NAME_AS_IT_SHOULD_BE_RECORDED = "Cats name that should be recorded and written to the json file";
public static final String CATS_NAME_FOR_CROSS_CHECK = "This name is unstubbd";
public static final String CATS_NAME_FOR_CROSS_CHECK = "This name is unstubbed";


@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static de.ppi.deepsampler.junit.JUnitTestUtility.assertTestBeanHasStubbedInt;
import static de.ppi.deepsampler.junit.JUnitTestUtility.assertTestBeanHasStubbedString;
import static org.junit.Assert.assertTrue;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@UseSamplerFixture(TestSampleFixture.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BeanExtensionTest {
public static final Path EXPECTED_SAVED_SAMPLER = Paths.get(SAVED_SAMPLER_FILE);

public static final String CATS_NAME_AS_IT_SHOULD_BE_RECORDED = "Cats name that should be recorded and written to the json file";
public static final String CATS_NAME_FOR_CROSS_CHECK = "This name is unstubbd";
public static final String CATS_NAME_FOR_CROSS_CHECK = "This name is unstubbed";


@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import de.ppi.deepsampler.persistence.json.extension.PlainByteArrayDeserializer;
import de.ppi.deepsampler.persistence.json.extension.PlainByteArraySerializer;
import de.ppi.deepsampler.persistence.json.extension.DeserializationExtension;
import de.ppi.deepsampler.persistence.json.extension.SerializationExtension;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.WritableTypeId;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
Expand Down Expand Up @@ -34,11 +33,11 @@ public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serial
/**
* Adds serialization-capabilities for polymorphic types.
*
* @param value
* @param gen
* @param serializers
* @param typeSer
* @throws IOException
* @param value {@inheritDoc}
* @param gen {@inheritDoc}
* @param serializers {@inheritDoc}
* @param typeSer {@inheritDoc}
* @throws IOException {@inheritDoc}
* @see <a href=""https://stackoverflow.com/questions/26672297/how-to-trigger-calls-to-serializewithtype-of-a-class-implementing-jsonseriali">Stackoverflow</a>
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ComboMatcher<T> implements ParameterMatcher<T> {

/**
* Create a ComboMatcher with the parameterMatcher to be imitated and the persistentMatcher to hold for the later creating of a real matcher
* in the proces of loading persistent samples.
* in the process of loading persistent samples.
*
* @param parameterMatcher the {@link ParameterMatcher} to imitate
* @param persistentMatcher the {@link PersistentMatcher} to hold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
public class PolymorphicPersistentBean extends DefaultPersistentBean {
/**
* contains the true type of the object for deserialization purpose asstring
* Contains the true type of the object for deserialization purpose as string
*/
private String polymorphicBeanType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ private ReflectionTools() {

/**
* Checks if cls is an Array with a complex component type. This is the case if the component type is not a primitive type
* nor one of its wrapper types. Multidimensional arrays, thus arrays in arrays are also treated as primitve arrays if the component type
* of the deepest not array type is a primitve.
* nor one of its wrapper types. Multidimensional arrays, thus arrays in arrays are also treated as primitive arrays if the component type
* of the deepest not array type is a primitive.
*
* @param cls The class of the suspected array
* @return true if cls is an array with elements that have a Type that is not primitive nor a primitve wrapper.
* @return true if cls is an array with elements that have a Type that is not primitive nor a primitive wrapper.
*/
public static boolean isObjectArray(final Class<?> cls) {
if (!cls.isArray()) {
Expand Down Expand Up @@ -55,8 +55,8 @@ public static boolean isObjectArray(final Class<?> cls) {
/**
* Checks if cls is a primitive type or one of its wrapper types i.e. Integer for int.
*
* @param cls The suspected primitve type
* @return true it cls is a primitve or a wrapper like int and Integer.
* @param cls The suspected primitive type
* @return true it cls is a primitive or a wrapper like int and Integer.
*/
public static boolean isPrimitiveOrWrapper(final Class<?> cls) {
return cls.isPrimitive()
Expand Down Expand Up @@ -87,7 +87,7 @@ public static boolean hasPrimitiveTypeParameters(Type type) {
* (Real primitives cannot occur here, because primitives are not allowed as generic type parameters.)
*
* @param type The generic class that should be checked.
* @param numberOfParametersToCheck The number of the first generic parameters that should be chekced.
* @param numberOfParametersToCheck The number of the first generic parameters that should be checked.
* @return true if cls has generic type parameters that are wrapper types.
*/
public static boolean hasPrimitiveTypeParameters(Type type, int numberOfParametersToCheck) {
Expand Down Expand Up @@ -149,7 +149,7 @@ public static <T> Class<T> getClass(Type type) {
* Creates an empty array. The dimensions of the new array will be the same as of templateArray. The componentType of the
* new array will be newArrayType.
*
* @param templateArray A template array that is used as an example for the deimensions of the new array.
* @param templateArray A template array that is used as an example for the dimensions of the new array.
* @param newArrayType the componentType of the new array
* @param <T> the componentType of the new array
* @return the new array formed after templateArray and newArrayType.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@
* java beans. Also it will convert back this data-structures to the original objects.
* The reason for this is to omit the type information when serializing objects.
* </p>
*
* <br>
*
* <p>
* As this is a highly generic and complicated process deepsampler offers extensions
* As this is a highly generic and complicated process DeepSampler offers extensions
* for this BeanFactory the {@link BeanConverterExtension}. To add an extension you have
* to specifiy it when recording/loading samples with {@link de.ppi.deepsampler.persistence.api.PersistentSampler}
* to specify it when recording/loading samples with {@link de.ppi.deepsampler.persistence.api.PersistentSampler}
* ({@link de.ppi.deepsampler.persistence.api.PersistentSampleManager#addBeanExtension(BeanConverterExtension)}.
* </p>
* <br>
* <p>
* The extension will be used for all processed objects (including embedded objects).
* </p>
* <br>
* <p>
* When you write an extension you firstly have to define for which type you
* want to extend the behavior of the original BeanFactory. For this purpose you
Expand All @@ -56,8 +51,8 @@ public interface BeanConverterExtension {
* Checks it this extension is responsible for objects of the type beanType.
*
* @param beanClass the {@link Class} of the type that will be processed by this extension.
* @param beanType the {@link ParameterizedType} of the type that will be processed by this extension. This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @param beanType the {@link ParameterizedType} of the type that will be processed by this extension. This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @return true if the {@link Type} should be processed within this extension, false otherwise
*/

Expand All @@ -68,22 +63,22 @@ public interface BeanConverterExtension {
* persistence api. Therefore the persistence api must be able to handle the serialization / deserialization.
*
* @param beanClass the {@link Class}of the type that will be skipped by this extension.
* @param beanType the {@link ParameterizedType} that will be skipped by this extension. This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @param beanType the {@link ParameterizedType} that will be skipped by this extension. This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @return true if the Type should be skipped
*/
boolean skip(Class<?> beanClass, ParameterizedType beanType);

/**
* Conversion logic for the type you defined to process and not to skip.
* Converts an original bean to the {@link PersistentBean} which will be sent to the persistence api.
*
* <p>
* It is also possible to convert bean to any other data structure if the underlying persistence api is fully capable of
* handling the data structure on its own.
*
* @param originalBean the original bean that is supposed to be converted to a serializable data structure, most likely a {@link PersistentBean}.
* @param beanType the {@link ParameterizedType} that will be used for the conversion. This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @param originalBean the original bean that is supposed to be converted to a serializable data structure, most likely a {@link PersistentBean}.
* @param beanType the {@link ParameterizedType} that will be used for the conversion. This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @param persistentBeanConverter the current {@link PersistentBeanConverter} that may be used to convert sub objects of bean.
* @return the generic data-structure for the bean
*/
Expand All @@ -93,18 +88,18 @@ public interface BeanConverterExtension {
* Conversion logic for the generic data-structure to the processed bean type.
* Reverts to the original Bean by converting the {@link PersistentBean}, which was deserialized by the underlying
* persistence api, to the original object.
*
* <p>
* It is also possible to deserialize other types then {@link PersistentBean} if the underlying persistence api is fully
* capable of deserializing this type. I.E. {@link java.util.List}s can be deserialized by Jackson (the default JSON persistence api)
* but the elements of the list might be generic {@link PersistentBean}s. The {@link CollectionExtension} would leave it to
* Jackson to deserialize the List, but it would iterate over that List to revert the {@link PersistentBean}s inside of that list.
*
* @param persistentBean the generic bean
* @param targetClass the {@link Class} of the type that will created from the persistentBean.
* @param targetType the {@link ParameterizedType} fo the type that will be created from persistentBean, This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @param persistentBean the generic bean
* @param targetClass the {@link Class} of the type that will created from the persistentBean.
* @param targetType the {@link ParameterizedType} fo the type that will be created from persistentBean, This parameter can only be supplied
* if the type is actually a generic type. If this is not the case, beanType is null.
* @param persistentBeanConverter the current {@link PersistentBeanConverter} that may be used to revert sub objects of persistentBean.
* @param <T> type of the original bean
* @param <T> type of the original bean
* @return original bean
*/
<T> T revert(Object persistentBean, Class<T> targetClass, ParameterizedType targetType, PersistentBeanConverter persistentBeanConverter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public boolean isProcessable(Class<?> beanClass, ParameterizedType beanType) {
}

/**
* We skip the conversion of all Collections, which have primitive (or their wrapper) generic types. Primitve Collections
* We skip the conversion of all Collections, which have primitive (or their wrapper) generic types. Primitive Collections
* will then be handled by the concrete persistence api (i.e. Jackson for JSON serialisation).
*
* @param beanType the {@link Type} of the bean (Collection is expected here) that is handeld by this {@link BeanConverterExtension}
* @param beanType the {@link Type} of the bean (Collection is expected here) that is handled by this {@link BeanConverterExtension}
* @return true if beanType is a primitive {@link Collection}
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void beanInBeanShouldBeReverted() {
}

@Test
void primitiveBeanShouldBereverted() {
void primitiveBeanShouldBeReverted() {
// GIVEN
final Map<String, Object> values = new HashMap<>();
values.put("0$simpleInt", 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.ppi.deepsampler.persistence.error.PersistenceException;
import org.junit.jupiter.api.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void shouldConvertUnmodifiableSetAndReplaceItByHashSet() throws NoSuchMethodExce
// WHEN
Set<Date> result = converter.convert(unmodifiableSet, returnType);

// TEHN
// THEN
assertNotNull(result);
assertTrue(result instanceof HashSet);
assertFalse(unmodifiableSet instanceof HashSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import com.google.inject.Guice;
import de.ppi.deepsampler.provider.common.*;
import de.ppi.deepsampler.provider.testservices.DecoupledTestService;

import javax.inject.Inject;


Expand Down
Loading

0 comments on commit 622838c

Please sign in to comment.