package br.com.alura.argentum.testes;
import java.time.LocalDateTime;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import br.com.alura.argentum.modelo.Negociacao;
import br.com.alura.argentum.xstream.LocalDateTimeConverter;
public class LocalDateTimeConverterTest {
/**
*
*/
@Test
public void deveRetornarUmXMLComDataCorreta () {
LocalDateTime hoje = LocalDateTime.of(2016, 04, 04, 12, 00);
Negociacao negociacao = new Negociacao(10.0, 4, hoje);
XStream stream = new XStream(new DomDriver());
stream.alias("negociacao", Negociacao.class);
stream.registerLocalConverter(Negociacao.class, "data", new LocalDateTimeConverter());
String xmlConvertido = stream.toXML(negociacao);
String xmlEsperado =
"<negociacao>\r\n" +
" <preco>10.0</preco>\r\n" +
" <quantidade>4</quantidade>\r\n" +
" <data>\r\n" +
" <time>1459782000000</time>\r\n" +
" <timezone>America/Sao_Paulo</timezone>\r\n" +
" </data>\r\n" +
"<negociacao>";
Assert.assertEquals(xmlEsperado, xmlConvertido);
}
}