diff --git a/src/main/java/com/fasterxml/uuid/Jug.java b/src/main/java/com/fasterxml/uuid/Jug.java index b019447..5cc7357 100644 --- a/src/main/java/com/fasterxml/uuid/Jug.java +++ b/src/main/java/com/fasterxml/uuid/Jug.java @@ -20,12 +20,15 @@ import java.util.*; import com.fasterxml.uuid.impl.NameBasedGenerator; +import com.fasterxml.uuid.jug.UsageInfo; /** * Simple command-line interface to UUID generation functionality. */ public class Jug { + private final UsageInfo usageInfo = new UsageInfo(); + protected final static HashMap TYPES = new HashMap(); static { TYPES.put("time-based", "t"); @@ -46,34 +49,6 @@ public class Jug OPTIONS.put("performance", "p"); OPTIONS.put("verbose", "v"); } - - protected void printUsage() - { - String clsName = Jug.class.getName(); - System.err.println("Usage: java "+clsName+" [options] type"); - System.err.println("Where options are:"); - System.err.println(" --count / -c : will generate UUIDs (default: 1)"); - System.err.println(" --ethernet-address / -e : defines the ethernet address"); - System.err.println(" (in xx:xx:xx:xx:xx:xx notation, usually obtained using 'ifconfig' etc)"); - System.err.println(" to use with time-based UUID generation"); - System.err.println(" --help / -h: lists the usage (ie. what you see now)"); - System.err.println(" --name / -n: specifies"); - System.err.println(" o name for name-based UUID generation"); - System.err.println(" o 'information' part of tag-URI for tag-URI UUID generation"); - System.err.println(" --namespace / -s: specifies"); - System.err.println(" o the namespace (DNS or URL) for name-based UUID generation"); - System.err.println(" o 'authority' part of tag-URI for tag-URI UUID generation;"); - System.err.println(" (fully-qualified domain name, email address)"); - System.err.println(" --performance / -p: measure time it takes to generate UUID(s)."); - System.err.println(" [note that UUIDs are not printed out unless 'verbose' is also specified]"); - System.err.println(" --verbose / -v: lists additional information about UUID generation\n (by default only UUIDs are printed out (to make it usable in scripts)"); - System.err.println("And type is one of:"); - System.err.println(" time-based / t: generate UUID based on current time and optional\n location information (defined with -e option)"); - System.err.println(" random-based / r: generate UUID based on the default secure random number generator"); - System.err.println(" name-based / n: generate UUID based on MD5 hash of given String ('name')"); - System.err.println(" reordered-time-based / o: generate UUID based on current time and optional\n location information (defined with -e option)"); - System.err.println(" epoch-based / e: generate UUID based on current time (as 'epoch') and random number"); - } private void printMap(Map m, PrintStream out, boolean option) { @@ -107,7 +82,7 @@ public static void main(String[] args) public void run(String[] args) { if (args.length == 0) { - printUsage(); + usageInfo.print(); return; } @@ -198,7 +173,7 @@ public void run(String[] args) { } break; case 'h': - printUsage(); + usageInfo.print(); return; case 'n': // Need the name diff --git a/src/main/java/com/fasterxml/uuid/impl/LoggerFacade.java b/src/main/java/com/fasterxml/uuid/impl/LoggerFacade.java index 3aaf077..ac776d5 100644 --- a/src/main/java/com/fasterxml/uuid/impl/LoggerFacade.java +++ b/src/main/java/com/fasterxml/uuid/impl/LoggerFacade.java @@ -1,10 +1,11 @@ package com.fasterxml.uuid.impl; +import com.fasterxml.uuid.Jug; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Wrapper we (only) need to support CLI usage (see {@link com.fasterxml.uuid.Jug} + * Wrapper we (only) need to support CLI usage (see {@link Jug} * wherein we do not actually have logger package included; in which case we * will print warning(s) out to {@code System.err}. * For normal embedded usage no benefits, except if someone forgot their SLF4j API diff --git a/src/main/java/com/fasterxml/uuid/jug/UsageInfo.java b/src/main/java/com/fasterxml/uuid/jug/UsageInfo.java new file mode 100644 index 0000000..3514eb2 --- /dev/null +++ b/src/main/java/com/fasterxml/uuid/jug/UsageInfo.java @@ -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 usageMessages = new ArrayList<>(); + + static { + usageMessages.add("Usage: java " + Jug.class.getName() + " [options] type"); + usageMessages.add("Where options are:"); + usageMessages.add(" --count / -c : will generate UUIDs (default: 1)"); + usageMessages.add(" --ethernet-address / -e : 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 printer) { + usageMessages.forEach(printer); + } +} diff --git a/src/test/java/com/fasterxml/uuid/JugNamedTest.java b/src/test/java/com/fasterxml/uuid/jug/JugNamedTest.java similarity index 98% rename from src/test/java/com/fasterxml/uuid/JugNamedTest.java rename to src/test/java/com/fasterxml/uuid/jug/JugNamedTest.java index 2352a94..2ffdd57 100644 --- a/src/test/java/com/fasterxml/uuid/JugNamedTest.java +++ b/src/test/java/com/fasterxml/uuid/jug/JugNamedTest.java @@ -1,5 +1,6 @@ -package com.fasterxml.uuid; +package com.fasterxml.uuid.jug; +import com.fasterxml.uuid.Jug; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -175,4 +176,4 @@ public String toString() { } } } -} \ No newline at end of file +} diff --git a/src/test/java/com/fasterxml/uuid/JugNoArgsTest.java b/src/test/java/com/fasterxml/uuid/jug/JugNoArgsTest.java similarity index 99% rename from src/test/java/com/fasterxml/uuid/JugNoArgsTest.java rename to src/test/java/com/fasterxml/uuid/jug/JugNoArgsTest.java index d000105..90849ac 100644 --- a/src/test/java/com/fasterxml/uuid/JugNoArgsTest.java +++ b/src/test/java/com/fasterxml/uuid/jug/JugNoArgsTest.java @@ -1,5 +1,6 @@ -package com.fasterxml.uuid; +package com.fasterxml.uuid.jug; +import com.fasterxml.uuid.Jug; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -214,4 +215,4 @@ public static List useCases() { "m" ); } -} \ No newline at end of file +} diff --git a/src/test/java/com/fasterxml/uuid/jug/UsageInfoTest.java b/src/test/java/com/fasterxml/uuid/jug/UsageInfoTest.java new file mode 100644 index 0000000..6bca8f7 --- /dev/null +++ b/src/test/java/com/fasterxml/uuid/jug/UsageInfoTest.java @@ -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 { + + 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 : will generate UUIDs (default: 1)\n" + + " --ethernet-address / -e : 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); + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy