/** * @deprecated Provided to satisfy the {@code Function} interface; use {@link #convert} instead. */ @Deprecated @Override @CanIgnoreReturnValue public final @Nullable B apply(@Nullable A a) { return convert(a); }
public void testStringConverter_convert() { Converter<String, Long> converter = Longs.stringConverter(); assertEquals((Long) 1L, converter.convert("1")); assertEquals((Long) 0L, converter.convert("0")); assertEquals((Long) (-1L), converter.convert("-1")); assertEquals((Long) 255L, converter.convert("0xff")); assertEquals((Long) 255L, converter.convert("0xFF")); assertEquals((Long) (-255L), converter.convert("-0xFF")); assertEquals((Long) 255L, converter.convert("#0000FF")); assertEquals((Long) 438L, converter.convert("0666")); }
public void testStringConverter_convert() { Converter<String, Short> converter = Shorts.stringConverter(); assertEquals((Short) (short) 1, converter.convert("1")); assertEquals((Short) (short) 0, converter.convert("0")); assertEquals((Short) (short) (-1), converter.convert("-1")); assertEquals((Short) (short) 255, converter.convert("0xff")); assertEquals((Short) (short) 255, converter.convert("0xFF")); assertEquals((Short) (short) (-255), converter.convert("-0xFF")); assertEquals((Short) (short) 255, converter.convert("#0000FF")); assertEquals((Short) (short) 438, converter.convert("0666")); }
public void testAsConverter_withNullMapping() throws Exception { BiMap<String, Integer> biMap = HashBiMap.create(); biMap.put("one", 1); biMap.put("two", 2); biMap.put("three", null); try { Maps.asConverter(biMap).convert("three"); fail(); } catch (IllegalArgumentException expected) { } }
public void testStringConverter_convert() { Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class); assertEquals(TestEnum.CHEETO, converter.convert("CHEETO")); assertEquals(TestEnum.HONDA, converter.convert("HONDA")); assertEquals(TestEnum.POODLE, converter.convert("POODLE")); assertNull(converter.convert(null)); assertNull(converter.reverse().convert(null)); }
void check() { runTester(); @SuppressWarnings("unchecked") // We are checking it anyway Converter<String, Integer> defaultConverter = (Converter<String, Integer>) getDefaultParameterValue(0); assertEquals(Integer.valueOf(0), defaultConverter.convert("anything")); assertEquals("", defaultConverter.reverse().convert(123)); assertNull(defaultConverter.convert(null)); assertNull(defaultConverter.reverse().convert(null)); } }
public void testNullIsNotPassedThrough() { Converter<String, String> nullsAreHandled = sillyConverter(true); assertEquals("forward", nullsAreHandled.convert("foo")); assertEquals(null, nullsAreHandled.convert(null)); assertEquals("backward", nullsAreHandled.reverse().convert("foo")); assertEquals(null, nullsAreHandled.reverse().convert(null)); }
public void testStringConverter_convertError() { Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class); try { converter.convert("xxx"); fail(); } catch (IllegalArgumentException expected) { } }
public void testStringConverter_convertError() { try { Floats.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
public void testStringConverter_convertError() { try { Ints.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
public void testStringConverter_convertError() { try { Doubles.stringConverter().convert("notanumber"); fail(); } catch (NumberFormatException expected) { } }
public void testStringConverter_reverse() { Converter<String, Integer> converter = Ints.stringConverter(); assertEquals("1", converter.reverse().convert(1)); assertEquals("0", converter.reverse().convert(0)); assertEquals("-1", converter.reverse().convert(-1)); assertEquals("255", converter.reverse().convert(0xff)); assertEquals("255", converter.reverse().convert(0xFF)); assertEquals("-255", converter.reverse().convert(-0xFF)); assertEquals("438", converter.reverse().convert(0666)); }
public void testStringConverter_reverse() { Converter<String, Long> converter = Longs.stringConverter(); assertEquals("1", converter.reverse().convert(1L)); assertEquals("0", converter.reverse().convert(0L)); assertEquals("-1", converter.reverse().convert(-1L)); assertEquals("255", converter.reverse().convert(0xffL)); assertEquals("255", converter.reverse().convert(0xFFL)); assertEquals("-255", converter.reverse().convert(-0xFFL)); assertEquals("438", converter.reverse().convert(0666L)); }
public void testStringConverter_reverse() { Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class); assertEquals("CHEETO", converter.reverse().convert(TestEnum.CHEETO)); assertEquals("HONDA", converter.reverse().convert(TestEnum.HONDA)); assertEquals("POODLE", converter.reverse().convert(TestEnum.POODLE)); }
@GwtIncompatible // Double.toString returns different value in GWT. public void testStringConverter_reverse() { Converter<String, Double> converter = Doubles.stringConverter(); assertEquals("1.0", converter.reverse().convert(1.0)); assertEquals("0.0", converter.reverse().convert(0.0)); assertEquals("-1.0", converter.reverse().convert(-1.0)); assertEquals("1000000.0", converter.reverse().convert(1e6)); assertEquals("1.0E-6", converter.reverse().convert(1e-6)); }
public void testConverterToBackward() { assertEquals("FOO_BAR", UPPER_UNDERSCORE.converterTo(UPPER_CAMEL).reverse().convert("FooBar")); assertEquals("FOO_BAR", UPPER_UNDERSCORE.converterTo(LOWER_CAMEL).reverse().convert("fooBar")); assertEquals("FooBar", UPPER_CAMEL.converterTo(UPPER_UNDERSCORE).reverse().convert("FOO_BAR")); assertEquals("fooBar", LOWER_CAMEL.converterTo(UPPER_UNDERSCORE).reverse().convert("FOO_BAR")); }
public void testIdentityConverter() { Converter<String, String> stringIdentityConverter = Converter.identity(); assertSame(stringIdentityConverter, stringIdentityConverter.reverse()); assertSame(STR_TO_LONG, stringIdentityConverter.andThen(STR_TO_LONG)); assertSame(STR_VAL, stringIdentityConverter.convert(STR_VAL)); assertSame(STR_VAL, stringIdentityConverter.reverse().convert(STR_VAL)); assertEquals("Converter.identity()", stringIdentityConverter.toString()); assertSame(Converter.identity(), Converter.identity()); }