Skip to content

Commit

Permalink
Merge pull request #17 from eBay/byarger/fix
Browse files Browse the repository at this point in the history
Camel case correctness for output files and checks and preventing empty string input
  • Loading branch information
yarg0007 authored Feb 28, 2023
2 parents b1e9b6a + ba1d3e0 commit eb0fdc1
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
String text = doubleTextField.getText();
if (text.isEmpty()) {
return;
}
doubleTextField.setText("");
DefaultListModel<String> model = (DefaultListModel<String>) list.getModel();
model.addElement(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
String text = integerTextField.getText();
if (text.isEmpty()) {
return;
}
integerTextField.setText("");
DefaultListModel<String> model = (DefaultListModel<String>) list.getModel();
model.addElement(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
String text = inputField.getText();
if (text.isEmpty()) {
return;
}
inputField.setText("");
DefaultListModel<String> model = (DefaultListModel<String>) list.getModel();
model.addElement(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public void export(File exportPath, List<ValidationSetModel> validationSetModels

String json = getJsonFromValidationSet(coreValidationSet, validationSetModel);

String fileName = String.format(DEVELOPER_MOCK_FILE_NAME_FORMAT, validationSetModel.getValidationSetName());
String validationSetName = validationSetModel.getValidationSetName();
validationSetName = camelCaseValidationSetName(validationSetName);

String fileName = String.format(DEVELOPER_MOCK_FILE_NAME_FORMAT, validationSetName);
File exportFile = new File(exportPath, fileName);
FileWriter fileWriter = new FileWriter(exportFile);
fileWriter.write(json);
Expand Down Expand Up @@ -90,4 +93,18 @@ protected ValidationSetModel getCoreValidationSet(List<ValidationSetModel> valid

return null;
}

/**
* Apply camel casing to the first letter of the validation set name.
* @param validationSetName Validation set name to process.
* @return Validation set name with the first letter converted to upper case.
*/
protected String camelCaseValidationSetName(String validationSetName) {
if (validationSetName.length() > 0) {
String firstCharacter = String.valueOf(validationSetName.charAt(0));
firstCharacter = firstCharacter.toUpperCase();
validationSetName = firstCharacter + validationSetName.substring(1);
}
return validationSetName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ public String getValidationStatementsForValidationSet(ValidationSetModel validat
return getValidationStatementsForNodeModels(Arrays.asList(validationSetModel.getData()));
}

/**
* Apply camel casing to the first letter of the validation set name.
* @param validationSetName Validation set name to process.
* @return Validation set name with the first letter converted to lower case.
*/
protected String lowerCaseCamelCaseValidationSetName(String validationSetName) {
if (validationSetName.length() > 0) {
String firstCharacter = String.valueOf(validationSetName.charAt(0));
firstCharacter = firstCharacter.toLowerCase();
validationSetName = firstCharacter + validationSetName.substring(1);
}
return validationSetName;
}

private String getValidationStatementsForNodeModels(List<NodeModel> nodeModels) throws IOException, ClassNotFoundException {
StringBuilder methodBuilder = new StringBuilder();
for (NodeModel nodeModel : nodeModels) {
Expand Down Expand Up @@ -196,7 +210,9 @@ private String prepareValidationStatements(List<ValidationSetModel> validationSe
StringBuilder allValidations = new StringBuilder();

for (ValidationSetModel validationSetModel : validationSetModels) {
String methodSignature = validationSetModel.getValidationSetName() + "(SoftAssert softAssert)";
String validationSetName = validationSetModel.getValidationSetName();
validationSetName = lowerCaseCamelCaseValidationSetName(validationSetName);
String methodSignature = validationSetName + "(SoftAssert softAssert)";
allValidations.append(GENERATED_VALIDATIONS_START_BLOCK);
allValidations.append("\n");
allValidations.append(prepareMethodAndStatementsWithMethod(Arrays.asList(validationSetModel.getData()), methodSignature));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,23 @@ public void getCoreValidationSet() throws IOException {
assertThat(validations.size(), is(equalTo(1)));
assertThat(validations.get(0).getValidationSetName(), is(equalTo("FOO")));
}

@DataProvider(name = "camelCaseValidationSetNameTestValues")
public Object[][] camelCaseValidationSetNameTestValues() {
return new Object[][] {
{ "", "" },
{ "first", "First" },
{ "a", "A" },
{ "AA", "AA" },
{ "aA", "AA" },
{ "andBecause", "AndBecause" },
{ "aa", "Aa" },
};
}

@Test(dataProvider = "camelCaseValidationSetNameTestValues")
public void camelCaseValidationSetName(String input, String expected) {
String actual = export.camelCaseValidationSetName(input);
assertThat(actual, is(equalTo(expected)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.util.ArrayList;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.ebay.test.util.FileParser;
Expand Down Expand Up @@ -102,4 +103,24 @@ public void multipleExportsDoesNotIncreaseWhitespace() throws Exception {
String actualFileContents = FileParser.readInFile(exportFile);
assertThat("Generated file contents must match expected.", actualFileContents, is(equalTo(expectedFileContents)));
}

@DataProvider(name = "lowerCaseCamelCaseValidationSetNameTestData")
public Object[][] lowerCaseCamelCaseValidationSetNameTestData() {
return new Object[][] {
{ "", "" },
{ "First", "first" },
{ "a", "a" },
{ "AA", "aA" },
{ "aA", "aA" },
{ "andBecause", "andBecause" },
{ "Aa", "aa" },
};
}

@Test(dataProvider = "lowerCaseCamelCaseValidationSetNameTestData")
public void lowerCaseCamelCaseValidationSetName(String input, String expected) {
ThinModelExport export = new ThinModelExport();
String actual = export.lowerCaseCamelCaseValidationSetName(input);
assertThat(actual, is(equalTo(expected)));
}
}

0 comments on commit eb0fdc1

Please sign in to comment.