From 52f5f1bb700fbb75a8b078ac646347ba4840c951 Mon Sep 17 00:00:00 2001 From: TheSilentCoder <184309164+ThatSilentCoder@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:48:21 -0500 Subject: [PATCH] issue_873: fixed all checkstyle issues --- HIRS_Structs/build.gradle | 4 +-- .../config/spotbugs/spotbugs-exclude.xml | 4 +-- .../converters/SimpleStructBuilder.java | 30 +++++++++---------- .../converters/SimpleStructConverter.java | 2 +- .../structs/converters/StructConverter.java | 4 +-- .../structs/elements/StructElementLength.java | 2 +- .../hirs/structs/elements/StructElements.java | 2 +- .../elements/aca/IdentityRequestEnvelope.java | 11 +++---- .../aca/IdentityResponseEnvelope.java | 4 +-- .../elements/aca/SymmetricAttestation.java | 2 +- .../elements/tpm/AsymmetricKeyParams.java | 4 +-- .../elements/tpm/AsymmetricPublicKey.java | 2 +- .../elements/tpm/EncryptionScheme.java | 18 +++++------ .../structs/elements/tpm/IdentityProof.java | 4 +-- .../structs/elements/tpm/IdentityRequest.java | 4 +-- .../hirs/structs/elements/tpm/PublicKey.java | 2 +- .../structs/elements/tpm/RsaSubParams.java | 2 +- .../structs/elements/tpm/StorePubKey.java | 2 +- .../structs/elements/tpm/SymmetricKey.java | 2 +- .../elements/tpm/SymmetricKeyParams.java | 4 +-- .../elements/tpm/SymmetricSubParams.java | 2 +- .../hirs/structs/elements/tpm/Version.java | 2 +- .../converters/SimpleStructBuilderTest.java | 28 +++++++++-------- .../converters/SimpleStructConverterTest.java | 27 ++++++++++------- .../converters/TestEmbeddedStruct.java | 13 ++++++-- .../converters/TestInvalidDataTypeStruct.java | 2 +- .../hirs/structs/converters/TestStruct.java | 9 ++++-- .../converters/TestVariableStruct.java | 1 + 28 files changed, 104 insertions(+), 89 deletions(-) diff --git a/HIRS_Structs/build.gradle b/HIRS_Structs/build.gradle index 087653eaf..b3c6a5f97 100644 --- a/HIRS_Structs/build.gradle +++ b/HIRS_Structs/build.gradle @@ -39,10 +39,10 @@ configurations.checkstyle { } } checkstyleMain { - source ='src/main/java' + source = 'src/main/java' } checkstyleTest { - source ='src/test/java' + source = 'src/test/java' } tasks.withType(Checkstyle) { reports { diff --git a/HIRS_Structs/config/spotbugs/spotbugs-exclude.xml b/HIRS_Structs/config/spotbugs/spotbugs-exclude.xml index 52a0aba2a..f7aeab0b9 100644 --- a/HIRS_Structs/config/spotbugs/spotbugs-exclude.xml +++ b/HIRS_Structs/config/spotbugs/spotbugs-exclude.xml @@ -2,11 +2,11 @@ - + - + diff --git a/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructBuilder.java b/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructBuilder.java index 12c86657c..45a8d3175 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructBuilder.java +++ b/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructBuilder.java @@ -2,22 +2,24 @@ import hirs.structs.elements.Struct; import hirs.structs.elements.StructElementLength; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.lang3.reflect.FieldUtils; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; + /** * StructBuilder implementation. * * @param the type of Struct to build */ public class SimpleStructBuilder implements StructBuilder { - private T struct; private final Class clazz; + private T struct; /** * Instantiates the builder. + * * @param clazz The type of struct to build */ public SimpleStructBuilder(final Class clazz) { @@ -29,7 +31,7 @@ private void resetStruct() { try { struct = ConstructorUtils.invokeConstructor(clazz); } catch (InstantiationException | IllegalAccessException - | NoSuchMethodException | InvocationTargetException e) { + | NoSuchMethodException | InvocationTargetException e) { throw new StructBuilderException( String.format("Unexpected error constructing new instance: %s", clazz.getSimpleName(), e.getMessage()), e); @@ -59,17 +61,13 @@ public SimpleStructBuilder set(final String field, final String value) { public SimpleStructBuilder set(final String field, final Number value) { try { String type = clazz.getDeclaredField(field).getType().getSimpleName(); - switch (clazz.getDeclaredField(field).getType().getSimpleName()) { - case "short": - return setField(field, value.shortValue()); - case "int": - return setField(field, value.intValue()); - case "byte": - return setField(field, value.byteValue()); - default: - throw new StructBuilderException( - String.format("Unhandled numeric field type: %s", type)); - } + return switch (clazz.getDeclaredField(field).getType().getSimpleName()) { + case "short" -> setField(field, value.shortValue()); + case "int" -> setField(field, value.intValue()); + case "byte" -> setField(field, value.byteValue()); + default -> throw new StructBuilderException( + String.format("Unhandled numeric field type: %s", type)); + }; } catch (NoSuchFieldException | SecurityException e) { throw new StructBuilderException( String.format("Unexpected error setting field: %s", @@ -122,7 +120,7 @@ private SimpleStructBuilder setField(final String fieldName, final Object val FieldUtils.writeField(field, struct, value); field.setAccessible(false); } catch (NoSuchFieldException | SecurityException - | IllegalArgumentException | IllegalAccessException e) { + | IllegalArgumentException | IllegalAccessException e) { throw new StructBuilderException( String.format("Unexpected error setting field: %s", fieldName, e.getMessage()), e); diff --git a/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructConverter.java b/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructConverter.java index 35f9d0b37..28a1a4863 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructConverter.java +++ b/HIRS_Structs/src/main/java/hirs/structs/converters/SimpleStructConverter.java @@ -25,7 +25,7 @@ public final byte[] convert(final Struct struct) { // using output stream resources, serialize the specified struct try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) { + DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) { // obtain the struct elements definition StructElements structElements = struct.getClass().getAnnotation(StructElements.class); diff --git a/HIRS_Structs/src/main/java/hirs/structs/converters/StructConverter.java b/HIRS_Structs/src/main/java/hirs/structs/converters/StructConverter.java index 7c6189692..391e5df40 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/converters/StructConverter.java +++ b/HIRS_Structs/src/main/java/hirs/structs/converters/StructConverter.java @@ -20,8 +20,8 @@ public interface StructConverter { * * @param data to be parsed * @param type type of data being parsed - * @param the {@link Struct} type + * @param the {@link Struct} type * @return de-serialized struct */ - T convert(final byte[] data, final Class type); + T convert(byte[] data, Class type); } diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/StructElementLength.java b/HIRS_Structs/src/main/java/hirs/structs/elements/StructElementLength.java index 9868246eb..24f608b21 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/StructElementLength.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/StructElementLength.java @@ -14,7 +14,7 @@ public @interface StructElementLength { /** - * the field that this length represents. + * @return the field that this length represents. */ String fieldName(); } diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/StructElements.java b/HIRS_Structs/src/main/java/hirs/structs/elements/StructElements.java index 0e931f70b..25a4f57ac 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/StructElements.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/StructElements.java @@ -13,7 +13,7 @@ public @interface StructElements { /** - * elements in order to be processed by a converter. + * @return elements in order to be processed by a converter. */ String[] elements(); } diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityRequestEnvelope.java b/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityRequestEnvelope.java index 7ff11fd15..9a5dae36e 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityRequestEnvelope.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityRequestEnvelope.java @@ -10,10 +10,10 @@ * A container for an encoded {@link hirs.structs.elements.tpm.IdentityRequest}, * its associated endorsement credential, and its device information. */ -@StructElements(elements = { "requestLength", "request", - "endorsementCredentialModulusLength", "endorsementCredentialModulus", - "endorsementCredentialLength", "endorsementCredential", - "deviceInfoReportLength", "deviceInfoReport" }) +@StructElements(elements = {"requestLength", "request", + "endorsementCredentialModulusLength", "endorsementCredentialModulus", + "endorsementCredentialLength", "endorsementCredential", + "deviceInfoReportLength", "deviceInfoReport"}) public class IdentityRequestEnvelope implements Struct { @StructElementLength(fieldName = "request") @@ -72,7 +72,6 @@ public int getEndorsementCredentialLength() { } /** - * * @return the endorsementCredential */ public byte[] getEndorsementCredential() { @@ -80,7 +79,6 @@ public byte[] getEndorsementCredential() { } /** - * * @return the length of the device info report */ public int getDeviceInfoReportLength() { @@ -88,7 +86,6 @@ public int getDeviceInfoReportLength() { } /** - * * @return the device info report */ public byte[] getDeviceInfoReport() { diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityResponseEnvelope.java b/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityResponseEnvelope.java index 2602f919e..a7b3ccb17 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityResponseEnvelope.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/aca/IdentityResponseEnvelope.java @@ -9,8 +9,8 @@ /** * Data structure used by the ACA to respond back to a client's {@link IdentityRequestEnvelope}. */ -@StructElements(elements = { "asymmetricContentsSize", "asymmetricContents", - "symmetricAttestation" }) +@StructElements(elements = {"asymmetricContentsSize", "asymmetricContents", + "symmetricAttestation"}) public class IdentityResponseEnvelope implements Struct { @StructElementLength(fieldName = "asymmetricContents") diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/aca/SymmetricAttestation.java b/HIRS_Structs/src/main/java/hirs/structs/elements/aca/SymmetricAttestation.java index 9301663d0..94b808544 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/aca/SymmetricAttestation.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/aca/SymmetricAttestation.java @@ -12,7 +12,7 @@ * the envelope contains the Identity Credential that is signed by the ACA. This along with the key * parameters are typically sent to the TPM to activate an Identity. */ -@StructElements(elements = { "credentialSize", "algorithm", "credential" }) +@StructElements(elements = {"credentialSize", "algorithm", "credential"}) public class SymmetricAttestation implements Struct { @StructElementLength(fieldName = "credential") diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricKeyParams.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricKeyParams.java index 15ebae97e..b61d89c64 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricKeyParams.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricKeyParams.java @@ -8,8 +8,8 @@ * As defined in TCPA 4.20, the key parameters data structure describes the parameters used to * generate a key pair and to store the parts of a key. */ -@StructElements(elements = { "algorithmId", "encryptionScheme", "signatureScheme", "paramsSize", - "params" }) +@StructElements(elements = {"algorithmId", "encryptionScheme", "signatureScheme", "paramsSize", + "params"}) public class AsymmetricKeyParams implements Struct { private int algorithmId; diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricPublicKey.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricPublicKey.java index e5cdb56db..c2cbfb48b 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricPublicKey.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/AsymmetricPublicKey.java @@ -8,7 +8,7 @@ * portion of an asymmetric key pair. It contains all the information necessary for it's unambiguous * usage. */ -@StructElements(elements = { "asymmetricKeyParams", "storePubKey" }) +@StructElements(elements = {"asymmetricKeyParams", "storePubKey"}) public class AsymmetricPublicKey implements Struct { /** diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/EncryptionScheme.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/EncryptionScheme.java index 91ea7886b..2535b2055 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/EncryptionScheme.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/EncryptionScheme.java @@ -35,11 +35,6 @@ public enum EncryptionScheme { this.encryptionScheme = encryptionScheme; } - @Override - public String toString() { - return this.encryptionScheme; - } - /** * Maps an {@link EncryptionScheme} based upon an integer. If the scheme is unmapped, the * default, {@link #PKCS1} is returned. @@ -48,11 +43,14 @@ public String toString() { * @return the encryption scheme, or if unknown, the default. */ public static EncryptionScheme fromInt(final int scheme) { - switch (scheme) { - case OAEP_VALUE: - return OAEP; - default: - return PKCS1; + if (scheme == OAEP_VALUE) { + return OAEP; } + return PKCS1; + } + + @Override + public String toString() { + return this.encryptionScheme; } } diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityProof.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityProof.java index d86ab26a4..8e03e91f2 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityProof.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityProof.java @@ -11,9 +11,9 @@ * identity process. This structure contains information that is required by the Attestation * Certificate Authority to attest an identity request. */ -@StructElements(elements = { "version", "labelSize", "identityBindingSize", "endorsementSize", +@StructElements(elements = {"version", "labelSize", "identityBindingSize", "endorsementSize", "platformSize", "conformanceSize", "identityKey", "label", "identityBinding", - "endorsementCredential", "platformCredential", "conformanceCredential" }) + "endorsementCredential", "platformCredential", "conformanceCredential"}) public class IdentityProof implements Struct { private Version version; diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityRequest.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityRequest.java index 08159f5ea..94260475a 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityRequest.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/IdentityRequest.java @@ -10,8 +10,8 @@ * As specified in TCPA 4.30.2 specification. This structure is sent to the Attestation Certificate * Authority to create an Identity Credential. */ -@StructElements(elements = { "asymmetricBlobSize", "symmetricBlobSize", "asymmetricAlgorithm", - "symmetricAlgorithm", "asymmetricBlob", "symmetricBlob" }) +@StructElements(elements = {"asymmetricBlobSize", "symmetricBlobSize", "asymmetricAlgorithm", + "symmetricAlgorithm", "asymmetricBlob", "symmetricBlob"}) public class IdentityRequest implements Struct { @StructElementLength(fieldName = "asymmetricBlob") diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/PublicKey.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/PublicKey.java index 5bcd6bcf2..245188a44 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/PublicKey.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/PublicKey.java @@ -8,7 +8,7 @@ * portion of an asymmetric key pair. It contains all the information necessary for it's unambiguous * usage. */ -@StructElements(elements = { "asymmetricKeyParams", "storePubKey" }) +@StructElements(elements = {"asymmetricKeyParams", "storePubKey"}) public class PublicKey implements Struct { private AsymmetricKeyParams asymmetricKeyParams; diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/RsaSubParams.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/RsaSubParams.java index 95f94c4e0..9abef6878 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/RsaSubParams.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/RsaSubParams.java @@ -10,7 +10,7 @@ * Parameters that are used to describe a particular {@link AsymmetricKeyParams} as specified by the * TCPA 4.20. */ -@StructElements(elements = { "keyLength", "totalPrimes", "exponentSize", "exponent" }) +@StructElements(elements = {"keyLength", "totalPrimes", "exponentSize", "exponent"}) public class RsaSubParams implements Struct { private int keyLength; diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/StorePubKey.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/StorePubKey.java index 872ac3e70..cc70106d1 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/StorePubKey.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/StorePubKey.java @@ -10,7 +10,7 @@ * As specified in TCPA Main Specification section 4.27.2. This structure represents a public key of * an asymmetric key pair. */ -@StructElements(elements = { "keyLength", "key" }) +@StructElements(elements = {"keyLength", "key"}) public class StorePubKey implements Struct { @StructElementLength(fieldName = "key") diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKey.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKey.java index ef9d1832c..3c2fb30b1 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKey.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKey.java @@ -10,7 +10,7 @@ * Part of the TPM Identity Request. This Structure is encrypted inside the request and is typically * unencrypted by an Attestation Certificate Authority. */ -@StructElements(elements = { "algorithmId", "encryptionScheme", "keySize", "key" }) +@StructElements(elements = {"algorithmId", "encryptionScheme", "keySize", "key"}) public class SymmetricKey implements Struct { /** diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKeyParams.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKeyParams.java index eb959624e..7b03b9fb2 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKeyParams.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricKeyParams.java @@ -7,8 +7,8 @@ /** * Represents a symmetric key as specified in section 4.20 of the TCPA. */ -@StructElements(elements = { "algorithmId", "encryptionScheme", "signatureScheme", "paramsSize", - "params" }) +@StructElements(elements = {"algorithmId", "encryptionScheme", "signatureScheme", "paramsSize", + "params"}) public class SymmetricKeyParams implements Struct { /** diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricSubParams.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricSubParams.java index fd3e80a16..fde376328 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricSubParams.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/SymmetricSubParams.java @@ -10,7 +10,7 @@ * Represents a dynamic key parameters data structure that is enclosed inside a {@link * SymmetricKeyParams}. */ -@StructElements(elements = { "keyLength", "blockSize", "ivSize", "iv" }) +@StructElements(elements = {"keyLength", "blockSize", "ivSize", "iv"}) public class SymmetricSubParams implements Struct { private int keyLength; diff --git a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/Version.java b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/Version.java index d9e724cf2..3204b8d6e 100644 --- a/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/Version.java +++ b/HIRS_Structs/src/main/java/hirs/structs/elements/tpm/Version.java @@ -7,7 +7,7 @@ * As specified in the TCPA Main Specification section 4.5. This structure represents the version of * the TPM. */ -@StructElements(elements = { "major", "minor", "revisionMajor", "revisionMinor" }) +@StructElements(elements = {"major", "minor", "revisionMajor", "revisionMinor"}) public class Version implements Struct { private byte major; diff --git a/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructBuilderTest.java b/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructBuilderTest.java index e788cc649..f712f7609 100644 --- a/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructBuilderTest.java +++ b/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructBuilderTest.java @@ -1,8 +1,9 @@ package hirs.structs.converters; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; /** * Tests suite for {@link SimpleStructConverter}. @@ -13,24 +14,25 @@ public class SimpleStructBuilderTest { /** * Tests {@link SimpleStructBuilder#build()}. - * @throws NoSuchFieldException sometimes - * @throws IllegalAccessException sometimes + * + * @throws NoSuchFieldException sometimes + * @throws IllegalAccessException sometimes * @throws IllegalArgumentException sometimes */ @Test public final void testBuild() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { TestStruct struct = new SimpleStructBuilder<>(TestStruct.class) - .set("testShort", NUMBER) - .set("testByte", NUMBER) - .set("testEmbeddedStruct", new SimpleStructBuilder<>(TestEmbeddedStruct.class) - .set("embeddedShort", NUMBER) - .set("embedded", ARRAY) - .build()) - .set("testVariableStruct", new SimpleStructBuilder<>(TestVariableStruct.class) - .set("testArray", ARRAY) - .build()) - .build(); + .set("testShort", NUMBER) + .set("testByte", NUMBER) + .set("testEmbeddedStruct", new SimpleStructBuilder<>(TestEmbeddedStruct.class) + .set("embeddedShort", NUMBER) + .set("embedded", ARRAY) + .build()) + .set("testVariableStruct", new SimpleStructBuilder<>(TestVariableStruct.class) + .set("testArray", ARRAY) + .build()) + .build(); assertEquals(NUMBER, struct.getTestShort()); assertEquals(NUMBER, struct.getTestByte()); diff --git a/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructConverterTest.java b/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructConverterTest.java index 915dcf395..0aa37fe20 100644 --- a/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructConverterTest.java +++ b/HIRS_Structs/src/test/java/hirs/structs/converters/SimpleStructConverterTest.java @@ -1,8 +1,9 @@ package hirs.structs.converters; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; /** * Tests suite for {@link SimpleStructConverter}. @@ -10,11 +11,11 @@ public class SimpleStructConverterTest { private static final byte[] EXPECTED_BYTES = - new byte[]{0, 5, 0, 0, 0, 10, 0, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 6, 0, 0, 0, 0}; + new byte[] {0, 5, 0, 0, 0, 10, 0, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 6, 0, 0, 0, 0}; private final TestStruct testStruct = new TestStruct(); - private StructConverter converter = new SimpleStructConverter(); + private final StructConverter converter = new SimpleStructConverter(); /** * Tests {@link SimpleStructConverter#convert(hirs.structs.elements.Struct)}. @@ -47,8 +48,9 @@ public final void testConvertToStruct() { */ @Test public final void testNoElementsStructConvertToArray() { - assertThrows(StructConversionException.class, () -> - {converter.convert(new TestNoElementsAnnotationStruct());}, ".*@StructElements.*"); + assertThrows(StructConversionException.class, () -> { + converter.convert(new TestNoElementsAnnotationStruct()); + }, ".*@StructElements.*"); } /** @@ -57,8 +59,9 @@ public final void testNoElementsStructConvertToArray() { */ @Test public final void testNoElementsStructConvertToStruct() { - assertThrows(StructConversionException.class, () -> - {converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);}, ".*@StructElements.*"); + assertThrows(StructConversionException.class, () -> { + converter.convert(new byte[1], TestNoElementsAnnotationStruct.class); + }, ".*@StructElements.*"); } /** @@ -68,8 +71,9 @@ public final void testNoElementsStructConvertToStruct() { */ @Test public final void testInvalidDataTypeStructConvertToArray() { - assertThrows(StructConversionException.class, () -> - {converter.convert(new TestInvalidDataTypeStruct());}, "Unsupported field type.*"); + assertThrows(StructConversionException.class, () -> { + converter.convert(new TestInvalidDataTypeStruct()); + }, "Unsupported field type.*"); } /** @@ -79,8 +83,9 @@ public final void testInvalidDataTypeStructConvertToArray() { */ @Test public final void testInvalidDataTypeStructConvertToStruct() { - assertThrows(StructConversionException.class, () -> - {converter.convert(new byte[1], TestInvalidDataTypeStruct.class);}, "Unsupported field type.*"); + assertThrows(StructConversionException.class, () -> { + converter.convert(new byte[1], TestInvalidDataTypeStruct.class); + }, "Unsupported field type.*"); } diff --git a/HIRS_Structs/src/test/java/hirs/structs/converters/TestEmbeddedStruct.java b/HIRS_Structs/src/test/java/hirs/structs/converters/TestEmbeddedStruct.java index b8639322a..44686f2dd 100644 --- a/HIRS_Structs/src/test/java/hirs/structs/converters/TestEmbeddedStruct.java +++ b/HIRS_Structs/src/test/java/hirs/structs/converters/TestEmbeddedStruct.java @@ -9,7 +9,7 @@ /** * A struct to be embedded within TestStruct. */ -@StructElements(elements = { "embeddedSize", "embeddedShort", "embedded" }) +@StructElements(elements = {"embeddedSize", "embeddedShort", "embedded"}) public class TestEmbeddedStruct implements Struct { private static final int EMBEDDED_SIZE = 10; @@ -18,7 +18,7 @@ public class TestEmbeddedStruct implements Struct { private static final int HASH_CODE = 31; - private static final byte[] DEFAULT_ARRAY = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + private static final byte[] DEFAULT_ARRAY = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; @StructElementLength(fieldName = "embedded") @@ -28,6 +28,12 @@ public class TestEmbeddedStruct implements Struct { private byte[] embedded = DEFAULT_ARRAY; + /** + * Returns true if the provided object is equivalent to this class. + * + * @param o object to compare + * @return true if the provided object is equal to this class + */ @Override public boolean equals(final Object o) { if (this == o) { @@ -53,6 +59,7 @@ public final int hashCode() { /** * Getter. + * * @return value */ public byte[] getEmbedded() { @@ -61,6 +68,7 @@ public byte[] getEmbedded() { /** * Getter. + * * @return value */ public short getEmbeddedShort() { @@ -69,6 +77,7 @@ public short getEmbeddedShort() { /** * Getter. + * * @return value */ public int getEmbeddedSize() { diff --git a/HIRS_Structs/src/test/java/hirs/structs/converters/TestInvalidDataTypeStruct.java b/HIRS_Structs/src/test/java/hirs/structs/converters/TestInvalidDataTypeStruct.java index 772c7ad9c..e89375228 100644 --- a/HIRS_Structs/src/test/java/hirs/structs/converters/TestInvalidDataTypeStruct.java +++ b/HIRS_Structs/src/test/java/hirs/structs/converters/TestInvalidDataTypeStruct.java @@ -6,7 +6,7 @@ /** * Test Struct that has an unsupported data type. */ -@StructElements(elements = { "testLong" }) +@StructElements(elements = {"testLong"}) public class TestInvalidDataTypeStruct implements Struct { private static final Long TEST_LONG_VALUE = 1L; diff --git a/HIRS_Structs/src/test/java/hirs/structs/converters/TestStruct.java b/HIRS_Structs/src/test/java/hirs/structs/converters/TestStruct.java index 47a902371..0e6428d5e 100644 --- a/HIRS_Structs/src/test/java/hirs/structs/converters/TestStruct.java +++ b/HIRS_Structs/src/test/java/hirs/structs/converters/TestStruct.java @@ -8,8 +8,8 @@ * A Struct class designed to fully test the design of the converter being tested. */ @StructElements( - elements = { "testShort", "testEmbeddedStruct", "testByte", "testVariableStructLength", - "testVariableStruct" }) + elements = {"testShort", "testEmbeddedStruct", "testByte", "testVariableStructLength", + "testVariableStruct"}) public class TestStruct implements Struct { private static final short TEST_SHORT = 0x5; @@ -54,6 +54,7 @@ public final int hashCode() { /** * Getter. + * * @return value */ public byte getTestByte() { @@ -62,6 +63,7 @@ public byte getTestByte() { /** * Getter. + * * @return value */ public short getTestShort() { @@ -70,6 +72,7 @@ public short getTestShort() { /** * Getter. + * * @return value */ public TestEmbeddedStruct getTestEmbeddedStruct() { @@ -78,6 +81,7 @@ public TestEmbeddedStruct getTestEmbeddedStruct() { /** * Getter. + * * @return value */ public TestVariableStruct getTestVariableStruct() { @@ -86,6 +90,7 @@ public TestVariableStruct getTestVariableStruct() { /** * Getter. + * * @return value */ public int getTestVariableStructLength() { diff --git a/HIRS_Structs/src/test/java/hirs/structs/converters/TestVariableStruct.java b/HIRS_Structs/src/test/java/hirs/structs/converters/TestVariableStruct.java index 05073a020..fccbb4aee 100644 --- a/HIRS_Structs/src/test/java/hirs/structs/converters/TestVariableStruct.java +++ b/HIRS_Structs/src/test/java/hirs/structs/converters/TestVariableStruct.java @@ -14,6 +14,7 @@ public class TestVariableStruct implements Struct { /** * Getter. + * * @return value */ public byte[] getTestArray() {