Skip to content

Commit

Permalink
Merge new test of encoding into existing one
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Dirkse committed Sep 23, 2024
1 parent b61bec2 commit 3fdc141
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/test/java/nl/nn/testtool/MessageEncoderTest.java

This file was deleted.

38 changes: 38 additions & 0 deletions src/test/java/nl/nn/testtool/test/junit/TestMessageEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.parsers.ParserConfigurationException;

import nl.nn.testtool.MessageEncoder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.rules.TestName;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
Expand All @@ -46,6 +50,40 @@ public class TestMessageEncoder {
@Rule
public TestName name = new TestName();

@Test
public void encode_and_decode_boolean_true() {
MessageEncoder instance = new MessageEncoderImpl();
MessageEncoder.ToStringResult encoded = instance.toString(true, null);
Assertions.assertEquals("true", encoded.getString());
Assertions.assertEquals("java.lang.Boolean", encoded.getMessageClassName());
Checkpoint checkpoint = new Checkpoint();
checkpoint.setMessage(encoded.getString());
checkpoint.setEncoding(encoded.getEncoding());
checkpoint.setMessageClassName(encoded.getMessageClassName());
Object back = instance.toObject(checkpoint);
if(! (back instanceof Boolean)) {
fail("Expected to get back Boolean");
}
Assertions.assertTrue((Boolean) back);
}

@Test
public void encode_decode_boolean_false() {
MessageEncoder instance = new MessageEncoderImpl();
MessageEncoder.ToStringResult encoded = instance.toString(false, null);
Assertions.assertEquals("false", encoded.getString());
Assertions.assertEquals("java.lang.Boolean", encoded.getMessageClassName());
Checkpoint checkpoint = new Checkpoint();
checkpoint.setMessage(encoded.getString());
checkpoint.setEncoding(encoded.getEncoding());
checkpoint.setMessageClassName(encoded.getMessageClassName());
Object back = instance.toObject(checkpoint);
if(! (back instanceof Boolean)) {
fail("Expected to get back Boolean");
}
assertFalse((Boolean) back);
}

@Test
public void testToString() throws SAXException, IOException, ParserConfigurationException, StorageException {
TestTool testTool = new TestTool();
Expand Down

0 comments on commit 3fdc141

Please sign in to comment.