Skip to content

Commit

Permalink
Merge pull request #10 from AlexandrouR/minorFixes
Browse files Browse the repository at this point in the history
Class name will always start with a capital letter
  • Loading branch information
antonydenyer authored Oct 14, 2019
2 parents 81c8a42 + 89b91fc commit 1c8cfc5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/web3j/console/project/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.web3j.console.project.utills.InputVerifier;

import static org.web3j.codegen.Console.exitError;

public class Project {
Expand Down Expand Up @@ -89,7 +91,8 @@ public Project build() {
final ProjectWriter projectWriter = new ProjectWriter();
projectWriter.writeResourceFile(
templateProvider.getMainJavaClass(),
projectStructure.getProjectName() + ".java",
InputVerifier.capitalizeFirstLetter(
projectStructure.getProjectName() + ".java"),
projectStructure.getMainPath());
projectWriter.writeResourceFile(
templateProvider.getGradleBuild(),
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/web3j/console/project/ProjectCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import picocli.CommandLine;

import org.web3j.console.project.utills.InputVerifier;

import static org.web3j.codegen.Console.exitError;
import static org.web3j.codegen.Console.exitSuccess;
import static org.web3j.utils.Collection.tail;
Expand All @@ -44,7 +46,11 @@ public class ProjectCreator {
.loadGradleJar("gradle-wrapper.jar")
.loadSolidityGreeter("Greeter.sol")
.withPackageNameReplacement(s -> s.replace("<package_name>", packageName))
.withProjectNameReplacement(s -> s.replace("<project_name>", projectName))
.withProjectNameReplacement(
s ->
s.replace(
"<project_name>",
InputVerifier.capitalizeFirstLetter(projectName)))
.build();
}

Expand Down Expand Up @@ -82,7 +88,6 @@ void generate() {
+ projectStructure.getProjectName()
+ " at location: "
+ projectStructure.getProjectRoot());

} catch (final Exception e) {
exitError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ public static boolean packageNameIsValid(final String packageName) {
}
return true;
}

public static String capitalizeFirstLetter(String input) {

if (Character.isUpperCase(input.charAt(0))) {
return input;
}
return input.substring(0, 1).toUpperCase() + input.substring(1);
}
}
10 changes: 8 additions & 2 deletions src/test/java/org/web3j/console/project/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import org.web3j.console.project.utills.InputVerifier;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class ProjectTest {
Expand All @@ -39,7 +41,11 @@ public void setUpProject(@TempDir Path tempDirPath) throws Exception {
.loadGradleJar("gradle-wrapper.jar")
.loadSolidityGreeter("Greeter.sol")
.withPackageNameReplacement(s -> s.replace("<package_name>", "test"))
.withProjectNameReplacement(s -> s.replace("<project_name>", "test"))
.withProjectNameReplacement(
s ->
s.replace(
"<project_name>",
InputVerifier.capitalizeFirstLetter("test")))
.build();
Project.builder()
.withTemplateProvider(templateProviderNew)
Expand All @@ -60,7 +66,7 @@ public void directoryCreationTest() {
@Test
public void fileCreationTest() {
final boolean mainJavaClass =
new File(projectStructure.getMainPath() + File.separator + "test.java").exists();
new File(projectStructure.getMainPath() + File.separator + "Test.java").exists();
final boolean greeterContract =
new File(projectStructure.getSolidityPath() + File.separator + "Greeter.sol")
.exists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -56,4 +57,9 @@ public void packageNameIsValidTest() {
public void packageNameIsNotValidTest() {
assertFalse(InputVerifier.packageNameIsValid("1.com"));
}

@Test
public void firstLetterIsCapitalizedTest() {
assertEquals("ClassName", InputVerifier.capitalizeFirstLetter("className"));
}
}

0 comments on commit 1c8cfc5

Please sign in to comment.