argument, String partOfWord, ArgumentIterator iterator)
+ {
+ return firstParser.complete(null, partOfWord, iterator);
+ }
+ }
+
/**
*
* Makes it possible to convert several (or zero) {@link String}s into a single {@code T} value.
@@ -525,6 +673,16 @@ ParameterArity parameterArity()
{
return ParameterArity.AT_LEAST_ONE_ARGUMENT;
}
+
+ /**
+ * @param argument the argument that was matched
+ * @param partOfWord a part of a parameter
+ * @param iterator current iterator
+ */
+ Iterable complete(@Nullable Argument argument, String partOfWord, ArgumentIterator iterator)
+ {
+ return Collections.emptyList();
+ }
}
@CheckReturnValue
@@ -596,7 +754,7 @@ static final class HelpParser extends InternalStringParser
@Override
String parse(ArgumentIterator arguments, String previousOccurance, Argument> argumentSettings, Locale locale) throws ArgumentException
{
- throw arguments.currentParser().helpFor(arguments, locale);
+ throw arguments.currentHolder().parser().helpFor(arguments, locale);
}
@Override
@@ -616,43 +774,21 @@ String metaDescription(Argument> argumentSettings)
{
return "";
}
- }
-
- /**
- * Runs a {@link Runnable} when {@link StringParser#parse(String, Locale) parse} is invoked.
- */
- static final class RunnableParser extends InternalStringParser
*/
- public static final String SUGGESTION = "Didn't expect %s, did you mean one of these?" + NEWLINE + TAB + "%s";
+ public static final String SUGGESTION = "Didn't expect %s, did you mean one of these?" + lineSeparator() + TAB + "%s";
/**
*
@@ -243,6 +244,13 @@ private ProgrammaticErrors()
* {@link ArgumentBuilder#variableArity()}
*/
public static final String SEVERAL_VARIABLE_ARITY_PARSERS = "Several unnamed arguments are configured to receive a variable arity of parameters: %s";
+
+ /**
+ * Parameter %s = a list with all parameters that is configured with
+ * {@link ArgumentBuilder#repeated()} and are {@link ArgumentBuilder#names(String...) indexed}
+ */
+ public static final String INDEXED_AND_REPEATED_ARGUMENT = "Argument: %s is both indexed and repeated. If you expect more than one parameter, use arity(...) / variableArity() instead.";
+
/**
* Parameter %s = a name that would cause ambiguous parsing
*/
@@ -280,6 +288,6 @@ private ProgrammaticErrors()
* Parameter %s = the illegal argument that the {@link CommandLineParser} wasn't
* configured to handle
*/
- public static final String ILLEGAL_ARGUMENT = "%s was not found in this result at all. Did you perhaps forget to add it to withArguments(...)?";
+ public static final String ILLEGAL_ARGUMENT = "%s was not found in this result at all. Did you perhaps forget to add it to withArguments(...)? Another failure cause could be that you are expecting to access arguments to subcommands from a parent command, that is not enabled by default.";
}
}
diff --git a/jargo/src/test/java/se/softhouse/common/classes/ClassesTest.java b/jargo/src/test/java/se/softhouse/common/classes/ClassesTest.java
index f6b30d6c..95563016 100644
--- a/jargo/src/test/java/se/softhouse/common/classes/ClassesTest.java
+++ b/jargo/src/test/java/se/softhouse/common/classes/ClassesTest.java
@@ -18,12 +18,12 @@
import org.junit.Test;
-import se.softhouse.common.testlib.Launcher;
-import se.softhouse.common.testlib.Launcher.LaunchedProgram;
-
import com.google.common.testing.NullPointerTester;
import com.google.common.testing.NullPointerTester.Visibility;
+import se.softhouse.common.testlib.Launcher;
+import se.softhouse.common.testlib.Launcher.LaunchedProgram;
+
/**
* Tests for {@link Classes}
*/
@@ -34,11 +34,10 @@ public void testThatMainClassNameIsExampleProgram() throws IOException, Interrup
{
LaunchedProgram threadedProgram = Launcher.launch(ExampleProgram.class);
- // TODO(jontejj): add assertion once
- // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8021205 has been solved
- // assertThat(threadedProgram.errors()).as("Errors detected in subprogram: " +
- // threadedProgram.errors() + ". Debuginfo:"
- // + threadedProgram.debugInformation()).isEmpty();
+ // If you get problems with this line, try to update your java environment. See
+ // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8021205 for more details.
+ assertThat(threadedProgram.errors())
+ .as("Errors detected in subprogram: " + threadedProgram.errors() + ". Debuginfo:" + threadedProgram.debugInformation()).isEmpty();
assertThat(threadedProgram.output()).isEqualTo("ExampleProgram");
}
@@ -47,11 +46,10 @@ public void testThatFetchingMainClassNameWorksFromANewThread() throws IOExceptio
{
LaunchedProgram threadedProgram = Launcher.launch(ThreadedProgram.class);
- // TODO(jontejj): add assertion once
- // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8021205 has been solved
- // assertThat(threadedProgram.errors()).as("Errors detected in subprogram: " +
- // threadedProgram.errors() + ". Debuginfo:"
- // + threadedProgram.debugInformation()).isEmpty();
+ // If you get problems with this line, try to update your java environment. See
+ // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8021205 for more details.
+ assertThat(threadedProgram.errors())
+ .as("Errors detected in subprogram: " + threadedProgram.errors() + ". Debuginfo:" + threadedProgram.debugInformation()).isEmpty();
assertThat(threadedProgram.output()).isEqualTo("ThreadedProgram");
}
diff --git a/jargo/src/test/java/se/softhouse/common/classes/NoMainAvailable.java b/jargo/src/test/java/se/softhouse/common/classes/NoMainAvailable.java
index 42e44890..e8e565b1 100644
--- a/jargo/src/test/java/se/softhouse/common/classes/NoMainAvailable.java
+++ b/jargo/src/test/java/se/softhouse/common/classes/NoMainAvailable.java
@@ -12,6 +12,8 @@
*/
package se.softhouse.common.classes;
+import static org.fest.assertions.Assertions.assertThat;
+
public final class NoMainAvailable
{
private NoMainAvailable()
@@ -38,8 +40,10 @@ public void run()
}
try
{
- Classes.mainClassName();
- System.err.print("Requesting name of mainClass after main thread has died should trigger an IllegalStateException");
+ String mainClassName = Classes.mainClassName();
+ assertThat(mainClassName)
+ .describedAs("Requesting name of mainClass after main thread has died should trigger an IllegalStateException") //
+ .isNull();
}
catch(IllegalStateException expected)
{
diff --git a/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieBenchmark.java b/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieBenchmark.java
index 411976df..fe95dbb2 100644
--- a/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieBenchmark.java
+++ b/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieBenchmark.java
@@ -15,7 +15,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.SortedMap;
import com.google.caliper.Param;
@@ -88,7 +87,7 @@ public int timePrefixSearching(int reps)
int dummy = 0;
for(int i = 0; i < reps; i++)
{
- for(Entry entry : type.entriesWithPrefix(elements, "100"))
+ for(Entry entry : type.entriesWithPrefix(elements, "100").entrySet())
{
if(entry != null)
{
@@ -103,37 +102,40 @@ private enum CollectionType
{
MAP
{
- @Override
+
+ @Override
Map createMap(Map elements)
{
return Maps.newTreeMap();
}
- @Override
- Set> entriesWithPrefix(Map elements, String prefix)
+ @Override
+ Map entriesWithPrefix(Map elements, String prefix)
{
- return ((SortedMap) elements).tailMap(prefix).entrySet();
+ return ((SortedMap) elements).tailMap(prefix);
}
- },
- CHARACTER_TRIE
- {
- @Override
+ },
+
+ CHARACTER_TRIE{
+
+ @Override
Map createMap(Map elements)
{
return CharacterTrie.newTrie(elements);
}
- @Override
- Set> entriesWithPrefix(Map elements, String prefix)
+ @Override
+ Map entriesWithPrefix(Map elements, String prefix)
{
return ((CharacterTrie) elements).getEntriesWithPrefix(prefix);
}
- };
- abstract Map createMap(Map elements);
+ };
+
+ abstract Map createMap(Map elements);
- abstract Set> entriesWithPrefix(Map elements, String prefix);
+ abstract Map entriesWithPrefix(Map elements, String prefix);
}
diff --git a/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieTest.java b/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieTest.java
index bce16bab..f00d4c92 100644
--- a/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieTest.java
+++ b/jargo/src/test/java/se/softhouse/common/collections/CharacterTrieTest.java
@@ -16,6 +16,7 @@
import static org.fest.assertions.MapAssert.entry;
import static org.junit.Assert.fail;
+import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map.Entry;
@@ -160,7 +161,7 @@ public void testFindingAllEntriesWithPrefix() throws Exception
trie.put("fooo", BAR);
trie.put("fooos", ZOO);
- Set actualEntries = valuesInSet(trie.getEntriesWithPrefix("fooo"));
+ Collection actualEntries = trie.getEntriesWithPrefix("fooo").values();
assertThat(actualEntries).containsOnly(BAR, ZOO);
}
@@ -188,7 +189,7 @@ public void testThatFindingAllEntriesWithEmptyPrefixReturnsTheWholeTrie() throws
// Make sure equals of Entry isn't fooling us
CharacterTrie copy = CharacterTrie.newTrie(trie);
- assertThat(trie.getEntriesWithPrefix("")).isEqualTo(copy.entrySet());
+ assertThat(trie.getEntriesWithPrefix("")).isEqualTo(copy.getEntriesWithPrefix(""));
}
@Test
diff --git a/jargo/src/test/java/se/softhouse/common/guavaextensions/Suppliers2Test.java b/jargo/src/test/java/se/softhouse/common/guavaextensions/Suppliers2Test.java
index 27f499d2..01fe0660 100644
--- a/jargo/src/test/java/se/softhouse/common/guavaextensions/Suppliers2Test.java
+++ b/jargo/src/test/java/se/softhouse/common/guavaextensions/Suppliers2Test.java
@@ -24,6 +24,9 @@
import com.google.common.testing.NullPointerTester;
import com.google.common.testing.NullPointerTester.Visibility;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import se.softhouse.common.testlib.Explanation;
+
/**
* Tests for {@link Suppliers2}
*/
@@ -73,6 +76,7 @@ public void testThatRepeatedElementsReturnCorrectNumberOfInstances()
}
@Test(expected = IllegalArgumentException.class)
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testThatNegativeRepeatsIsIllegal()
{
Suppliers2.ofRepeatedElements(FOO_SUPPLIER, -1);
diff --git a/jargo/src/test/java/se/softhouse/common/numbers/NumberTypeTest.java b/jargo/src/test/java/se/softhouse/common/numbers/NumberTypeTest.java
index 9d295d35..9b698ffe 100644
--- a/jargo/src/test/java/se/softhouse/common/numbers/NumberTypeTest.java
+++ b/jargo/src/test/java/se/softhouse/common/numbers/NumberTypeTest.java
@@ -13,6 +13,7 @@
package se.softhouse.common.numbers;
import static java.lang.String.format;
+import static java.lang.System.lineSeparator;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static se.softhouse.common.numbers.NumberType.BIG_DECIMAL;
@@ -22,7 +23,6 @@
import static se.softhouse.common.numbers.NumberType.LONG;
import static se.softhouse.common.numbers.NumberType.OUT_OF_RANGE;
import static se.softhouse.common.numbers.NumberType.SHORT;
-import static se.softhouse.common.strings.StringsUtil.NEWLINE;
import static se.softhouse.common.testlib.Locales.SWEDISH;
import java.math.BigDecimal;
@@ -36,6 +36,9 @@
import com.google.common.testing.NullPointerTester;
import com.google.common.testing.NullPointerTester.Visibility;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import se.softhouse.common.testlib.Explanation;
+
/**
* Tests for {@link NumberType}
*/
@@ -96,6 +99,7 @@ public void testNumbersAtBounds()
}
}
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
private void testUnlimitedType(NumberType> type)
{
try
@@ -142,6 +146,7 @@ public void testThatDescriptionOfValidValuesReturnsHumanReadableStrings() throws
}
@Test(expected = IllegalArgumentException.class)
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testThatEmptyInputThrows() throws Exception
{
BYTE.parse("");
@@ -192,6 +197,7 @@ public void testThatToStringReturnsName()
}
@Test
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testInvalidShortNumbers()
{
List invalidInput = Arrays.asList(Short.MIN_VALUE - 1, Short.MAX_VALUE + 1);
@@ -210,6 +216,7 @@ public void testInvalidShortNumbers()
}
@Test
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testInvalidIntegerNumbers()
{
List invalidInput = Arrays.asList((long) Integer.MIN_VALUE - 1, (long) Integer.MAX_VALUE + 1);
@@ -228,6 +235,7 @@ public void testInvalidIntegerNumbers()
}
@Test
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testInvalidLongNumbers()
{
List invalidInput = Arrays.asList(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE), biggerThanLong);
@@ -257,6 +265,7 @@ public void testThatNullContractsAreFollowed()
}
@Test
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testThatUnparsableIntegerGeneratesProperErrorMessage() throws Exception
{
try
@@ -269,7 +278,7 @@ public void testThatUnparsableIntegerGeneratesProperErrorMessage() throws Except
/**
* @formatter.off
*/
- assertThat(e).hasMessage("'123a' is not a valid integer (Localization: English)" + NEWLINE +
+ assertThat(e).hasMessage("'123a' is not a valid integer (Localization: English)" + lineSeparator() +
" ^");
/**
* @formatter.on
@@ -278,6 +287,7 @@ public void testThatUnparsableIntegerGeneratesProperErrorMessage() throws Except
}
@Test
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testThatUnparsableBigIntegerGeneratesProperErrorMessage() throws Exception
{
try
@@ -290,7 +300,7 @@ public void testThatUnparsableBigIntegerGeneratesProperErrorMessage() throws Exc
/**
* @formatter.off
*/
- assertThat(e).hasMessage("'12.3' is not a valid big-integer (Localization: English)" + NEWLINE +
+ assertThat(e).hasMessage("'12.3' is not a valid big-integer (Localization: English)" + lineSeparator() +
" ^");
/**
* @formatter.on
@@ -299,6 +309,7 @@ public void testThatUnparsableBigIntegerGeneratesProperErrorMessage() throws Exc
}
@Test
+ @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = Explanation.FAIL_FAST)
public void testThatDecimalSeparatorCausesParseErrorForDiscreetTypes() throws Exception
{
List> discreetTypes = Arrays.>asList(BYTE, SHORT, INTEGER, LONG, BIG_INTEGER);
diff --git a/jargo/src/test/java/se/softhouse/common/strings/DescribersTest.java b/jargo/src/test/java/se/softhouse/common/strings/DescribersTest.java
index 96453a6a..d5747584 100644
--- a/jargo/src/test/java/se/softhouse/common/strings/DescribersTest.java
+++ b/jargo/src/test/java/se/softhouse/common/strings/DescribersTest.java
@@ -12,26 +12,11 @@
*/
package se.softhouse.common.strings;
-import com.google.common.testing.NullPointerTester;
-import com.google.common.testing.NullPointerTester.Visibility;
-import org.junit.Test;
-import se.softhouse.common.strings.Describers.BooleanDescribers;
-import se.softhouse.common.testlib.Locales;
-import se.softhouse.common.testlib.ResourceLoader;
-
-import java.io.File;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
import static com.google.common.collect.Maps.newLinkedHashMap;
+import static java.lang.System.lineSeparator;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
-import static org.fest.assertions.Assertions.*;
+import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.fail;
import static se.softhouse.common.strings.Describers.asFunction;
import static se.softhouse.common.strings.Describers.booleanAsEnabledDisabled;
@@ -42,9 +27,28 @@
import static se.softhouse.common.strings.Describers.numberDescriber;
import static se.softhouse.common.strings.Describers.toStringDescriber;
import static se.softhouse.common.strings.Describers.withConstantString;
-import static se.softhouse.common.strings.StringsUtil.NEWLINE;
import static se.softhouse.common.testlib.Locales.TURKISH;
+import java.io.File;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.google.common.testing.NullPointerTester;
+import com.google.common.testing.NullPointerTester.Visibility;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import se.softhouse.common.strings.Describers.BooleanDescribers;
+import se.softhouse.common.testlib.Explanation;
+import se.softhouse.common.testlib.Locales;
+import se.softhouse.common.testlib.ResourceLoader;
+
/**
* Tests for {@link Describers}
*/
@@ -188,7 +192,7 @@ public void testMapDescriberForValuesAndKeysWithCustomSeparator()
Describer