[DEV] add simple record test

This commit is contained in:
Edouard DUPIN 2021-07-08 14:19:28 +02:00
parent 99b846be25
commit 70dae9d861

View File

@ -0,0 +1,45 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.atriasoft.exml.Exml;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ExmlTestIntrospectionRecord {
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
Log.warning("================================================================");
}
public record TestRecord(
Integer valueA,
double valueB) {
public TestRecord(final Integer valueA, final double valueB) {
this.valueA = valueA;
this.valueB = valueB;
}
}
@Test
public void testModelRecord() {
TestRecord elem = new TestRecord(66, 18523.0);
StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionObject.NODE_NAME, builder));
String dataTest = builder.toString();
Log.warning("data generated: " + builder.toString());
Assertions.assertEquals("<elem valueA=\"66\">\n"
+ " <valueB>18523.0</valueB>\n"
+ "</elem>", dataTest);
final TestRecord root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestRecord.class, ExmlTestIntrospectionObject.NODE_NAME));
Assertions.assertEquals(66, root.valueA);
Assertions.assertEquals(18523.0f, root.valueB);
}
}