Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from CJSCommonPlatform/constructor-parameter-o…
Browse files Browse the repository at this point in the history
…rdering

sort the order of constructor parameters alphabetically
  • Loading branch information
mapingo committed Aug 30, 2017
2 parents df4e557 + 5e1b752 commit afaef7d
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,20 @@ public void shouldAnArraySchemaDocumentWithAnArrayOfItemSchemas() throws Excepti
assertThat(newClasses.get(1).getSimpleName(), is("RecipeAdded"));

final Constructor<?> ingredientsConstructor = newClasses.get(0).getConstructor(
Integer.class,
String.class);
String.class, Integer.class);
final Constructor<?> recipeAddedConstructor = newClasses.get(1).getConstructor(
String.class,
Boolean.class,
List.class,
String.class,
String.class);

final Object ingredient_1 = ingredientsConstructor.newInstance(1, "Eye of Newt");
final Object ingredient_2 = ingredientsConstructor.newInstance(3, "Toe of Frog");
final Object ingredient_1 = ingredientsConstructor.newInstance("Eye of Newt", 1);
final Object ingredient_2 = ingredientsConstructor.newInstance("Toe of Frog", 3);

final Object regicidePie = recipeAddedConstructor.newInstance(
"Regicide Pie",
false,
asList(ingredient_1, ingredient_2),
"Regicide Pie",
"13"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public void shouldGenerateJavaClassSourceCode() throws Exception {
final Constructor<?> addressConstructor = classes.get(0).getConstructor(String.class, String.class);
final Object address = addressConstructor.newInstance(firstLine, postCode);

final Constructor<?> employeeConstructor = classes.get(1).getConstructor(String.class, String.class, BigDecimal.class, ZonedDateTime.class, List.class, address.getClass());
final Object employee = employeeConstructor.newInstance(firstName, lastName, poundsPerHour, startDate, favouriteColours, address);
final Constructor<?> employeeConstructor = classes.get(1).getConstructor(address.getClass(), List.class, String.class, String.class, BigDecimal.class, ZonedDateTime.class);
final Object employee = employeeConstructor.newInstance(address, favouriteColours, firstName, lastName, poundsPerHour, startDate);

final String employeeJson = objectMapper.writeValueAsString(employee);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ public void shouldParseAVeryComplexSchemaDocument() throws Exception {

final Object ukComms = newClasses.get(0).getConstructor(Boolean.class).newInstance(true);
final Object usComms = newClasses.get(1).getConstructor(Boolean.class).newInstance(true);
final Object communtication = newClasses.get(2).getConstructor(Boolean.class).newInstance(true);
final Object communication = newClasses.get(2).getConstructor(Boolean.class).newInstance(true);

final Constructor<?> constructor = newClasses.get(3).getConstructor(
final Constructor<?> addressConstructor = newClasses.get(3).getConstructor(
String.class,
String.class,
String.class,
communtication.getClass(),
communication.getClass(),
String.class,
usComms.getClass(),
String.class,
ukComms.getClass(),
String.class,
String.class);
String.class,
ukComms.getClass());

assertThat(constructor, is(notNullValue()));
assertThat(addressConstructor, is(notNullValue()));

final String city = "city";
final String county = "county";
Expand All @@ -114,17 +114,17 @@ public void shouldParseAVeryComplexSchemaDocument() throws Exception {
final String nullZipCode = null;
final String nullState = null;

final Object addressObject = constructor.newInstance(
city,
final Object addressObject = addressConstructor.newInstance(
addressLine1,
addressLine2,
communtication,
nullZipCode,
usComms,
city,
communication,
nullState,
ukComms,
usComms,
nullZipCode,
county,
postCode
postCode,
ukComms
);

final String json = objectMapper.writeValueAsString(addressObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public void shouldBuildTypeSpecFromSchema() throws Exception {
final Integer signedInCount = 25;
final BigDecimal ratio = BigDecimal.valueOf(2.5);

final Constructor<?> personConstructor = personClass.getConstructor(String.class, String.class, Boolean.class, Integer.class, BigDecimal.class);
final Constructor<?> personConstructor = personClass.getConstructor(String.class, String.class, BigDecimal.class, Boolean.class, Integer.class);

final Object person = personConstructor.newInstance(firstName, lastName, required, signedInCount, ratio);
final Object person = personConstructor.newInstance(firstName, lastName, ratio, required, signedInCount);

final String personJson = objectMapper.writeValueAsString(person);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public void shouldGenerateJavaClassSourceCode() throws Exception {
final Class<? extends Enum> enumClass = (Class<? extends Enum>) classes.get(0);
final Enum red = Enum.valueOf(enumClass, enumName.toUpperCase());

final Constructor<?> studentConstructor = classes.get(1).getConstructor(String.class, Integer.class, classes.get(0));
final Constructor<?> studentConstructor = classes.get(1).getConstructor(Integer.class, classes.get(0), String.class);
final String name = "Fred";
final Integer age = 21;
final Object student = studentConstructor.newInstance(name, age, red);
final Object student = studentConstructor.newInstance(age, red, name);

final String studentJson = objectMapper.writeValueAsString(student);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package uk.gov.justice.generation;

import static java.lang.String.format;

import uk.gov.justice.generation.io.files.loader.SchemaLoader;
import uk.gov.justice.generation.pojo.core.ClassNameProvider;
import uk.gov.justice.generation.pojo.core.GenerationContext;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.generation.pojo.dom;

import static java.util.Collections.unmodifiableList;
import static java.util.Comparator.comparing;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -28,10 +29,18 @@ public ClassDefinition addFieldDefinition(final Definition fieldDefinition) {
}

public List<Definition> getFieldDefinitions() {

sortDefinitionsByFieldNameFirst();

return unmodifiableList(fieldDefinitions);

}

public Optional<String> getEventName() {
return eventName;
}

private void sortDefinitionsByFieldNameFirst() {
fieldDefinitions.sort(comparing(Definition::getFieldName));
}
}
Loading

0 comments on commit afaef7d

Please sign in to comment.