Skip to content

Commit

Permalink
Modifying SimpleStructBuilderTest and SimpleStructConverterTest to us…
Browse files Browse the repository at this point in the history
…e JUnit5 instead of TestNG. Removing TestNG from build.gradle and adding JUnit5 dependency instead
  • Loading branch information
iadgovuser62 committed Jan 24, 2024
1 parent b12f065 commit c75b3de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
8 changes: 7 additions & 1 deletion HIRS_Structs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.13.0'

// testCompile libs.mockito
testImplementation libs.testng
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.3'
testImplementation 'org.hamcrest:hamcrest:2.2'
}

test {
useJUnitPlatform()
}

//ext.configDir = new File(projectDir, 'config')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package hirs.structs.converters;

import static org.testng.Assert.assertEquals;
import org.testng.annotations.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}.
Expand All @@ -12,9 +13,9 @@ public class SimpleStructBuilderTest {

/**
* Tests {@link SimpleStructBuilder#build()}.
* @throws java.lang.NoSuchFieldException sometimes
* @throws java.lang.IllegalAccessException sometimes
* @throws java.lang.IllegalArgumentException sometimes
* @throws NoSuchFieldException sometimes
* @throws IllegalAccessException sometimes
* @throws IllegalArgumentException sometimes
*/
@Test
public final void testBuild() throws NoSuchFieldException, IllegalArgumentException,
Expand All @@ -31,15 +32,15 @@ public final void testBuild() throws NoSuchFieldException, IllegalArgumentExcept
.build())
.build();

assertEquals(struct.getTestShort(), NUMBER);
assertEquals(struct.getTestByte(), NUMBER);
assertEquals(NUMBER, struct.getTestShort());
assertEquals(NUMBER, struct.getTestByte());

assertEquals(struct.getTestEmbeddedStruct().getEmbeddedShort(), NUMBER);
assertEquals(struct.getTestEmbeddedStruct().getEmbedded(), ARRAY);
assertEquals(struct.getTestEmbeddedStruct().getEmbeddedSize(), ARRAY.length);
assertEquals(NUMBER, struct.getTestEmbeddedStruct().getEmbeddedShort());
assertArrayEquals(ARRAY, struct.getTestEmbeddedStruct().getEmbedded());
assertEquals(ARRAY.length, struct.getTestEmbeddedStruct().getEmbeddedSize());

assertEquals(struct.getTestVariableStruct().getTestArray(), ARRAY);
assertEquals(struct.getTestVariableStructLength(), ARRAY.length);
assertArrayEquals(ARRAY, struct.getTestVariableStruct().getTestArray());
assertEquals(ARRAY.length, struct.getTestVariableStructLength());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package hirs.structs.converters;

import org.testng.Assert;
import org.testng.annotations.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}.
Expand All @@ -24,7 +25,7 @@ public final void testConvertToByteArray() {
byte[] serializedStruct = converter.convert(testStruct);

// assert that the returned contents are expected
Assert.assertEquals(serializedStruct, EXPECTED_BYTES);
assertArrayEquals(EXPECTED_BYTES, serializedStruct);
}

/**
Expand All @@ -44,42 +45,43 @@ public final void testConvertToStruct() {
* Struct does not have the required {@link hirs.structs.elements.StructElements}
* annotation.
*/
@Test(expectedExceptions = StructConversionException.class,
expectedExceptionsMessageRegExp = ".*@StructElements.*")
@Test
public final void testNoElementsStructConvertToArray() {
converter.convert(new TestNoElementsAnnotationStruct());
assertThrows(StructConversionException.class, () ->
{converter.convert(new TestNoElementsAnnotationStruct());}, ".*@StructElements.*");
}

/**
* Tests {@link SimpleStructConverter#convert(byte[], Class)} where the Struct type does not
* have the required {@link hirs.structs.elements.StructElements} annotation.
*/
@Test(expectedExceptions = StructConversionException.class,
expectedExceptionsMessageRegExp = ".*@StructElements.*")
@Test
public final void testNoElementsStructConvertToStruct() {
converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);
assertThrows(StructConversionException.class, () ->
{converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);}, ".*@StructElements.*");
}

/**
* Tests {@link SimpleStructConverter#convert(hirs.structs.elements.Struct)} where the
* Struct is {@link TestInvalidDataTypeStruct}. It is expected that a conversion exception will
* be thrown with a message indicating that a field type is unsupported.
*/
@Test(expectedExceptions = StructConversionException.class,
expectedExceptionsMessageRegExp = "Unsupported field type.*")
@Test
public final void testInvalidDataTypeStructConvertToArray() {
converter.convert(new TestInvalidDataTypeStruct());
assertThrows(StructConversionException.class, () ->
{converter.convert(new TestInvalidDataTypeStruct());}, "Unsupported field type.*");
}

/**
* Tests {@link SimpleStructConverter#convert(byte[], Class)} where the Struct is {@link
* TestInvalidDataTypeStruct}. It is expected that a conversion exception will be thrown with a
* message indicating that a field type is unsupported.
*/
@Test(expectedExceptions = StructConversionException.class,
expectedExceptionsMessageRegExp = "Unsupported field type.*")
@Test
public final void testInvalidDataTypeStructConvertToStruct() {
converter.convert(new byte[1], TestInvalidDataTypeStruct.class);
assertThrows(StructConversionException.class, () ->
{converter.convert(new byte[1], TestInvalidDataTypeStruct.class);}, "Unsupported field type.*");

}

}

0 comments on commit c75b3de

Please sign in to comment.