In the project I work on we use XSD to generate some classes. XSD determines the order of elements, similar to this snippet:
<xs:element name="Customer_ID" type="com:Text6"/> <xs:element name="Customer_Desc" type="com:Text150"/> <xs:element name="Customer_Name" type="com:Text50"/> <xs:element name="Institution" type="com:Text150" minOccurs="0"/> <xs:element name="Scheme" type="com:Text50"/> <xs:element name="Country" type="com:Country"/>
One colleague created some tests in which he sets object fields in different order comparing to the order in XSD, for example:
obj.setCustomerName("name"); obj.setCountry("EU"); obj.setScheme("scheme"); obj.setCustomerDesc("description"); //etc.
Furthermore, he uses different order in different tests. I argued that we should stick to the same order in code as it is in XSD because that way it's easier to read or change code/XSD. He thinks it's nitpicking because, at the end, object will have its fields initialized anyway.
I'd like to hear your thoughts - is this really nitpicking from my side or not?
The fact that you are using XSD is not important. You are creating Java classes and those don't care the order (well, unless there is some dependency that should be dealt with in the constructor or a builder, rather than through setters). Keeping them in order because of the XSD can end being a maintenance nightmare, as any change on the class/schema could mean reordering every single place where you use your setters