mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-05-24 19:24:31 +00:00
Modifying SimpleStructBuilderTest and SimpleStructConverterTest to use JUnit5 instead of TestNG. Removing TestNG from build.gradle and adding JUnit5 dependency instead
This commit is contained in:
parent
b12f0654ea
commit
c75b3dea86
@ -19,7 +19,13 @@ dependencies {
|
|||||||
implementation 'org.apache.commons:commons-lang3:3.13.0'
|
implementation 'org.apache.commons:commons-lang3:3.13.0'
|
||||||
|
|
||||||
// testCompile libs.mockito
|
// 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')
|
//ext.configDir = new File(projectDir, 'config')
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package hirs.structs.converters;
|
package hirs.structs.converters;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import org.testng.annotations.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests suite for {@link SimpleStructConverter}.
|
* Tests suite for {@link SimpleStructConverter}.
|
||||||
@ -12,9 +13,9 @@ public class SimpleStructBuilderTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link SimpleStructBuilder#build()}.
|
* Tests {@link SimpleStructBuilder#build()}.
|
||||||
* @throws java.lang.NoSuchFieldException sometimes
|
* @throws NoSuchFieldException sometimes
|
||||||
* @throws java.lang.IllegalAccessException sometimes
|
* @throws IllegalAccessException sometimes
|
||||||
* @throws java.lang.IllegalArgumentException sometimes
|
* @throws IllegalArgumentException sometimes
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public final void testBuild() throws NoSuchFieldException, IllegalArgumentException,
|
public final void testBuild() throws NoSuchFieldException, IllegalArgumentException,
|
||||||
@ -31,15 +32,15 @@ public class SimpleStructBuilderTest {
|
|||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertEquals(struct.getTestShort(), NUMBER);
|
assertEquals(NUMBER, struct.getTestShort());
|
||||||
assertEquals(struct.getTestByte(), NUMBER);
|
assertEquals(NUMBER, struct.getTestByte());
|
||||||
|
|
||||||
assertEquals(struct.getTestEmbeddedStruct().getEmbeddedShort(), NUMBER);
|
assertEquals(NUMBER, struct.getTestEmbeddedStruct().getEmbeddedShort());
|
||||||
assertEquals(struct.getTestEmbeddedStruct().getEmbedded(), ARRAY);
|
assertArrayEquals(ARRAY, struct.getTestEmbeddedStruct().getEmbedded());
|
||||||
assertEquals(struct.getTestEmbeddedStruct().getEmbeddedSize(), ARRAY.length);
|
assertEquals(ARRAY.length, struct.getTestEmbeddedStruct().getEmbeddedSize());
|
||||||
|
|
||||||
assertEquals(struct.getTestVariableStruct().getTestArray(), ARRAY);
|
assertArrayEquals(ARRAY, struct.getTestVariableStruct().getTestArray());
|
||||||
assertEquals(struct.getTestVariableStructLength(), ARRAY.length);
|
assertEquals(ARRAY.length, struct.getTestVariableStructLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package hirs.structs.converters;
|
package hirs.structs.converters;
|
||||||
|
|
||||||
import org.testng.Assert;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import org.testng.annotations.Test;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests suite for {@link SimpleStructConverter}.
|
* Tests suite for {@link SimpleStructConverter}.
|
||||||
@ -24,7 +25,7 @@ public class SimpleStructConverterTest {
|
|||||||
byte[] serializedStruct = converter.convert(testStruct);
|
byte[] serializedStruct = converter.convert(testStruct);
|
||||||
|
|
||||||
// assert that the returned contents are expected
|
// assert that the returned contents are expected
|
||||||
Assert.assertEquals(serializedStruct, EXPECTED_BYTES);
|
assertArrayEquals(EXPECTED_BYTES, serializedStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,20 +45,20 @@ public class SimpleStructConverterTest {
|
|||||||
* Struct does not have the required {@link hirs.structs.elements.StructElements}
|
* Struct does not have the required {@link hirs.structs.elements.StructElements}
|
||||||
* annotation.
|
* annotation.
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = StructConversionException.class,
|
@Test
|
||||||
expectedExceptionsMessageRegExp = ".*@StructElements.*")
|
|
||||||
public final void testNoElementsStructConvertToArray() {
|
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
|
* Tests {@link SimpleStructConverter#convert(byte[], Class)} where the Struct type does not
|
||||||
* have the required {@link hirs.structs.elements.StructElements} annotation.
|
* have the required {@link hirs.structs.elements.StructElements} annotation.
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = StructConversionException.class,
|
@Test
|
||||||
expectedExceptionsMessageRegExp = ".*@StructElements.*")
|
|
||||||
public final void testNoElementsStructConvertToStruct() {
|
public final void testNoElementsStructConvertToStruct() {
|
||||||
converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);
|
assertThrows(StructConversionException.class, () ->
|
||||||
|
{converter.convert(new byte[1], TestNoElementsAnnotationStruct.class);}, ".*@StructElements.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,10 +66,10 @@ public class SimpleStructConverterTest {
|
|||||||
* Struct is {@link TestInvalidDataTypeStruct}. It is expected that a conversion exception will
|
* Struct is {@link TestInvalidDataTypeStruct}. It is expected that a conversion exception will
|
||||||
* be thrown with a message indicating that a field type is unsupported.
|
* be thrown with a message indicating that a field type is unsupported.
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = StructConversionException.class,
|
@Test
|
||||||
expectedExceptionsMessageRegExp = "Unsupported field type.*")
|
|
||||||
public final void testInvalidDataTypeStructConvertToArray() {
|
public final void testInvalidDataTypeStructConvertToArray() {
|
||||||
converter.convert(new TestInvalidDataTypeStruct());
|
assertThrows(StructConversionException.class, () ->
|
||||||
|
{converter.convert(new TestInvalidDataTypeStruct());}, "Unsupported field type.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,10 +77,11 @@ public class SimpleStructConverterTest {
|
|||||||
* TestInvalidDataTypeStruct}. It is expected that a conversion exception will be thrown with a
|
* TestInvalidDataTypeStruct}. It is expected that a conversion exception will be thrown with a
|
||||||
* message indicating that a field type is unsupported.
|
* message indicating that a field type is unsupported.
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = StructConversionException.class,
|
@Test
|
||||||
expectedExceptionsMessageRegExp = "Unsupported field type.*")
|
|
||||||
public final void testInvalidDataTypeStructConvertToStruct() {
|
public final void testInvalidDataTypeStructConvertToStruct() {
|
||||||
converter.convert(new byte[1], TestInvalidDataTypeStruct.class);
|
assertThrows(StructConversionException.class, () ->
|
||||||
|
{converter.convert(new byte[1], TestInvalidDataTypeStruct.class);}, "Unsupported field type.*");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user