Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Falha no teste

@Override
    public Object unmarshal(HierarchicalStreamReader reader,
            UnmarshallingContext context) {

        reader.moveDown();
        String nomeId = reader.getNodeName();
        String valorId = reader.getAttribute("id");
        reader.moveUp();

        reader.moveDown();
        String nomeFornecedor = reader.getNodeName();
        String valorFornecedor = reader.getAttribute("fornecedor");
        reader.moveUp();

        reader.moveDown();
        String nomeEndereco = reader.getNodeName();
        reader.moveDown();
        String nomeLinhaUm = reader.getNodeName();
        String valorLinhaUm = reader.getAttribute("linha1");
        reader.moveUp();
        reader.moveDown();
        String nomeLinhaDois = reader.getNodeName();
        String valorLinhaDois = reader.getAttribute("linha2");
        reader.moveUp();
        reader.moveUp();

        List<Produto>produtos = new ArrayList<>();
        int id = Integer.parseInt(valorId);
        Compra compra = new Compra(id, produtos);

        reader.moveDown();
        List<Produto> produtosLidos = (List<Produto>) context.convertAnother(compra, List.class);
        produtos.addAll(produtosLidos);
        reader.moveUp();

        return compra;
    }
com.thoughtworks.xstream.converters.ConversionException: null : null
---- Debugging information ----
message             : null
cause-exception     : java.lang.NumberFormatException
cause-message       : null
class               : br.com.caelum.xstream.Compra
required-type       : br.com.caelum.xstream.Compra
converter-type      : br.com.caelum.xstream.CompraDiferenteConverter
line number         : 7
version             : 1.4.7
-------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1185)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1169)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1040)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1031)
    at br.com.caelum.xstream.CompraTest.deveUsarUmConversorDiferente(CompraTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at br.com.caelum.xstream.CompraDiferenteConverter.unmarshal(CompraDiferenteConverter.java:78)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    ... 32 more
1 resposta
solução!

Já achei os erros, confundi os métodos.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software