-
-
Notifications
You must be signed in to change notification settings - Fork 110
Jug refactor: Separate information printing logic and its invocation #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
134fe53
separate info logic from invocation
divinenickname edbdbc5
add package to export and import declarations
divinenickname 1946b23
readme fix. update version to 5.1.0
divinenickname ee4dda6
fix tests for UsageInfo
divinenickname d2fad10
Merge branch 'master' into jug-refactor
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
package com.fasterxml.uuid.jug; | ||
|
||
import com.fasterxml.uuid.Jug; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class UsageInfo | ||
{ | ||
|
||
private static final List<String> usageMessages = new ArrayList<>(); | ||
cowtowncoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static { | ||
usageMessages.add("Usage: java " + Jug.class.getName() + " [options] type"); | ||
usageMessages.add("Where options are:"); | ||
usageMessages.add(" --count / -c <number>: will generate <number> UUIDs (default: 1)"); | ||
usageMessages.add(" --ethernet-address / -e <ether-address>: defines the ethernet address"); | ||
usageMessages.add(" (in xx:xx:xx:xx:xx:xx notation, usually obtained using 'ifconfig' etc)"); | ||
usageMessages.add(" to use with time-based UUID generation"); | ||
usageMessages.add(" --help / -h: lists the usage (ie. what you see now)"); | ||
usageMessages.add(" --name / -n: specifies"); | ||
usageMessages.add(" o name for name-based UUID generation"); | ||
usageMessages.add(" o 'information' part of tag-URI for tag-URI UUID generation"); | ||
usageMessages.add(" --namespace / -s: specifies"); | ||
usageMessages.add(" o the namespace (DNS or URL) for name-based UUID generation"); | ||
usageMessages.add(" o 'authority' part of tag-URI for tag-URI UUID generation;"); | ||
usageMessages.add(" (fully-qualified domain name, email address)"); | ||
usageMessages.add(" --performance / -p: measure time it takes to generate UUID(s)."); | ||
usageMessages.add(" [note that UUIDs are not printed out unless 'verbose' is also specified]"); | ||
usageMessages.add(" --verbose / -v: lists additional information about UUID generation\n (by default only UUIDs are printed out (to make it usable in scripts)"); | ||
usageMessages.add("And type is one of:"); | ||
usageMessages.add(" time-based / t: generate UUID based on current time and optional\n location information (defined with -e option)"); | ||
usageMessages.add(" random-based / r: generate UUID based on the default secure random number generator"); | ||
usageMessages.add(" name-based / n: generate UUID based on MD5 hash of given String ('name')"); | ||
usageMessages.add(" reordered-time-based / o: generate UUID based on current time and optional\n location information (defined with -e option)"); | ||
usageMessages.add(" epoch-based / e: generate UUID based on current time (as 'epoch') and random number"); | ||
} | ||
|
||
/** | ||
* Uses default print mechanism | ||
*/ | ||
public void print() { | ||
print(System.err::println); | ||
} | ||
|
||
/** | ||
* Uses specific print mechanism | ||
* | ||
* @param printer specific printer for messages | ||
*/ | ||
public void print(Consumer<String> printer) { | ||
usageMessages.forEach(printer); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
package com.fasterxml.uuid.jug; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class UsageInfoTest { | ||
cowtowncoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); | ||
|
||
private final String expectedMessage = "Usage: java com.fasterxml.uuid.Jug [options] type\n" + | ||
"Where options are:\n" + | ||
" --count / -c <number>: will generate <number> UUIDs (default: 1)\n" + | ||
" --ethernet-address / -e <ether-address>: defines the ethernet address\n" + | ||
" (in xx:xx:xx:xx:xx:xx notation, usually obtained using 'ifconfig' etc)\n" + | ||
" to use with time-based UUID generation\n" + | ||
" --help / -h: lists the usage (ie. what you see now)\n" + | ||
" --name / -n: specifies\n" + | ||
" o name for name-based UUID generation\n" + | ||
" o 'information' part of tag-URI for tag-URI UUID generation\n" + | ||
" --namespace / -s: specifies\n" + | ||
" o the namespace (DNS or URL) for name-based UUID generation\n" + | ||
" o 'authority' part of tag-URI for tag-URI UUID generation;\n" + | ||
" (fully-qualified domain name, email address)\n" + | ||
" --performance / -p: measure time it takes to generate UUID(s).\n" + | ||
" [note that UUIDs are not printed out unless 'verbose' is also specified]\n" + | ||
" --verbose / -v: lists additional information about UUID generation\n" + | ||
" (by default only UUIDs are printed out (to make it usable in scripts)\n" + | ||
"And type is one of:\n" + | ||
" time-based / t: generate UUID based on current time and optional\n" + | ||
" location information (defined with -e option)\n" + | ||
" random-based / r: generate UUID based on the default secure random number generator\n" + | ||
" name-based / n: generate UUID based on MD5 hash of given String ('name')\n" + | ||
" reordered-time-based / o: generate UUID based on current time and optional\n" + | ||
" location information (defined with -e option)\n" + | ||
" epoch-based / e: generate UUID based on current time (as 'epoch') and random number" + | ||
"\n"; | ||
|
||
@Before | ||
public void setup() { | ||
PrintStream stubbedStream = new PrintStream(outContent); | ||
System.setOut(stubbedStream); | ||
|
||
PrintStream stubbedErrStream = new PrintStream(errContent); | ||
System.setErr(stubbedErrStream); | ||
} | ||
|
||
/** | ||
* This test contains trailed '\n' symbol. | ||
*/ | ||
@Test | ||
public void validateMessage_defaultStdError() { | ||
new UsageInfo().print(); | ||
|
||
String actual = errContent.toString(); | ||
|
||
assertEquals(expectedMessage, actual); | ||
} | ||
|
||
@Test | ||
public void validateMessage_defaultStdOut() { | ||
new UsageInfo().print(System.out::println); | ||
|
||
String actual = outContent.toString(); | ||
|
||
assertEquals(expectedMessage, actual); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.