src_fm_fc_ms_ff stringlengths 43 86.8k | target stringlengths 20 276k |
|---|---|
Schooljaar implements IBeginEinddatumEntiteit, Comparable<Schooljaar>,
Serializable { public static Schooljaar parse(String value) { Pattern[] patterns = new Pattern[] {officieel, kort}; for (Pattern pattern : patterns) { Matcher matcher = pattern.matcher(value); if (!matcher.matches()) { continue; } String startJaar... | @Test public void parseAAAA_2009fails() { assertThat(Schooljaar.parse("AAAA/2009"), is(nullValue())); }
@Test public void parse2008_AAAAfails() { assertThat(Schooljaar.parse("2008/AAAA"), is(nullValue())); }
@Test public void parse2008A2009fails() { assertThat(Schooljaar.parse("2008A2009"), is(nullValue())); } |
NaturalOrderComparator implements Comparator<Object>, Serializable { @Override public int compare(Object o1, Object o2) { String a = o1.toString(); String b = o2.toString(); int ia = 0, ib = 0; int nza = 0, nzb = 0; char ca, cb; int result; while (true) { nza = nzb = 0; ca = charAt(a, ia); cb = charAt(b, ib); while (Ch... | @Test public void testCompare() { String[] strings = new String[] {"1-2", "1-02", "1-20", "10-20", "fred", "jane", "pic01", "pic2", "pic02", "pic02a", "pic3", "pic4", "pic 4 else", "pic 5", "pic 5 something", "pic05", "pic 6", "pic 7", "pic100", "pic100a", "pic120", "pic121", "pic02000", "tom", "x2-g8", "x2-y7", "x2-y0... |
ExceptionUtil { public static void printStackTrace(PrintWriter pw, Throwable t) { printStackTrace(pw, t, new StackTraceElement[] {}); } static String getDescription(Exception exception); static boolean isCausedBy(Throwable exception, Class< ? extends Throwable> cause); static void printStackTrace(PrintWriter pw, Throw... | @Test public void enkelvoudigeExceptie() { NullPointerException e = returnsNullPointerException(); ExceptionUtil.printStackTrace(pw, e); String expected = "java.lang.NullPointerException" + newLine() + "\tat nl.topicus.cobra.util.ExceptionUtilTest.returnsNullPointerException(ExceptionUtilTest.java:25)"; Assert.assertEq... |
DecimalUtil { public static final boolean nonZero(BigDecimal decimal) { return decimal != null && decimal.compareTo(BigDecimal.ZERO) != 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final ... | @Test public void testNonZero() { Assert.assertFalse(DecimalUtil.nonZero(null)); Assert.assertFalse(DecimalUtil.nonZero(BigDecimal.ZERO)); Assert.assertTrue(DecimalUtil.nonZero(DecimalUtil.THREE)); } |
DecimalUtil { public static final boolean isZero(BigDecimal decimal) { return decimal.compareTo(BigDecimal.ZERO) == 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boolean greaterThan(... | @Test public void testIsZero() { Assert.assertTrue(DecimalUtil.isZero(BigDecimal.ZERO)); Assert.assertFalse(DecimalUtil.isZero(DecimalUtil.THREE)); } |
DecimalUtil { public static final boolean greaterThan(BigDecimal is, BigDecimal than) { return is.compareTo(than) > 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boolean greaterThan(... | @Test public void testGreaterThanBigDecimalBigDecimal() { Assert.assertTrue(DecimalUtil.greaterThan(DecimalUtil.SEVEN, DecimalUtil.THREE)); Assert.assertFalse(DecimalUtil.greaterThan(DecimalUtil.TWO, DecimalUtil.EIGHT)); Assert.assertFalse(DecimalUtil.greaterThan(DecimalUtil.SEVEN, DecimalUtil.SEVEN)); }
@Test public v... |
DecimalUtil { public static final boolean greaterThanOrEqual(BigDecimal is, int than) { return is.compareTo(BigDecimal.valueOf(than)) >= 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final... | @Test public void testGreaterThanOrEqual() { Assert.assertTrue(DecimalUtil.greaterThanOrEqual(DecimalUtil.SEVEN, 3)); Assert.assertFalse(DecimalUtil.greaterThanOrEqual(DecimalUtil.TWO, 8)); Assert.assertTrue(DecimalUtil.greaterThanOrEqual(DecimalUtil.SEVEN, 7)); } |
DecimalUtil { public static final int compare(BigDecimal one, BigDecimal other) { if (one == null && other == null) return 0; if (one == null) return -1; else if (other == null) return 1; return one.compareTo(other); } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); s... | @Test public void testCompare() { Assert.assertEquals(0, DecimalUtil.compare(null, null)); Assert.assertEquals(-1, DecimalUtil.compare(null, DecimalUtil.SEVEN)); Assert.assertEquals(1, DecimalUtil.compare(DecimalUtil.SEVEN, null)); Assert.assertEquals(0, DecimalUtil.compare(DecimalUtil.SEVEN, DecimalUtil.SEVEN)); Asser... |
DecimalUtil { public static final BigDecimal max(BigDecimal one, BigDecimal other) { return (one.compareTo(other) > 0 ? one : other); } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boole... | @Test public void testMax() { Assert.assertEquals(DecimalUtil.FIVE, DecimalUtil.max(DecimalUtil.FIVE, DecimalUtil.FOUR)); Assert.assertEquals(DecimalUtil.FIVE, DecimalUtil.max(DecimalUtil.ONE, DecimalUtil.FIVE)); } |
DecimalUtil { public static final BigDecimal min(BigDecimal one, BigDecimal other) { return (one.compareTo(other) < 0 ? one : other); } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boole... | @Test public void testMin() { Assert.assertEquals(DecimalUtil.FOUR, DecimalUtil.min(DecimalUtil.FIVE, DecimalUtil.FOUR)); Assert.assertEquals(DecimalUtil.FOUR, DecimalUtil.min(DecimalUtil.FOUR, DecimalUtil.NINE)); } |
DecimalUtil { public static final boolean greaterThanZero(BigDecimal is) { return is != null && is.compareTo(BigDecimal.ZERO) > 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boolean ... | @Test public void testGreaterThanZero() { Assert.assertFalse(DecimalUtil.greaterThanZero(null)); Assert.assertFalse(DecimalUtil.greaterThanZero(BigDecimal.ZERO)); Assert.assertTrue(DecimalUtil.greaterThanZero(DecimalUtil.SEVEN)); } |
DecimalUtil { public static boolean zeroOrMore(BigDecimal decimal) { return decimal != null && decimal.compareTo(BigDecimal.ZERO) >= 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boo... | @Test public void testZeroOrMore() { Assert.assertFalse(DecimalUtil.zeroOrMore(null)); Assert.assertFalse(DecimalUtil.zeroOrMore(BigDecimal.valueOf(-0.01))); Assert.assertTrue(DecimalUtil.zeroOrMore(BigDecimal.ZERO)); Assert.assertTrue(DecimalUtil.zeroOrMore(BigDecimal.valueOf(0.01))); Assert.assertTrue(DecimalUtil.zer... |
DecimalUtil { public static final boolean lessThanZero(BigDecimal decimal) { if (decimal == null) return false; return decimal.compareTo(BigDecimal.ZERO) < 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal ... | @Test public void testLessThanZero() { Assert.assertFalse(DecimalUtil.lessThanZero(null)); Assert.assertTrue(DecimalUtil.lessThanZero(BigDecimal.valueOf(-0.01))); Assert.assertFalse(DecimalUtil.lessThanZero(BigDecimal.ZERO)); Assert.assertFalse(DecimalUtil.lessThanZero(BigDecimal.valueOf(0.01))); Assert.assertTrue(Deci... |
DecimalUtil { public static final boolean lessOrEqualtoZero(BigDecimal decimal) { if (decimal == null) return false; return decimal.compareTo(BigDecimal.ZERO) <= 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDe... | @Test public void testLessOrEqualtoZero() { Assert.assertFalse(DecimalUtil.lessOrEqualtoZero(null)); Assert.assertTrue(DecimalUtil.lessOrEqualtoZero(BigDecimal.valueOf(-0.01))); Assert.assertTrue(DecimalUtil.lessOrEqualtoZero(BigDecimal.ZERO)); Assert.assertFalse(DecimalUtil.lessOrEqualtoZero(BigDecimal.valueOf(0.01)))... |
DecimalUtil { public static final boolean lessOrEqual(BigDecimal decimal, int other) { return decimal.compareTo(BigDecimal.valueOf(other)) <= 0; } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static ... | @Test public void testLessOrEqual() { Assert.assertTrue(DecimalUtil.lessOrEqual(DecimalUtil.FIVE, 11)); Assert.assertFalse(DecimalUtil.lessOrEqual(DecimalUtil.FIVE, 3)); } |
DecimalUtil { public static final BigDecimal divide(BigDecimal decimal, int by) { return decimal.divide(BigDecimal.valueOf(by)); } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boolean gr... | @Test public void testDivideBigDecimalInt() { Assert.assertEquals(BigDecimal.ZERO, DecimalUtil.divide(BigDecimal.ZERO, 3)); Assert.assertEquals(DecimalUtil.TWO, DecimalUtil.divide(DecimalUtil.EIGHT, 4)); }
@Test public void testDivideBigDecimalMathContextInt() { MathContext mc = new MathContext(1, RoundingMode.HALF_UP)... |
DecimalUtil { public static final BigDecimal multiply(BigDecimal decimal, int by) { return decimal.multiply(BigDecimal.valueOf(by)); } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boolea... | @Test public void testMultiply() { Assert.assertEquals(DecimalUtil.SIX, DecimalUtil.multiply(DecimalUtil.THREE, 2)); } |
DecimalUtil { public static final BigDecimal valueOf(String string) { return new BigDecimal(localizeString(string)); } static final boolean nonZero(BigDecimal decimal); static final boolean isZero(BigDecimal decimal); static final boolean greaterThan(BigDecimal is, BigDecimal than); static final boolean greaterThan(Bi... | @Test public void testValueOf() { Assert.assertEquals(BigDecimal.ZERO, DecimalUtil.valueOf("0")); Assert.assertEquals(BigDecimal.valueOf(0.1), DecimalUtil.valueOf("0.1")); Assert.assertEquals(BigDecimal.valueOf(0.1), DecimalUtil.valueOf("0,1")); Assert.assertEquals(BigDecimal.valueOf(1000.1), DecimalUtil.valueOf("1.000... |
Asserts { public static void assertNotNull(final String parameter, final Object waarde) { if (log.isDebugEnabled()) { String waardeText = String.valueOf(waarde); waardeText = waardeText.substring(0, Math.min(waardeText.length(), 16)); log.debug("Controleer dat " + parameter + " niet null is, huidige waarde: '" + waarde... | @Test(expected = IllegalArgumentException.class) public void testAssertNotNullMetNull() { Asserts.assertNotNull("foo", null); }
@Test public void testAssertNotNullMetNotNull() { Asserts.assertNotNull("foo", new Object()); } |
Asserts { public static void assertNotEmpty(String parameter, Object waarde) { assertNotNull(parameter, waarde); if ("".equals(waarde.toString().trim())) { String bericht = "Parameter " + parameter + " is leeg"; throw new IllegalArgumentException(bericht); } } static void assertNotNull(final String parameter, final Ob... | @Test(expected = IllegalArgumentException.class) public void testAssertNotEmptyMetEmpty() { Asserts.assertNotEmpty("foo", ""); }
@Test public void testAssertNotEmptyMetNotEmpty() { Asserts.assertNotEmpty("foo", "123"); } |
Asserts { public static void assertMatchesRegExp(String parameter, String value, String regexp) { assertNotNull(parameter, value); assertNotNull("regexp", regexp); Pattern pattern = Pattern.compile(regexp); String trimmedValue = value.trim(); Matcher matcher = pattern.matcher(trimmedValue.subSequence(0, trimmedValue.le... | @Test public void testAssertMatchesRegExp() { Asserts.assertMatchesRegExp("postcode", "1234 Aa", "[1-9][0-9]{3} ?[a-zA-Z]{2}"); Asserts.assertMatchesRegExp("postcode", "1234Aa", "[1-9][0-9]{3} ?[a-zA-Z]{2}"); Asserts.assertMatchesRegExp("postcode", " 1234 Aa ", "[1-9][0-9]{3} ?[a-zA-Z]{2}"); }
@Test(expected = IllegalA... |
Dutch implements ToWords { @SuppressWarnings("all") public String toWords(long num) { if (num == 0) return ZERO; boolean negative = (num < 0); if (negative) num = -num; String s = ""; for (int group = 0; num > 0; group++) { int remdr = (int) (num % divisor[group]); num = num / divisor[group]; if (group == 1&& 1 <= num ... | @Test public void test0() { Assert.assertEquals("nul", dutch.toWords(0)); }
@Test public void testMin1() { Assert.assertEquals("min een", dutch.toWords(-1)); }
@Test public void test1() { Assert.assertEquals("een", dutch.toWords(1)); }
@Test public void testMin10() { Assert.assertEquals("min tien", dutch.toWords(-10));... |
StringUtil { public static Integer getFirstNumberSequence(String tekst) { if (tekst == null) return Integer.valueOf(0); int start = Integer.MAX_VALUE; int end = Integer.MIN_VALUE; boolean inNumberSequence = false; for (int i = 0; i < tekst.length(); i++) { if (tekst.charAt(i) >= '0' && tekst.charAt(i) <= '9') { start =... | @Test public void getNumberPart1() { String test = "t.o. 12 a"; assertEquals(new Integer(12), StringUtil.getFirstNumberSequence(test)); }
@Test public void getNumberPart2() { String test = ""; assertNull(StringUtil.getFirstNumberSequence(test)); }
@Test public void getNumberPart3() { String test = "abcdefg"; assertNull... |
StringUtil { public static String truncate(String source, int maxLength, String cutoffReplacement) { if (source == null || source.length() <= maxLength) return source; int cutoffLength = maxLength; if (cutoffReplacement != null) cutoffLength -= cutoffReplacement.length(); if (cutoffLength <= 0) { if (cutoffReplacement ... | @Test public void truncate1() { String org = "test"; String replace = ".."; int max = 500; assertEquals(org, StringUtil.truncate(org, max, replace)); }
@Test public void truncate2() { String org = "test"; int max = 3; assertEquals("tes", StringUtil.truncate(org, max, null)); }
@Test public void truncate3() { String org... |
StringUtil { public static String containsSamengesteldeLetter(String value) { if (isEmpty(value)) return " "; String naam = value.toUpperCase(); for (String letter : SAMENGESTELDE_LETTERS) { if (naam.startsWith(letter)) { return letter; } } return String.valueOf(value.charAt(0)).toUpperCase(); } private StringUtil(); ... | @Test public void samenGesteldeLetter() { String naam = "IJsbrand"; String naam1 = "Pietje"; assertEquals("IJ", StringUtil.containsSamengesteldeLetter(naam)); assertEquals("P", StringUtil.containsSamengesteldeLetter(naam1)); } |
StringUtil { public static String firstLetterUppercase(String name) { if (StringUtil.isEmpty(name)) return " "; Integer firstLetterPos = null; for (int i = 0; i < name.length() && firstLetterPos == null; i++) { if (Character.isLetter(name.charAt(i))) firstLetterPos = i; } if (firstLetterPos != null) return new StringBu... | @Test public void voorvoegselsEersteLetterHoofdletter() { assertEquals("'T", StringUtil.firstLetterUppercase("'t")); assertEquals("T", StringUtil.firstLetterUppercase("t")); assertEquals("Ten", StringUtil.firstLetterUppercase("ten")); assertEquals("10 Links", StringUtil.firstLetterUppercase("10 links")); assertEquals("... |
SpringBootExample implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(SpringBootExample.class, args); } static void main(String[] args); @Override void run(String... args); } | @Test public void shouldExecuteMainWithoutExceptions() { SpringBootExample.main(new String[0]); } |
WritableMapConfigurationSource extends MapConfigurationSource implements WritableConfigurationSource { @Override public OptionalValue<String> removeValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); return source.containsKey(key) ? present(source.remove(key)) : absent(); } Wr... | @Test public void shouldRemoveValue() { Map<String, String> map = new HashMap<>(); map.put("key", "value"); WritableConfigurationSource mapConfigurationSource = new WritableMapConfigurationSource(map); mapConfigurationSource.removeValue("key", null); assertThat(mapConfigurationSource.getValue("key", null).isPresent()).... |
PropertiesConfigurationSource implements IterableConfigurationSource { @Override public Iterable<ConfigurationEntry> getAllConfigurationEntries() { Map<String, String> map = source.entrySet().stream() .filter(e -> e.getValue() instanceof String) .collect(toMap(Object::toString, e -> (String) e.getValue())); return new ... | @Test public void shouldLoadPropertiesFromFile() { PropertiesConfigurationSource source = new PropertiesConfigurationSource(file.getAbsolutePath()); assertThat(source.getAllConfigurationEntries().iterator()).isEmpty(); } |
PatternConverter implements TypeConverter<Pattern> { @Override public Pattern fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); try { return (value == null) ? null : Pattern.compile(value); } catch (PatternSyntaxException e) { throw new IllegalArgumentExc... | @Test public void shouldConvertFromString() { Pattern pattern = Pattern.compile(".*"); Pattern value = converter.fromString(Pattern.class, ".*", null); assertThat(value.pattern()).isEqualTo(pattern.pattern()); }
@Test public void shouldThrowExceptionWhenConvertingFromStringAndWrongValue() { String value = "{"; assertTh... |
PatternConverter implements TypeConverter<Pattern> { @Override public String toString(Type type, Pattern value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return Objects.toString(value, null); } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override Pat... | @Test public void shouldConvertToString() { Pattern pattern = Pattern.compile("123.*"); String asString = converter.toString(Pattern.class, pattern, null); assertThat(asString).isEqualTo(pattern.toString()); } |
PatternConverter implements TypeConverter<Pattern> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && Pattern.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type type, Map<String... | @Test public void shouldAcceptType() { Type type = Pattern.class; boolean isApplicable = converter.isApplicable(type, null); assertThat(isApplicable).isTrue(); }
@Test public void shouldNotAcceptUnknownType() { boolean isApplicable = converter.isApplicable(mock(Type.class), null); assertThat(isApplicable).isFalse(); } |
ObjectBuilder { ObjectBuilder beginList() { return beginList(new ArrayList<>()); } } | @Test public void shouldFailInCaseEndingObjectWhenArrayWasBegun() { assertThatThrowExceptionOfType( new ObjectBuilder().beginList()::endMap, IllegalStateException.class); } |
ObjectBuilder { ObjectBuilder beginMap() { return beginMap(new LinkedHashMap<>()); } } | @Test public void shouldFailInCaseEndingArrayWhenObjectWasBegun() { assertThatThrowExceptionOfType( new ObjectBuilder().beginMap()::endList, IllegalStateException.class); } |
TypeConverterUtils { static int notEscapedIndexOf(CharSequence value, int startPos, char character) { Objects.requireNonNull(value, "value must not be null"); char prev = 0xffff; for (int i = max(startPos, 0), len = value.length(); i < len; i++) { char current = value.charAt(i); if (current == character) { if (prev == ... | @Test public void shouldProperlyReturnNotEscapedIndexOf() { assertThat(TypeConverterUtils.notEscapedIndexOf("abcb", 0, 'b')).isEqualTo(1); assertThat(TypeConverterUtils.notEscapedIndexOf("a\\bcb", 0, 'b')).isEqualTo(4); assertThat(TypeConverterUtils.notEscapedIndexOf("a\\b\\\\bcb", 0, 'b')).isEqualTo(5); }
@Test public... |
JaxbConverter implements TypeConverter<T> { @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (isBlank(value)) { return null; } @SuppressWarnings("unchecked") Class<T> targetClazz = (Class<T>) type; JaxbPool jaxbPool = getJaxbPool(ta... | @Test public void shouldReturnNullObjectForBlankXML() { String resource = " "; XmlRootConfiguration01 xmlRootConfiguration01 = (XmlRootConfiguration01) jaxbTypeConverter.fromString(XmlRootConfiguration01.class, resource, null); assertThat(xmlRootConfiguration01).isNull(); }
@Test public void shouldReturnNullObjectForNu... |
PeriodConverter implements TypeConverter<Period> { @Override public Period fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); try { return value == null ? null : Period.parse(value); } catch (DateTimeParseException e) { throw new IllegalArgumentException(f... | @Test public void shouldConvertFromString() { Period period = Period.ofDays(123); Period readPeriod = converter.fromString(Period.class, "P123D", null); assertThat(readPeriod).isEqualTo(period); }
@Test public void shouldThrowExceptionWhenConvertingFromStringAndWrongValue() { String toConvert = "XXXXX"; assertThatThrow... |
PeriodConverter implements TypeConverter<Period> { @Override public String toString(Type type, Period value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return Objects.toString(value, null); } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override Period... | @Test public void shouldConvertToString() { Period period = Period.ofDays(123); String asString = converter.toString(Period.class, period, null); assertThat(asString).isEqualTo("P123D"); } |
PeriodConverter implements TypeConverter<Period> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && Period.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type type, Map<String, S... | @Test public void shouldAcceptPeriodType() { Type type = Period.class; boolean isApplicable = converter.isApplicable(type, null); assertThat(isApplicable).isTrue(); }
@Test public void shouldNotAcceptUnknownType() { boolean isApplicable = converter.isApplicable(mock(Type.class), null); assertThat(isApplicable).isFalse(... |
LongConverter extends AbstractNumberConverter<Long> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, Long.class, Long.TYPE); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableWhenLongType() { Type type = Long.class; boolean applicable = longTypeConverter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotLongType() { Type type = Boolean.class; boolean applicable = longTypeConverter.isApplicable... |
OffsetDateTimeConverter extends AbstractTemporalAccessorConverter<OffsetDateTime> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && OffsetDateTime.class.isAssignableFrom((Class<?>) type); } @Override bool... | @Test public void shouldBeApplicableWhenOffsetDateTimeType() { Type type = OffsetDateTime.class; boolean applicable = offsetDateTimeConverter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotOffsetDateTimeType() { Type type = Boolean.class; boolean applica... |
CharacterConverter implements TypeConverter<Character> { @Override public Character fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null || value.isEmpty()) { return null; } if (value.length() == 1) { return value.charAt(0); } if (value.cha... | @Test public void shouldReadValuesFromStringWhenNotUnescaping() { String stringValue = "A"; Character value = converter.fromString(Character.class, stringValue, null); assertThat(value).isEqualTo('A'); }
@Test public void shouldReadValuesFromStringWhenUnescaping() { String stringValue = "\\u0080"; Character value = con... |
CharacterConverter implements TypeConverter<Character> { @Override public String toString(Type type, Character value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return value == null ? null : escapeJava(value.toString()); } @Override boolean isApplicable(Type type, Map<String, String... | @Test public void shouldWriteValueAsString() { Character value = 'A'; String asString = converter.toString(Character.class, value, null); assertThat(asString).isEqualTo("A"); }
@Test public void shouldConvertToNullFromNull() { Character value = null; String asString = converter.toString(Character.class, value, null); a... |
CharacterConverter implements TypeConverter<Character> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && (Character.class.isAssignableFrom((Class<?>) type) || Character.TYPE.isAssignableFrom((Class<?>) typ... | @Test public void shouldBeApplicableToCharacter() { boolean applicable = converter.isApplicable(Character.class, null); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableToNonCharacter() { boolean applicable = converter.isApplicable(Object.class, null); assertThat(applicable).isFalse(); } |
DurationConverter implements TypeConverter<Duration> { @Override public Duration fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); String format = (attributes == null) ? null : attributes.get(FORMAT); if (format != null) { try { SimpleDateFormat dateForma... | @Test public void shouldConvertFromStringWhenFormatNotSpecified() { Duration duration = Duration.ofMillis(1260535L); Duration readDuration = converter.fromString(Duration.class, "PT21M0.535S", null); assertThat(readDuration).isEqualTo(duration); }
@Test public void shouldConvertFromStringWhenFormatSpecified() { Duratio... |
DurationConverter implements TypeConverter<Duration> { @Override public String toString(Type type, Duration value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } String format = (attributes == null) ? null : attributes.get(FORMAT); if (format != null) ... | @Test public void shouldConvertToStringWhenFormatNotSpecified() { Duration duration = Duration.ofMillis(1260535L); String asString = converter.toString(Duration.class, duration, null); assertThat(asString).isEqualTo("PT21M0.535S"); }
@Test public void shouldConvertToStringWhenFormatSpecified() { Duration duration = Dur... |
DurationConverter implements TypeConverter<Duration> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && Duration.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type type, Map<Str... | @Test public void shouldAcceptReadableDurationType() { Type type = Duration.class; boolean isApplicable = converter.isApplicable(type, null); assertThat(isApplicable).isTrue(); }
@Test public void shouldNotAcceptUnknownType() { boolean isApplicable = converter.isApplicable(mock(Type.class), null); assertThat(isApplicab... |
ByteConverter extends AbstractNumberConverter<Byte> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, Byte.class, Byte.TYPE); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableWhenByteType() { Type type = Byte.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotByteType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(type, emptyMap(... |
LocalDateTimeConverter extends AbstractTemporalAccessorConverter<LocalDateTime> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && LocalDateTime.class.isAssignableFrom((Class<?>) type); } @Override boolean... | @Test public void shouldBeApplicableWhenLocalDateTimeType() { Type type = LocalDateTime.class; boolean applicable = localDateTimeTypeConverter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotLocalDateTimeType() { Type type = Boolean.class; boolean applica... |
BigDecimalConverter extends AbstractNumberConverter<BigDecimal> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, BigDecimal.class, null); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableToBigDecimal() { boolean applicable = converter.isApplicable(BigDecimal.class, null); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableToNonBigDecimal() { boolean applicable = converter.isApplicable(Object.class, null); assertThat(applicable).isFalse(); } |
IntegerConverter extends AbstractNumberConverter<Integer> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, Integer.class, Integer.TYPE); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableWhenIntegerType() { Type type = Integer.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotIntegerType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(type, ... |
DoubleConverter extends AbstractNumberConverter<Double> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, Double.class, Double.TYPE); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableWhenDoubleType() { Type type = Double.class; boolean applicable = doubleTypeConverter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotDoubleType() { Type type = Boolean.class; boolean applicable = doubleTypeConverter.is... |
CurrencyConverter implements TypeConverter<Currency> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && Currency.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type type, Map<Str... | @Test public void shouldBeApplicableWhenCurrencyType() { Type type = Currency.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotCurrencyType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(typ... |
YamlConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); String converter = (attributes == null) ? null : attributes.get(CONVERTER); return ignoreConverterAttribute || Objects.equals(converter, YAML); } Ya... | @Test void shouldThrowExceptionWhenTypeIsNullAndIsApplicable() { assertThatThrownBy(() -> typeConverter.isApplicable(null, null)) .isExactlyInstanceOf(NullPointerException.class) .hasMessage("type cannot be null"); } |
CurrencyConverter implements TypeConverter<Currency> { @Override public String toString(Type type, Currency value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return value == null ? null : value.getCurrencyCode(); } @Override boolean isApplicable(Type type, Map<String, String> attrib... | @Test public void shouldConvertToString() { Currency toConvert = Currency.getInstance("USD"); String converted = converter.toString(Currency.class, toConvert, emptyMap()); assertThat(converted).isEqualTo("USD"); }
@Test public void shouldReturnNullWhenToStringAndValueIsNull() { String converted = converter.toString(Cur... |
CurrencyConverter implements TypeConverter<Currency> { @Override public Currency fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return value == null ? null : Currency.getInstance(value); } @Override boolean isApplicable(Type type, Map<String, String> ... | @Test public void shouldConvertFromString() { String toConvert = "USD"; Currency converted = converter.fromString(Currency.class, toConvert, emptyMap()); assertThat(converted).isEqualTo(Currency.getInstance("USD")); }
@Test public void shouldThrowExceptionWhenInvalidFormat() { String toConvert = "invalid"; assertThatTh... |
BooleanConverter implements TypeConverter<Boolean> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && (Boolean.class.isAssignableFrom((Class<?>) type) || Boolean.TYPE.isAssignableFrom((Class<?>) type)); } ... | @Test public void shouldBeApplicableWhenBooleanType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotBooleanType() { Type type = Integer.class; boolean applicable = converter.isApplicable(type, ... |
YamlConverter implements TypeConverter<T> { @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { JavaType javaType = TypeFactory.defaultInstance().constructType(type); ObjectReader objectReader = o... | @Test void shouldConvertFromString() { String toConvert = "" + "integer: 1\n" + "string: test-1\n"; TestClass converted = typeConverter.fromString(TestClass.class, toConvert, null); assertThat(converted).isEqualTo(new TestClass(1, "test-1")); }
@Test void shouldConvertCollectionFromString() { String toConvert = "" + "-... |
BooleanConverter implements TypeConverter<Boolean> { @Override public String toString(Type type, Boolean value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (attributes != null && attributes.containsKey(FORMAT)) { String format = attributes.get(FORMAT); Pair<String, String> values =... | @Test public void shouldConvertToStringWhenFormatNotSpecifiedAndTrue() { Boolean b = true; String converted = converter.toString(Boolean.class, b, emptyMap()); assertThat(converted).isEqualTo("true"); }
@Test public void shouldConvertToStringWhenFormatNotSpecifiedAndFalse() { Boolean b = false; String converted = conve... |
BooleanConverter implements TypeConverter<Boolean> { @Override public Boolean fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } String format = (attributes == null) ? null : attributes.get(FORMAT); if (format != null) {... | @Test public void shouldThrowExceptionWhenConvertingFromStringAndWrongValue() { String aString = "wrong value"; assertThatThrownBy(() -> converter.fromString(Boolean.class, aString, null)) .isExactlyInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Unable to convert to Boolean. Unknown value:"); }
@Test... |
InstantConverter extends AbstractTemporalAccessorConverter<Instant> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && Instant.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type... | @Test public void shouldBeApplicableWhenInstantType() { Type type = Instant.class; boolean applicable = instantConverter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotInstantType() { Type type = Boolean.class; boolean applicable = instantConverter.isApp... |
InstantConverter extends AbstractTemporalAccessorConverter<Instant> { @Override public String toString(Type type, Instant value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } String format = null; ZoneId zoneId = DEFAULT_ZONE; if (attributes != null) ... | @Test public void shouldConvertToStringWhenFormatNotSpecified() { Instant toConvert = Instant.EPOCH; String converted = instantConverter.toString(Instant.class, toConvert, emptyMap()); assertThat(converted).isEqualTo("1970-01-01T00:00:00Z"); }
@Test public void shouldConvertToStringWhenFormatSpecifiedAndDefaultZone() {... |
StringConverter implements TypeConverter<String> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && String.class.isAssignableFrom((Class<?>) type); } StringConverter(boolean escape); StringConverter(); @Ov... | @Test public void shouldBeApplicableWhenStringType() { Type type = String.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotStringType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(type, emp... |
StringConverter implements TypeConverter<String> { @Override public String fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return shouldEscape(attributes) ? unescapeJava(value) : value; } StringConverter(boolean escape); StringConverter(); @Override bo... | @Test public void shouldConvertFromStringWhenFormatNotSpecified() { String in = "One\\\\Two"; String expected = "One\\Two"; String out = converter.fromString(String.class, in, null); assertThat(out).isEqualTo(expected); }
@Test public void shouldConvertFromStringWhenFormatSpecifiedAndFalse() { String in = "One\\\\Two";... |
GenericsExample { public static void main(String[] args) { new GenericsExample().run(); } static void main(String[] args); } | @Test public void shouldExecuteMainWithoutExceptions() { GenericsExample.main(new String[0]); } |
StringConverter implements TypeConverter<String> { @Override public String toString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return shouldEscape(attributes) ? escapeJava(value) : value; } StringConverter(boolean escape); StringConverter(); @Override boolea... | @Test public void shouldConvertToStringWhenFormatNotSpecified() { String in = "One\\Two"; String expected = "One\\\\Two"; String out = converter.toString(String.class, in, null); assertThat(out).isEqualTo(expected); }
@Test public void shouldConvertToStringWhenFormatSpecifiedAndFalse() { String in = "One\\Two"; String ... |
JsonLikeConverter implements TypeConverter<Object> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if (parameterizedType.getRawType()... | @Test public void shouldProperlyIndicateSupportedTypes() { assertThat(typeConverter.isApplicable(SUPPORTED_LIST_TYPE, null)).isTrue(); assertThat(typeConverter.isApplicable(SUPPORTED_MAP_TYPE, null)).isTrue(); assertThat(typeConverter.isApplicable(SUPPORTED_COMPLEX_TYPE, null)).isTrue(); assertThat(typeConverter.isAppl... |
JsonLikeConverter implements TypeConverter<Object> { int consumeNull(CharSequence value, int current, ObjectBuilder builder, boolean compact) { int found = value.length(); boolean consume = false; if (compact) { if (value.charAt(current) == COMPACT_JSON_NULL.charAt(0)) { if (found != COMPACT_JSON_NULL.length() + curren... | @Test public void shouldProperlyConsumeJsonNullsAndAddNullValuesToBuilder() { boolean compact = false; ObjectBuilder builder = Mockito.mock(ObjectBuilder.class); assertThat(typeConverter.consumeNull(JSON_NULL, 0, builder, compact)).isEqualTo(JSON_NULL.length()); assertThat(typeConverter.consumeNull(JSON_NULL + ',', 0, ... |
ChainedTypeConverter implements TypeConverter<Object> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return converterFor(type, attributes, false) != null; } ChainedTypeConverter(List<TypeConverter<?>> converters); ChainedTypeConverter(T... | @Test public void shouldSupportConvertersFromTheChain() { TypeConverter<?> converter = new ChainedTypeConverter(new StringConverter(false), new IntegerConverter()); assertThat(converter.isApplicable(String.class, null)).isTrue(); assertThat(converter.isApplicable(Integer.class, null)).isTrue(); assertThat(converter.isA... |
ChainedTypeConverter implements TypeConverter<Object> { @Override public Object fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return converterFor(type, attributes).fromString(type, value, attributes); } ChainedTypeConverter(List<TypeConverter<?>> conv... | @Test public void shouldThrowIAEWhenTypeIsNotSupported() { assertThrows(IllegalArgumentException.class, () -> { TypeConverter<Object> converter = new ChainedTypeConverter(new StringConverter()); converter.fromString(Long.class, "10", null); }); } |
FloatConverter extends AbstractNumberConverter<Float> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, Float.class, Float.TYPE); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableWhenFloatType() { Type type = Float.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotFloatType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(type, emptyM... |
UrlConverter implements TypeConverter<URL> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && URL.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type type, Map<String, String> at... | @Test public void shouldBeApplicableWhenUrlType() { Type type = URL.class; boolean applicable = converter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotUrlType() { Type type = Boolean.class; boolean applicable = converter.isApplicable(type, emptyMap());... |
UrlConverter implements TypeConverter<URL> { @Override public String toString(Type type, URL value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return Objects.toString(value, null); } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override URL fromString(... | @Test public void shouldConvertToString() throws MalformedURLException { String urlString = "http: URL toConvert = new URL(urlString); String converted = converter.toString(URL.class, toConvert, emptyMap()); assertThat(converted).isEqualTo(urlString); }
@Test public void shouldReturnNullWhenConvertingToStringAndValueTo... |
UrlConverter implements TypeConverter<URL> { @Override public URL fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { return new URL(value); } catch (MalformedURLException e) { throw new IllegalArgumentException(for... | @Test public void shouldCovertFromString() throws MalformedURLException { String urlInString = "http: URL fromConversion = converter.fromString(URL.class, urlInString, emptyMap()); URL expected = new URL(urlInString); assertThat(fromConversion).isEqualTo(expected); }
@Test public void shouldThrowExceptionWhenMalformedU... |
ShortConverter extends AbstractNumberConverter<Short> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { return isApplicable(type, Short.class, Short.TYPE); } @Override boolean isApplicable(Type type, Map<String, String> attributes); } | @Test public void shouldBeApplicableWhenShortType() { Type type = Short.class; boolean applicable = shortTypeConverter.isApplicable(type, emptyMap()); assertThat(applicable).isTrue(); }
@Test public void shouldNotBeApplicableWhenNotShortType() { Type type = Boolean.class; boolean applicable = shortTypeConverter.isAppli... |
EnumConverter implements TypeConverter<Enum<?>> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class<?> && Enum.class.isAssignableFrom((Class<?>) type); } @Override boolean isApplicable(Type type, Map<String, Stri... | @Test public void shouldAcceptEnumType() { Type type = TestEnum.class; boolean isApplicable = enumTypeAdapter.isApplicable(type, null); assertThat(isApplicable).isTrue(); } |
EnumConverter implements TypeConverter<Enum<?>> { @SuppressWarnings("unchecked") @Override public Enum<?> fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return value == null ? null : toEnumValue((Class<Enum<?>>) type, value); } @Override boolean isApp... | @Test public void shouldConvertFromString() { Enum<?> testEnum = enumTypeAdapter.fromString(TestEnum.class, "FIRST", null); assertThat(testEnum).isEqualTo(TestEnum.FIRST); }
@Test public void shouldThrowExceptionWhenConvertingFromStringAndWrongValue() { String value = "WRONG_VALUE"; assertThatThrownBy(() -> enumTypeAda... |
YamlConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } ca... | @Test void shouldConvertToString() { TestClass toConvert = new TestClass(1, "test-1"); String converted = typeConverter.toString(TestClass.class, toConvert, null); assertThat(converted).isEqualTo("" + "integer: 1\n" + "string: test-1\n"); }
@Test void shouldConvertCollectionToString() { List<TestClass> toConvert = asLi... |
EnumConverter implements TypeConverter<Enum<?>> { @Override public String toString(Type type, Enum<?> value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return value == null ? null : value.name(); } @Override boolean isApplicable(Type type, Map<String, String> attributes); @SuppressW... | @Test public void shouldConvertToString() { String value = enumTypeAdapter.toString(TestEnum.class, TestEnum.SECOND_VALUE, null); assertThat(value).isEqualTo(TestEnum.SECOND_VALUE.name()); } |
ConfigurationValueDecryptingProcessor implements ConfigurationValueProcessor { @Override public ConfigurationValue process(ConfigurationValue value) { requireNonNull(value, "value cannot be null"); if (value.isEncrypted() && Objects.equals(value.getEncryptionProvider(), decrypter.getName())) { String encrypted = value.... | @Test public void decryptUnencryptedValueAndResetProvider() { String encrypted = "encrypted"; String decrypted = "decrypted"; ConfigurationValue value = new ConfigurationValue(null, encrypted, true, Encrypted.DEFAULT, null); processor = new ConfigurationValueDecryptingProcessor(decrypter); when(decrypter.getName()).the... |
JsonConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); String converter = (attributes == null) ? null : attributes.get(CONVERTER); return ignoreConverterAttribute || Objects.equals(converter, JSON); } Js... | @Test void shouldThrowExceptionWhenTypeIsNullAndIsApplicable() { assertThatThrownBy(() -> typeConverter.isApplicable(null, null)) .isExactlyInstanceOf(NullPointerException.class) .hasMessage("type cannot be null"); } |
JsonConverter implements TypeConverter<T> { @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { JavaType javaType = TypeFactory.defaultInstance().constructType(type); ObjectReader objectReader = o... | @Test void shouldConvertFromString() { String toConvert = "" + "{" + " \"integer\": \"10\"," + " \"string\": \"test\"" + "}"; TestClass converted = typeConverter.fromString(TestClass.class, toConvert, null); assertThat(converted).isNotNull(); assertThat(converted.integer).isEqualTo(10); assertThat(converted.string).isE... |
MetaDataExample { public static void main(String[] args) { new MetaDataExample().run(); } static void main(String[] args); } | @Test public void shouldExecuteMainWithoutExceptions() { MetaDataExample.main(new String[0]); } |
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } ca... | @Test void shouldConvertToString() { TestClass toConvert = new TestClass(); toConvert.integer = 10; toConvert.string = "test"; String converted = typeConverter.toString(TestClass.class, toConvert, null); assertThat(converted).isEqualTo("" + "{" + "\"integer\":10," + "\"string\":\"test\"" + "}"); }
@Test void shouldRetu... |
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.com... | @Test public void shouldCreateEmptyKeySet() { KeyGenerator keyGenerator = emptyKeyGenerator(); List<String> configurationKeys = emptyList(); KeyGenerator fallbackKeyPrefixGenerator = emptyKeyGenerator(); List<String> keys = KeySetUtils.keySet(keyGenerator, configurationKeys, fallbackKeyPrefixGenerator, null); assertTha... |
SpringAnnotationBasedExample { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationBasedExample.class)) { context.getBean(SpringAnnotationBasedExample.class).run(); } } static void main(String[] args); } | @Test public void shouldExecuteMainWithoutExceptions() { SpringAnnotationBasedExample.main(new String[0]); } |
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) {... | @Test public void shouldProvidePrefixForSubConfiguration() { List<String> prefixes = extractor.getPrefixes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfiguration")); assertThat(prefixes).containsSequence("subConfiguration"); prefixes = extractor.getPrefixes(TestConfiguration.class, getMethod(T... |
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method) { Class<?> subConfigurationClazz = getSubConfigurationListElementType(configurationType, method); Annotation[] defaultsAnnotations = getDe... | @Test public void shouldProvideDefaultValuesForSubConfigurationList() { List<Map<String, String>> values = extractor.getSubConfigurationListDefaultValues(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfigurations")); assertThat(values).hasSize(2); assertThat(values.get(0)).contains( entry("one", ... |
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method) { if (!isAnnotationDeclaredLocally(method.getReturnType(), DefaultsAnnotation.class)) { return emptyMap(); } Class<?> defaultsAnnotation = findAnnot... | @Test public void shouldProvideDefaultValuesForSubConfiguration() { Map<String, String> values = extractor.getSubConfigurationDefaultValues(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfiguration")); assertThat(values).hasSize(2); assertThat(values).contains( entry("one", "1"), entry("two", "th... |
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override b... | @Test public void shouldProvideAttributesForValueProperty() { Map<String, String> attributes = extractor.attributes(TestConfiguration.class, getMethod(TestConfiguration.class, "getUrl")); assertThat(attributes).containsExactly( entry("custom", "url")); }
@Test public void shouldProvideAttributesForSubConfigurationPrope... |
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); } | @Test public void shouldExtractAttributesFromFixedAnnotation() { Map<String, String> attributes = getMetaAttributes(FixedAttributesUsage.class); assertThat(attributes).containsOnly( entry("one", "value-one"), entry("two", "value-two") ); }
@Test public void shouldExtractAttributesFromFixedAnnotationForMethod() { Map<St... |
SpringExample { public static void main(String[] args) { new SpringExample().run(); } static void main(String[] args); } | @Test public void shouldExecuteMainWithoutExceptions() { SpringExample.main(new String[0]); } |
CoreExample { public static void main(String[] args) { new CoreExample().run(); } static void main(String[] args); } | @Test public void shouldExecuteMainWithoutExceptions() { CoreExample.main(new String[0]); } |
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.... | @Test public void shouldFindPublicAbstractMethodInClass() throws NoSuchMethodException { abstract class TestClass { public abstract int propertyA(); } Collection<Method> methods = methodsProvider.getAllDeclaredMethods(TestClass.class); assertThat(methods).contains(TestClass.class.getMethod("propertyA")); }
@Test public... |
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metada... | @Test public void shouldReturnFromFallbackKey() { when(source.getValue("fallback.p1.p2.key", null)).thenReturn(present("value")); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("value")); }
@Te... |
PropertySourceConfigurationSource implements ConfigurationSource, BeanFactoryAware, EnvironmentAware, InitializingBean { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (PropertySource<?> propertySource : flattenedPropertySourc... | @Test public void shouldResolvePropertyPlaceholdersSetWithCorrectOrder() { assertThat(source.getValue("property.only.in.A", null)).isEqualTo(present("A")); assertThat(source.getValue("property.only.in.B", null)).isEqualTo(present("B")); assertThat(source.getValue("property.in.A.and.B", null)).isEqualTo(present("B")); } |
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String>... | @Test public void shouldReturnNullWhenPropertiesAreNull() { Map<String, String> properties = null; Map<String, String> attributes = attributes(properties); assertThat(attributes).isNull(); }
@Test public void shouldConstructFromMap() { Map<String, String> properties = MapUtils.of("key1", "val1", "key2", "val2"); Map<St... |
AttributesUtils implements Serializable { public static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child) { if (parent == null) { return getCached(child, true); } if (child == null) { return getCached(parent, true); } Map<String, String> merged = new LinkedHashMap<>(parent.size(... | @Test public void shouldMergeToNullWhenBothAreNull() { Map<String, String> merged = mergeAttributes(null, null); assertThat(merged).isNull(); } |
CachingTypeConverter implements TypeConverter<T>, InitializingBean { @SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = ca... | @Test public void shouldIntegrateWithSpring() { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class)) { TypeConverter<?> typeConverter = context.getBean(TypeConverter.class); assertThat(typeConverter).isInstanceOf(CachingTypeConverter.class); Long val = (Lo... |
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getRe... | @Test public void shouldGetProperties() { Bean bean = new Bean(); assertThat(getProperty(bean, "intValue")).isEqualTo(0); assertThat(getProperty(bean, "stringValue")).isNull(); assertThat(getProperty(bean, "beanValue")).isNull(); bean.setIntValue(1); assertThat(getProperty(bean, "intValue")).isEqualTo(bean.getIntValue(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.