<commit_before>package com.thoughtworks.acceptance;

import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;

/**
 * @author <NAME> 
 * @author <NAME>
 * @author <NAME>
 */
public class AttributeAliasTest extends AbstractAcceptanceTest {

    public void testSerializationOfAttributePossibleWithAliasAndConverter() {

        One one = new One();
        one.two = new Two();
        one.id  = new ID("hullo");

        xstream.attributeAlias("id", ID.class);
        xstream.registerSingleValueConverter(new MyIDConverter());
        
        assertEquals(
                "<com.thoughtworks.acceptance.AttributeAliasTest-One id=\"hullo\">\n" +
                "  <two/>\n" +
                "</com.thoughtworks.acceptance.AttributeAliasTest-One>",
                xstream.toXML(one));

    }

    public void testDeSerializationOfAttributePossibleWithAliasAndConverter() {

        xstream.attributeAlias("id", ID.class);
        xstream.registerSingleValueConverter(new MyIDConverter());
 
        One one = (One) xstream.fromXML(
                "<com.thoughtworks.acceptance.AttributeAliasTest-One id=\"hullo\">\n" +
                "  <two/>\n" +
                "</com.thoughtworks.acceptance.AttributeAliasTest-One>");

        assertEquals(one.id.value, "hullo");
        assertNotNull(one.two);

    }



    public static class One implements HasID {
        public ID id;
        public Two two;

        public void setID(ID id) {
            this.id = id;
        }
    }

    public static interface HasID {
        void setID(ID id);
    }
    
    public static class Two {}

    public static class ID {
        public ID(String value) {
            this.value = value;
        }

        public String value;
    }
<commit_msg>Added tests using know converters.<commit_after>package com.thoughtworks.acceptance;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;

/**
 * @author <NAME> 
 * @author <NAME>
 * @author <NAME>
 */
public class AttributeAliasTest extends AbstractAcceptanceTest {

    public void testSerializationOfAttributePossibleWithAliasAndKnownConverter() throws Exception {
        Three three = new Three();
        DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        three.date = format.parse("19/02/2006");
       
        xstream.attributeAlias("date", Date.class);
        assertEquals(
                "<com.thoughtworks.acceptance.AttributeAliasTest-Three date=\"2006-02-19 00:00:00.0 GMT\"/>", 
                xstream.toXML(three));
    }

    public void testDeSerializationOfAttributePossibleWithAliasAndKnownConverter() throws Exception {
        xstream.attributeAlias("date", Date.class); 
        Three three = (Three) xstream.fromXML(
                "<com.thoughtworks.acceptance.AttributeAliasTest-Three date=\"2006-02-19 00:00:00.0 GMT\"/>");

        assertEquals(three.date.toString(), "Sun Feb 19 00:00:00 GMT 2006");
    }

    public void testSerializationOfAttributePossibleWithAliasAndCustomConverter() {
        One one = new One();
        one.two = new Two();
        one.id  = new ID("hullo");

        xstream.attributeAlias("id", ID.class);
        xstream.registerSingleValueConverter(new MyIDConverter());
        
        assertEquals(
                "<com.thoughtworks.acceptance.AttributeAliasTest-One id=\"hullo\">\n" +
                "  <two/>\n" +
                "</com.thoughtworks.acceptance.AttributeAliasTest-One>",
                xstream.toXML(one));
    }

    public void testDeSerializationOfAttributePossibleWithAliasAndCustomConverter() {
        xstream.attributeAlias("id", ID.class);
        xstream.registerSingleValueConverter(new MyIDConverter());
 
        One one = (One) xstream.fromXML(
                "<com.thoughtworks.acceptance.AttributeAliasTest-One id=\"hullo\">\n" +
                "  <two/>\n" +
                "</com.thoughtworks.acceptance.AttributeAliasTest-One>");

        assertEquals(one.id.value, "hullo");
        assertNotNull(one.two);
    }

    public static class One implements HasID {
        public ID id;
        public Two two;

        public void setID(ID id) {
            this.id = id;
        }
    }

    public static interface HasID {
        void setID(ID id);
    }
    
    public static class Two {}

    public static class Three {
        public Date date;
    }
    
    public static class ID {
        public ID(String value) {
            this.value = value;
        }

        public String value;
    }

{'fraction_non_alphanumeric': 0.11265465595832429, 'fraction_numerical': 0.010853049706967658, 'mean_word_length': 2.336712527154236, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021108', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1265, 'n_words': 256}