java.util.IllegalFormatWidthException Java Examples

The following examples show how to use java.util.IllegalFormatWidthException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FuncWithFallbackTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void usesTheClosestFallback() throws Exception {
    final String expected = "Fallback from IllegalFormatException";
    MatcherAssert.assertThat(
        "Can't find the closest fallback",
        new FuncWithFallback<>(
            input -> {
                throw new IllegalFormatWidthException(1);
            },
            new IterableOf<>(
                new FallbackFrom<>(
                    IllegalArgumentException.class,
                    exp -> "Fallback from IllegalArgumentException"
                ),
                new FallbackFrom<>(
                    IllegalFormatException.class,
                    exp -> expected
                )
            )
        ),
        new FuncApplies<>(1, expected)
    );
}
 
Example #2
Source File: ScalarWithFallbackTest.java    From cactoos with MIT License 6 votes vote down vote up
@Test
public void usesTheClosestFallback() throws Exception {
    final String expected = "Fallback from IllegalFormatException";
    new Assertion<>(
        "Must find the closest fallback",
        new ScalarWithFallback<>(
            () -> {
                throw new IllegalFormatWidthException(1);
            },
            new IterableOf<>(
                new FallbackFrom<>(
                    new IterableOf<>(IllegalArgumentException.class),
                    exp -> "Fallback from IllegalArgumentException"
                ),
                new FallbackFrom<>(
                    new IterableOf<>(IllegalFormatException.class),
                    exp -> expected
                )
            )
        ),
        new ScalarHasValue<>(expected)
    ).affirm();
}
 
Example #3
Source File: FormatSpecifier.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void checkNumeric() {
	if (width != -1 && width < 0)
		throw new IllegalFormatWidthException(width);

	if (precision != -1 && precision < 0)
		throw new IllegalFormatPrecisionException(precision);

	// '-' and '0' require a width
	if (width == -1
			&& (f.contains(Flags.LEFT_JUSTIFY) || f
					.contains(Flags.ZERO_PAD)))
		throw new MissingFormatWidthException(toString());

	// bad combination
	if ((f.contains(Flags.PLUS) && f.contains(Flags.LEADING_SPACE))
			|| (f.contains(Flags.LEFT_JUSTIFY) && f
					.contains(Flags.ZERO_PAD)))
		throw new IllegalFormatFlagsException(f.toString());
}
 
Example #4
Source File: FormatSpecifier.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void checkText() {
	if (precision != -1)
		throw new IllegalFormatPrecisionException(precision);
	switch (c) {
	case Conversion.PERCENT_SIGN:
		if (f.valueOf() != Flags.LEFT_JUSTIFY.valueOf()
				&& f.valueOf() != Flags.NONE.valueOf())
			throw new IllegalFormatFlagsException(f.toString());
		// '-' requires a width
		if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
			throw new MissingFormatWidthException(toString());
		break;
	case Conversion.LINE_SEPARATOR:
		if (width != -1)
			throw new IllegalFormatWidthException(width);
		if (f.valueOf() != Flags.NONE.valueOf())
			throw new IllegalFormatFlagsException(f.toString());
		break;
	default:
           throw new UnknownFormatConversionException(String.valueOf(c));
	}
}
 
Example #5
Source File: FuncWithFallbackTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test(expected = Exception.class)
public void noFallbackIsProvided() throws Exception {
    new FuncWithFallback<>(
        input -> {
            throw new IllegalFormatWidthException(1);
        },
        new IterableOf<>()
    ).apply(1);
}
 
Example #6
Source File: ScalarWithFallbackTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test(expected = Exception.class)
public void noFallbackIsProvided() throws Exception {
    new ScalarWithFallback<>(
        () -> {
            throw new IllegalFormatWidthException(1);
        },
        new IterableOf<>()
    ).value();
}
 
Example #7
Source File: IllegalFormatWidthExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IllegalFormatWidthException#IllegalFormatWidthException(int)
 */
public void test_illegalFormatWidthException() {
    int width = Integer.MAX_VALUE;
    IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
            width);
    assertEquals(width, illegalFormatWidthException.getWidth());

}
 
Example #8
Source File: IllegalFormatWidthExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IllegalFormatWidthException#getWidth()
 */
public void test_getWidth() {
    int width = 12345;
    IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
            width);
    assertEquals(width, illegalFormatWidthException.getWidth());

}
 
Example #9
Source File: IllegalFormatWidthExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.IllegalFormatWidthException#getMessage()
 */
public void test_getMessage() {
    int width = 12345;
    IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
            width);
    assertTrue(null != illegalFormatWidthException.getMessage());

}
 
Example #10
Source File: IllegalFormatWidthExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    IllegalFormatWidthException initEx = (IllegalFormatWidthException) initial;
    IllegalFormatWidthException desrEx = (IllegalFormatWidthException) deserialized;

    assertEquals("Width", initEx.getWidth(), desrEx.getWidth());
}
 
Example #11
Source File: FormatSpecifier.java    From bazel with Apache License 2.0 5 votes vote down vote up
private int width(String s) throws FormatterNumberFormatException {
	width = -1;
	if (s != null) {
		try {
			width = Integer.parseInt(s);
			if (width < 0)
				throw new IllegalFormatWidthException(width);
		} catch (NumberFormatException x) {
               throw new FormatterNumberFormatException(s, "width");
		}
	}
	return width;
}
 
Example #12
Source File: IllegalFormatWidthExceptionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * serialization/deserialization.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new IllegalFormatWidthException(12345),
            exComparator);
}
 
Example #13
Source File: IllegalFormatWidthExceptionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new IllegalFormatWidthException(
            12345), exComparator);
}