This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
132 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
pojo-generator-core/src/main/java/uk/gov/justice/generation/pojo/core/ClassNameProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package uk.gov.justice.generation.pojo.core; | ||
|
||
import uk.gov.justice.generation.pojo.dom.ClassName; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.UUID; | ||
|
||
public class ClassNameProvider { | ||
|
||
public ClassName classNameFor(final String description) { | ||
return classNameFor(description, String.class); | ||
} | ||
|
||
public ClassName classNameFor(final String description, final Class<?> defaultClass) { | ||
if(UUID.class.getSimpleName().equals(description)) { | ||
return new ClassName(UUID.class); | ||
} | ||
|
||
if(ZonedDateTime.class.getSimpleName().equals(description)) { | ||
return new ClassName(ZonedDateTime.class); | ||
} | ||
|
||
return new ClassName(defaultClass); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...nerator-core/src/test/java/uk/gov/justice/generation/pojo/core/ClassNameProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package uk.gov.justice.generation.pojo.core; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import uk.gov.justice.generation.pojo.dom.ClassName; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.UUID; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ClassNameProviderTest { | ||
|
||
@InjectMocks | ||
private ClassNameProvider classNameProvider; | ||
|
||
@Test | ||
public void shouldConvertAUUIDStringToAUUIDClassName() throws Exception { | ||
|
||
final ClassName className = classNameProvider.classNameFor("UUID"); | ||
assertThat(className.getFullyQualifiedName(), is(UUID.class.getName())); | ||
} | ||
|
||
@Test | ||
public void shouldConvertAZoneDateTimeStringToAZoneDateTimeClassName() throws Exception { | ||
|
||
final ClassName className = classNameProvider.classNameFor("ZonedDateTime"); | ||
assertThat(className.getFullyQualifiedName(), is(ZonedDateTime.class.getName())); | ||
} | ||
|
||
@Test | ||
public void shouldConvertAnyUnknownStringToAStringClassName() throws Exception { | ||
|
||
final ClassName className = classNameProvider.classNameFor("SomethingSilly"); | ||
assertThat(className.getFullyQualifiedName(), is(String.class.getName())); | ||
} | ||
|
||
@Test | ||
public void shouldHandleNullStrings() throws Exception { | ||
|
||
final ClassName className = classNameProvider.classNameFor(null); | ||
assertThat(className.getFullyQualifiedName(), is(String.class.getName())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 5 additions & 10 deletions
15
...or-core/src/test/java/uk/gov/justice/generation/pojo/core/RootFieldNameGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters