Skip to content

Commit

Permalink
Refactor Test-classes (#69)
Browse files Browse the repository at this point in the history
* Refactor 'exampleRecord'-tests

* Refactor 'DepreatedExampleRecord'-tests

* Refactor 'exampleRecordWithArrayFields'-tests

* Refactor 'exampleRecordWithBooleanFields'-tests

* Refactor 'exampleRecordWithNumberFields'-tests

* Refactor 'exampleRecordWithStringFields'-tests

* Refactor 'exampleRecordWithIntegerFields'-tests

* Refactor 'exampleEnum'-tests

* Refactor 'deprecatedExampleEnum'-tests

* Refactor 'exmapleRecordWithExampleEnumFields'-tests

* Refactor 'exampleRecordWithExampleRecordFields'-tests

* Refactor all model-tests to `TestSuite.java`

* Refactor 'exampleRecordWithDefaultFields'-tests

* Add Constructor & field assertion-methods

* Refactor 'Record has fields'-tests

* Refactor 'Record field'-tests

* Refactor 'Class has Method'-tests

* Refactor 'Record has/does not have Method'-tests
  • Loading branch information
Chrimle authored Sep 18, 2024
1 parent 97fd03f commit 370c50b
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 698 deletions.
89 changes: 89 additions & 0 deletions src/test/java/com/chrimle/example/TestSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.chrimle.example;

import com.chrimle.example.utils.GeneratedEnumTestUtils;
import com.chrimle.example.utils.GeneratedRecordTestUtils;

public record TestSuite<DeprecatedExampleEnum extends Enum<DeprecatedExampleEnum>, ExampleEnum extends Enum<ExampleEnum>>(
Class<DeprecatedExampleEnum> deprecatedExampleEnum,
Class<?> deprecatedExampleRecord,
Class<ExampleEnum> exampleEnum,
Class<?> exampleRecord,
Class<?> exampleRecordWithArrayFields,
Class<?> exampleRecordWithBooleanFields,
Class<?> exampleRecordWithDefaultFields,
Class<?> exampleRecordWithExampleEnumFields,
Class<?> exampleRecordWithExampleRecordFields,
Class<?> exampleRecordWithIntegerFields,
Class<?> exampleRecordWithNumberFields,
Class<?> exampleRecordWithStringFields,
boolean hasAdditionalModelTypeAnnotations,
boolean hasAdditionalEnumTypeAnnotations,
boolean useEnumCaseInsensitive,
boolean serializableModel
) {

public void assertModels() {
GeneratedEnumTestUtils.assertExampleEnum(
exampleEnum,
hasAdditionalEnumTypeAnnotations,
useEnumCaseInsensitive
);
GeneratedEnumTestUtils.assertDeprecatedExampleEnum(
deprecatedExampleEnum,
hasAdditionalEnumTypeAnnotations,
useEnumCaseInsensitive
);
GeneratedRecordTestUtils.assertExampleRecord(
exampleRecord,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertDeprecatedExampleRecord(
deprecatedExampleRecord,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithBooleanFields(
exampleRecordWithBooleanFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithExampleEnumFields(
exampleRecordWithExampleEnumFields,
exampleEnum,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithExampleRecordFields(
exampleRecordWithExampleRecordFields,
exampleRecord,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithIntegerFields(
exampleRecordWithIntegerFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithNumberFields(
exampleRecordWithNumberFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithStringFields(
exampleRecordWithStringFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithArrayFields(
exampleRecordWithArrayFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithDefaultFields(
exampleRecordWithDefaultFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.chrimle.example.additionalEnumTypeAnnotations;

import com.chrimle.example.utils.GeneratedEnumTestUtils;
import com.chrimle.example.utils.GeneratedRecordTestUtils;
import java.math.BigDecimal;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import com.chrimle.example.TestSuite;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -14,147 +9,31 @@
@SuppressWarnings("deprecation")
public class AdditionalEnumTypeAnnotationTests {

final Class<DeprecatedExampleEnum> deprecatedExampleEnum = DeprecatedExampleEnum.class;
final Class<DeprecatedExampleRecord> deprecatedExampleRecord = DeprecatedExampleRecord.class;
final Class<ExampleEnum> exampleEnum = ExampleEnum.class;
final Class<ExampleRecord> exampleRecord = ExampleRecord.class;
final Class<ExampleRecordWithArrayFields> exampleRecordWithArrayFields = ExampleRecordWithArrayFields.class;
final Class<ExampleRecordWithBooleanFields> exampleRecordWithBooleanFields = ExampleRecordWithBooleanFields.class;
final Class<ExampleRecordWithDefaultFields> exampleRecordWithDefaultFields = ExampleRecordWithDefaultFields.class;
final Class<ExampleRecordWithExampleEnumFields> exampleRecordWithExampleEnumFields = ExampleRecordWithExampleEnumFields.class;
final Class<ExampleRecordWithExampleRecordFields> exampleRecordWithExampleRecordFields = ExampleRecordWithExampleRecordFields.class;
final Class<ExampleRecordWithIntegerFields> exampleRecordWithIntegerFields = ExampleRecordWithIntegerFields.class;
final Class<ExampleRecordWithNumberFields> exampleRecordWithNumberFields = ExampleRecordWithNumberFields.class;
final Class<ExampleRecordWithStringFields> exampleRecordWithStringFields = ExampleRecordWithStringFields.class;

final boolean HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS = false;
final boolean HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS = true;
final boolean USE_ENUM_CASE_INSENSITIVE = false;
final boolean IS_MODEL_SERIALIZABLE = false;

@Test
public void testAllGeneratedClasses() {
GeneratedEnumTestUtils.assertEnumClass(
exampleEnum,
false,
HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS,
USE_ENUM_CASE_INSENSITIVE
);
GeneratedEnumTestUtils.assertEnumClass(
deprecatedExampleEnum,
true,
HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS,
USE_ENUM_CASE_INSENSITIVE
);
GeneratedRecordTestUtils.assertRecord(
exampleRecord,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
Boolean.class
);
GeneratedRecordTestUtils.assertRecord(
deprecatedExampleRecord,
true,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
Boolean.class
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithBooleanFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
Boolean.class,
Boolean.class,
Boolean.class
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithExampleEnumFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
exampleEnum,
exampleEnum,
exampleEnum
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithExampleRecordFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
exampleRecord,
exampleRecord,
exampleRecord
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithIntegerFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
Integer.class,
Integer.class,
Integer.class
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithNumberFields,
false,
final TestSuite testSuite = new TestSuite(
DeprecatedExampleEnum.class,
DeprecatedExampleRecord.class,
ExampleEnum.class,
ExampleRecord.class,
ExampleRecordWithArrayFields.class,
ExampleRecordWithBooleanFields.class,
ExampleRecordWithDefaultFields.class,
ExampleRecordWithExampleEnumFields.class,
ExampleRecordWithExampleRecordFields.class,
ExampleRecordWithIntegerFields.class,
ExampleRecordWithNumberFields.class,
ExampleRecordWithStringFields.class,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
BigDecimal.class,
BigDecimal.class,
BigDecimal.class
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithStringFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
String.class,
String.class,
String.class
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithArrayFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
List.class,
List.class,
List.class
);
GeneratedRecordTestUtils.assertRecord(
exampleRecordWithDefaultFields,
false,
HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
IS_MODEL_SERIALIZABLE,
String.class,
String.class
HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS,
USE_ENUM_CASE_INSENSITIVE,
IS_MODEL_SERIALIZABLE
);
testSuite.assertModels();
}

@Test
@DisplayName("Testing nullable field is null after instantiation")
public void testNullableFieldIsNullAfterInstantiation() {
ExampleRecordWithDefaultFields record = new ExampleRecordWithDefaultFields(
null, "ignore");
Assertions.assertNull(record.field1());
}

@Test
@DisplayName("Testing field with default value is set to default if null is provided")
public void testFieldWithDefaultValueIsSetToDefaultIfProvidedValueIsNull() {
ExampleRecordWithDefaultFields record = new ExampleRecordWithDefaultFields(
"ignore", null);
Assertions.assertEquals("someDefaultValue", record.field2());
}

@Test
@DisplayName("Testing field with default value is set to provided value if not null")
public void testFieldWithDefaultValueIsSetToProvidedValueIfProvidedValueIsNotNull() {
ExampleRecordWithDefaultFields record = new ExampleRecordWithDefaultFields(
"ignore", "someValue");
Assertions.assertEquals("someValue", record.field2());
}

}
Loading

0 comments on commit 370c50b

Please sign in to comment.