Refactor AssertJ assertions into more idiomatic ones
This commit refactors some AssertJ assertions into more idiomatic and readable ones. Using the dedicated assertion instead of a generic one will produce more meaningful error messages. For instance, consider collection size: ``` // expected: 5 but was: 2 assertThat(collection.size()).equals(5); // Expected size: 5 but was: 2 in: [1, 2] assertThat(collection).hasSize(5); ``` Closes gh-30104
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -95,7 +95,7 @@ class SimpleTypeReferenceTests {
|
||||
void typeReferenceInRootPackage() {
|
||||
TypeReference type = SimpleTypeReference.of("MyRootClass");
|
||||
assertThat(type.getCanonicalName()).isEqualTo("MyRootClass");
|
||||
assertThat(type.getPackageName()).isEqualTo("");
|
||||
assertThat(type.getPackageName()).isEmpty();
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,7 +46,7 @@ class ConstantsTests {
|
||||
assertThatExceptionOfType(Constants.ConstantException.class).isThrownBy(() ->
|
||||
c.asNumber("bogus"));
|
||||
|
||||
assertThat(c.asString("S1").equals(A.S1)).isTrue();
|
||||
assertThat(c.asString("S1")).isEqualTo(A.S1);
|
||||
assertThatExceptionOfType(Constants.ConstantException.class).as("wrong type").isThrownBy(() ->
|
||||
c.asNumber("S1"));
|
||||
}
|
||||
@@ -194,21 +194,21 @@ class ConstantsTests {
|
||||
void getValuesWithNullPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set<?> values = c.getValues(null);
|
||||
assertThat(values.size()).as("Must have returned *all* public static final values").isEqualTo(7);
|
||||
assertThat(values).as("Must have returned *all* public static final values").hasSize(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getValuesWithEmptyStringPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set<Object> values = c.getValues("");
|
||||
assertThat(values.size()).as("Must have returned *all* public static final values").isEqualTo(7);
|
||||
assertThat(values).as("Must have returned *all* public static final values").hasSize(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getValuesWithWhitespacedStringPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set<?> values = c.getValues(" ");
|
||||
assertThat(values.size()).as("Must have returned *all* public static final values").isEqualTo(7);
|
||||
assertThat(values).as("Must have returned *all* public static final values").hasSize(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method getName = TestObject.class.getMethod("getName");
|
||||
String[] names = discoverer.getParameterNames(getName);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("no argument names").isEqualTo(0);
|
||||
assertThat(names).as("no argument names").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,7 +51,7 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method setName = TestObject.class.getMethod("setName", String.class);
|
||||
String[] names = discoverer.getParameterNames(setName);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("one argument").isEqualTo(1);
|
||||
assertThat(names).as("one argument").hasSize(1);
|
||||
assertThat(names[0]).isEqualTo("name");
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Constructor<TestObject> noArgsCons = TestObject.class.getConstructor();
|
||||
String[] names = discoverer.getParameterNames(noArgsCons);
|
||||
assertThat(names).as("should find cons info").isNotNull();
|
||||
assertThat(names.length).as("no argument names").isEqualTo(0);
|
||||
assertThat(names).as("no argument names").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Constructor<TestObject> twoArgCons = TestObject.class.getConstructor(String.class, int.class);
|
||||
String[] names = discoverer.getParameterNames(twoArgCons);
|
||||
assertThat(names).as("should find cons info").isNotNull();
|
||||
assertThat(names.length).as("one argument").isEqualTo(2);
|
||||
assertThat(names).as("one argument").hasSize(2);
|
||||
assertThat(names[0]).isEqualTo("name");
|
||||
assertThat(names[1]).isEqualTo("age");
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method m = getClass().getMethod("staticMethodNoLocalVars");
|
||||
String[] names = discoverer.getParameterNames(m);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("no argument names").isEqualTo(0);
|
||||
assertThat(names).as("no argument names").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,14 +88,14 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method m1 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE);
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("two arguments").isEqualTo(2);
|
||||
assertThat(names).as("two arguments").hasSize(2);
|
||||
assertThat(names[0]).isEqualTo("x");
|
||||
assertThat(names[1]).isEqualTo("y");
|
||||
|
||||
Method m2 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE, Long.TYPE);
|
||||
names = discoverer.getParameterNames(m2);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("three arguments").isEqualTo(3);
|
||||
assertThat(names).as("three arguments").hasSize(3);
|
||||
assertThat(names[0]).isEqualTo("x");
|
||||
assertThat(names[1]).isEqualTo("y");
|
||||
assertThat(names[2]).isEqualTo("z");
|
||||
@@ -108,13 +108,13 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method m1 = clazz.getMethod("staticMethod", Long.TYPE);
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("one argument").isEqualTo(1);
|
||||
assertThat(names).as("one argument").hasSize(1);
|
||||
assertThat(names[0]).isEqualTo("x");
|
||||
|
||||
Method m2 = clazz.getMethod("staticMethod", Long.TYPE, Long.TYPE);
|
||||
names = discoverer.getParameterNames(m2);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("two arguments").isEqualTo(2);
|
||||
assertThat(names).as("two arguments").hasSize(2);
|
||||
assertThat(names[0]).isEqualTo("x");
|
||||
assertThat(names[1]).isEqualTo("y");
|
||||
}
|
||||
@@ -126,14 +126,14 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method m1 = clazz.getMethod("instanceMethod", Double.TYPE, Double.TYPE);
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("two arguments").isEqualTo(2);
|
||||
assertThat(names).as("two arguments").hasSize(2);
|
||||
assertThat(names[0]).isEqualTo("x");
|
||||
assertThat(names[1]).isEqualTo("y");
|
||||
|
||||
Method m2 = clazz.getMethod("instanceMethod", Double.TYPE, Double.TYPE, Double.TYPE);
|
||||
names = discoverer.getParameterNames(m2);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("three arguments").isEqualTo(3);
|
||||
assertThat(names).as("three arguments").hasSize(3);
|
||||
assertThat(names[0]).isEqualTo("x");
|
||||
assertThat(names[1]).isEqualTo("y");
|
||||
assertThat(names[2]).isEqualTo("z");
|
||||
@@ -146,13 +146,13 @@ class LocalVariableTableParameterNameDiscovererTests {
|
||||
Method m1 = clazz.getMethod("instanceMethod", String.class);
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("one argument").isEqualTo(1);
|
||||
assertThat(names).as("one argument").hasSize(1);
|
||||
assertThat(names[0]).isEqualTo("aa");
|
||||
|
||||
Method m2 = clazz.getMethod("instanceMethod", String.class, String.class);
|
||||
names = discoverer.getParameterNames(m2);
|
||||
assertThat(names).as("should find method info").isNotNull();
|
||||
assertThat(names.length).as("two arguments").isEqualTo(2);
|
||||
assertThat(names).as("two arguments").hasSize(2);
|
||||
assertThat(names[0]).isEqualTo("aa");
|
||||
assertThat(names[1]).isEqualTo("bb");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,7 +100,7 @@ class ReactiveAdapterRegistryTests {
|
||||
List<Integer> sequence = Arrays.asList(1, 2, 3);
|
||||
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence);
|
||||
Object target = getAdapter(Flux.class).fromPublisher(source);
|
||||
assertThat(target instanceof Flux).isTrue();
|
||||
assertThat(target).isInstanceOf(Flux.class);
|
||||
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class ReactiveAdapterRegistryTests {
|
||||
void toMono() {
|
||||
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromArray(1, 2, 3);
|
||||
Object target = getAdapter(Mono.class).fromPublisher(source);
|
||||
assertThat(target instanceof Mono).isTrue();
|
||||
assertThat(target).isInstanceOf(Mono.class);
|
||||
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class ReactiveAdapterRegistryTests {
|
||||
void toCompletableFuture() throws Exception {
|
||||
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3});
|
||||
Object target = getAdapter(CompletableFuture.class).fromPublisher(source);
|
||||
assertThat(target instanceof CompletableFuture).isTrue();
|
||||
assertThat(target).isInstanceOf(CompletableFuture.class);
|
||||
assertThat(((CompletableFuture<Integer>) target).get()).isEqualTo(Integer.valueOf(1));
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ class ReactiveAdapterRegistryTests {
|
||||
CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
future.complete(1);
|
||||
Object target = getAdapter(CompletableFuture.class).toPublisher(future);
|
||||
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue();
|
||||
assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class);
|
||||
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class ReactiveAdapterRegistryTests {
|
||||
List<Integer> sequence = Arrays.asList(1, 2, 3);
|
||||
Publisher<Integer> source = Flux.fromIterable(sequence);
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Flowable.class).fromPublisher(source);
|
||||
assertThat(target instanceof io.reactivex.rxjava3.core.Flowable).isTrue();
|
||||
assertThat(target).isInstanceOf(io.reactivex.rxjava3.core.Flowable.class);
|
||||
assertThat(((io.reactivex.rxjava3.core.Flowable<?>) target).toList().blockingGet()).isEqualTo(sequence);
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ class ReactiveAdapterRegistryTests {
|
||||
List<Integer> sequence = Arrays.asList(1, 2, 3);
|
||||
Publisher<Integer> source = Flux.fromIterable(sequence);
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Observable.class).fromPublisher(source);
|
||||
assertThat(target instanceof io.reactivex.rxjava3.core.Observable).isTrue();
|
||||
assertThat(target).isInstanceOf(io.reactivex.rxjava3.core.Observable.class);
|
||||
assertThat(((io.reactivex.rxjava3.core.Observable<?>) target).toList().blockingGet()).isEqualTo(sequence);
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ class ReactiveAdapterRegistryTests {
|
||||
void toSingle() {
|
||||
Publisher<Integer> source = Flux.fromArray(new Integer[] {1});
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Single.class).fromPublisher(source);
|
||||
assertThat(target instanceof io.reactivex.rxjava3.core.Single).isTrue();
|
||||
assertThat(target).isInstanceOf(io.reactivex.rxjava3.core.Single.class);
|
||||
assertThat(((io.reactivex.rxjava3.core.Single<Integer>) target).blockingGet()).isEqualTo(Integer.valueOf(1));
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ class ReactiveAdapterRegistryTests {
|
||||
void toCompletable() {
|
||||
Publisher<Integer> source = Flux.fromArray(new Integer[] {1, 2, 3});
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Completable.class).fromPublisher(source);
|
||||
assertThat(target instanceof io.reactivex.rxjava3.core.Completable).isTrue();
|
||||
assertThat(target).isInstanceOf(io.reactivex.rxjava3.core.Completable.class);
|
||||
((io.reactivex.rxjava3.core.Completable) target).blockingAwait();
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ class ReactiveAdapterRegistryTests {
|
||||
List<Integer> sequence = Arrays.asList(1, 2, 3);
|
||||
Object source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence);
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Flowable.class).toPublisher(source);
|
||||
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue();
|
||||
assertThat(target).as("Expected Flux Publisher: " + target.getClass().getName()).isInstanceOf(Flux.class);
|
||||
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class ReactiveAdapterRegistryTests {
|
||||
List<Integer> sequence = Arrays.asList(1, 2, 3);
|
||||
Object source = io.reactivex.rxjava3.core.Observable.fromIterable(sequence);
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Observable.class).toPublisher(source);
|
||||
assertThat(target instanceof Flux).as("Expected Flux Publisher: " + target.getClass().getName()).isTrue();
|
||||
assertThat(target).as("Expected Flux Publisher: " + target.getClass().getName()).isInstanceOf(Flux.class);
|
||||
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ class ReactiveAdapterRegistryTests {
|
||||
void fromSingle() {
|
||||
Object source = io.reactivex.rxjava3.core.Single.just(1);
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Single.class).toPublisher(source);
|
||||
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue();
|
||||
assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class);
|
||||
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ class ReactiveAdapterRegistryTests {
|
||||
void fromCompletable() {
|
||||
Object source = io.reactivex.rxjava3.core.Completable.complete();
|
||||
Object target = getAdapter(io.reactivex.rxjava3.core.Completable.class).toPublisher(source);
|
||||
assertThat(target instanceof Mono).as("Expected Mono Publisher: " + target.getClass().getName()).isTrue();
|
||||
assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class);
|
||||
((Mono<Void>) target).block(ONE_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,8 +41,8 @@ class AnnotationAwareOrderComparatorTests {
|
||||
list.add(new B());
|
||||
list.add(new A());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list.get(0) instanceof A).isTrue();
|
||||
assertThat(list.get(1) instanceof B).isTrue();
|
||||
assertThat(list.get(0)).isInstanceOf(A.class);
|
||||
assertThat(list.get(1)).isInstanceOf(B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,8 +51,8 @@ class AnnotationAwareOrderComparatorTests {
|
||||
list.add(new B2());
|
||||
list.add(new A2());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list.get(0) instanceof A2).isTrue();
|
||||
assertThat(list.get(1) instanceof B2).isTrue();
|
||||
assertThat(list.get(0)).isInstanceOf(A2.class);
|
||||
assertThat(list.get(1)).isInstanceOf(B2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,8 +61,8 @@ class AnnotationAwareOrderComparatorTests {
|
||||
list.add(new B());
|
||||
list.add(new A2());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list.get(0) instanceof A2).isTrue();
|
||||
assertThat(list.get(1) instanceof B).isTrue();
|
||||
assertThat(list.get(0)).isInstanceOf(A2.class);
|
||||
assertThat(list.get(1)).isInstanceOf(B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,8 +71,8 @@ class AnnotationAwareOrderComparatorTests {
|
||||
list.add(new B());
|
||||
list.add(new C());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list.get(0) instanceof C).isTrue();
|
||||
assertThat(list.get(1) instanceof B).isTrue();
|
||||
assertThat(list.get(0)).isInstanceOf(C.class);
|
||||
assertThat(list.get(1)).isInstanceOf(B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -563,7 +563,7 @@ class AnnotationUtilsTests {
|
||||
|
||||
Set<ContextConfig> annotations = getRepeatableAnnotations(ConfigHierarchyTestCase.class, ContextConfig.class, null);
|
||||
assertThat(annotations).isNotNull();
|
||||
assertThat(annotations.size()).as("size if container type is omitted: ").isEqualTo(0);
|
||||
assertThat(annotations).as("size if container type is omitted: ").isEmpty();
|
||||
|
||||
annotations = getRepeatableAnnotations(ConfigHierarchyTestCase.class, ContextConfig.class, Hierarchy.class);
|
||||
assertThat(annotations).isNotNull();
|
||||
@@ -855,8 +855,8 @@ class AnnotationUtilsTests {
|
||||
void synthesizeAnnotationFromDefaultsWithAttributeAliases() throws Exception {
|
||||
ContextConfig contextConfig = synthesizeAnnotation(ContextConfig.class);
|
||||
assertThat(contextConfig).isNotNull();
|
||||
assertThat(contextConfig.value()).as("value: ").isEqualTo("");
|
||||
assertThat(contextConfig.location()).as("location: ").isEqualTo("");
|
||||
assertThat(contextConfig.value()).as("value: ").isEmpty();
|
||||
assertThat(contextConfig.location()).as("location: ").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1923,8 +1923,8 @@ class MergedAnnotationsTests {
|
||||
MergedAnnotation<TestConfiguration> annotation = MergedAnnotation.of(
|
||||
TestConfiguration.class);
|
||||
TestConfiguration synthesized = annotation.synthesize();
|
||||
assertThat(synthesized.value()).isEqualTo("");
|
||||
assertThat(synthesized.location()).isEqualTo("");
|
||||
assertThat(synthesized.value()).isEmpty();
|
||||
assertThat(synthesized.location()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,7 +65,7 @@ class TypeMappedAnnotationTests {
|
||||
WithConventionAliasToMetaAnnotation.class,
|
||||
ConventionAliasToMetaAnnotation.class,
|
||||
ConventionAliasMetaAnnotationTarget.class);
|
||||
assertThat(annotation.getString("value")).isEqualTo("");
|
||||
assertThat(annotation.getString("value")).isEmpty();
|
||||
assertThat(annotation.getString("convention")).isEqualTo("convention");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,7 +82,8 @@ class CharSequenceEncoderTests extends AbstractEncoderTests<CharSequenceEncoder>
|
||||
.forEach(charset -> {
|
||||
int capacity = this.encoder.calculateCapacity(sequence, charset);
|
||||
int length = sequence.length();
|
||||
assertThat(capacity >= length).as(String.format("%s has capacity %d; length %d", charset, capacity, length)).isTrue();
|
||||
assertThat(capacity).as(String.format("%s has capacity %d; length %d", charset, capacity, length))
|
||||
.isGreaterThanOrEqualTo(length);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,7 +77,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(String.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.lang.String");
|
||||
assertThat(desc.toString()).isEqualTo("java.lang.String");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isFalse();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -92,7 +92,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(List.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.List");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.List<java.util.List<java.util.Map<java.lang.Integer, java.lang.Enum<?>>>>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isTrue();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -113,7 +113,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(List.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.List");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.List<?>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isTrue();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -129,7 +129,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(Integer[].class);
|
||||
assertThat(desc.getName()).isEqualTo("java.lang.Integer[]");
|
||||
assertThat(desc.toString()).isEqualTo("java.lang.Integer[]");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isFalse();
|
||||
assertThat(desc.isArray()).isTrue();
|
||||
@@ -146,7 +146,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(Map.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.Map");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.Map<java.lang.Integer, java.util.List<java.lang.String>>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isFalse();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -462,7 +462,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(List.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.List");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.List<java.lang.Integer>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isTrue();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -478,7 +478,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(List.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.List");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.List<java.util.List<java.lang.Integer>>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isTrue();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -494,7 +494,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(Map.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.Map");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.Map<java.lang.String, java.lang.Integer>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isFalse();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -511,7 +511,7 @@ class TypeDescriptorTests {
|
||||
assertThat(desc.getObjectType()).isEqualTo(Map.class);
|
||||
assertThat(desc.getName()).isEqualTo("java.util.Map");
|
||||
assertThat(desc.toString()).isEqualTo("java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Integer>>");
|
||||
assertThat(!desc.isPrimitive()).isTrue();
|
||||
assertThat(desc.isPrimitive()).isFalse();
|
||||
assertThat(desc.getAnnotations()).isEmpty();
|
||||
assertThat(desc.isCollection()).isFalse();
|
||||
assertThat(desc.isArray()).isFalse();
|
||||
@@ -668,7 +668,7 @@ class TypeDescriptorTests {
|
||||
getClass().getMethod("setProperty", Map.class));
|
||||
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
|
||||
TypeDescriptor upCast = typeDescriptor.upcast(Object.class);
|
||||
assertThat(upCast.getAnnotation(MethodAnnotation1.class) != null).isTrue();
|
||||
assertThat(upCast.getAnnotation(MethodAnnotation1.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -402,7 +402,7 @@ class DefaultConversionServiceTests {
|
||||
@Test
|
||||
void convertEmptyArrayToString() {
|
||||
String result = conversionService.convert(new String[0], String.class);
|
||||
assertThat(result).isEqualTo("");
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -739,8 +739,8 @@ class DefaultConversionServiceTests {
|
||||
foo.setProperty("1", "BAR");
|
||||
foo.setProperty("2", "BAZ");
|
||||
String result = conversionService.convert(foo, String.class);
|
||||
assertThat(result.contains("1=BAR")).isTrue();
|
||||
assertThat(result.contains("2=BAZ")).isTrue();
|
||||
assertThat(result).contains("1=BAR");
|
||||
assertThat(result).contains("2=BAZ");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -749,7 +749,7 @@ class DefaultConversionServiceTests {
|
||||
assertThat(result).hasSize(3);
|
||||
assertThat(result.getProperty("a")).isEqualTo("b");
|
||||
assertThat(result.getProperty("c")).isEqualTo("2");
|
||||
assertThat(result.getProperty("d")).isEqualTo("");
|
||||
assertThat(result.getProperty("d")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -811,7 +811,7 @@ class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void convertObjectToStringWithJavaTimeOfMethodPresent() {
|
||||
assertThat(conversionService.convert(ZoneId.of("GMT+1"), String.class).startsWith("GMT+")).isTrue();
|
||||
assertThat(conversionService.convert(ZoneId.of("GMT+1"), String.class)).startsWith("GMT+");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -895,7 +895,7 @@ class DefaultConversionServiceTests {
|
||||
TypeDescriptor descriptor = new TypeDescriptor(parameter);
|
||||
Object actual = conversionService.convert("1,2,3", TypeDescriptor.valueOf(String.class), descriptor);
|
||||
assertThat(actual.getClass()).isEqualTo(Optional.class);
|
||||
assertThat(((Optional<List<Integer>>) actual).get()).isEqualTo(List.of(1, 2, 3));
|
||||
assertThat(((Optional<List<Integer>>) actual)).contains(List.of(1, 2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -195,7 +195,7 @@ class CollectionToCollectionConverterTests {
|
||||
aSource, TypeDescriptor.forObject(aSource), TypeDescriptor.forObject(new ArrayList()));
|
||||
boolean condition = myConverted instanceof ArrayList<?>;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(((ArrayList<?>) myConverted)).hasSize(aSource.size());
|
||||
assertThat(((ArrayList<?>) myConverted)).hasSameSizeAs(aSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -131,8 +131,8 @@ class GenericConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void convertAssignableSource() {
|
||||
assertThat(conversionService.convert(false, boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
assertThat(conversionService.convert(false, Boolean.class)).isEqualTo(Boolean.FALSE);
|
||||
assertThat(conversionService.convert(false, boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert(false, Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -387,7 +387,7 @@ class GenericConversionServiceTests {
|
||||
GenericConverter.ConvertiblePair pair = new GenericConverter.ConvertiblePair(Number.class, String.class);
|
||||
GenericConverter.ConvertiblePair pairOpposite = new GenericConverter.ConvertiblePair(String.class, Number.class);
|
||||
assertThat(pair.equals(pairOpposite)).isFalse();
|
||||
assertThat(pair.hashCode() == pairOpposite.hashCode()).isFalse();
|
||||
assertThat(pair.hashCode()).isNotEqualTo(pairOpposite.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -416,7 +416,7 @@ class GenericConversionServiceTests {
|
||||
conversionService.addConverter(new ColorConverter());
|
||||
conversionService.addConverter(converter);
|
||||
assertThat(conversionService.convert("#000000", Color.class)).isEqualTo(Color.BLACK);
|
||||
assertThat(converter.getMatchAttempts() > 0).isTrue();
|
||||
assertThat(converter.getMatchAttempts()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -425,8 +425,8 @@ class GenericConversionServiceTests {
|
||||
conversionService.addConverter(new ColorConverter());
|
||||
conversionService.addConverterFactory(converter);
|
||||
assertThat(conversionService.convert("#000000", Color.class)).isEqualTo(Color.BLACK);
|
||||
assertThat(converter.getMatchAttempts() > 0).isTrue();
|
||||
assertThat(converter.getNestedMatchAttempts() > 0).isTrue();
|
||||
assertThat(converter.getMatchAttempts()).isGreaterThan(0);
|
||||
assertThat(converter.getNestedMatchAttempts()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -457,7 +457,7 @@ class GenericConversionServiceTests {
|
||||
MyConditionalGenericConverter converter = new MyConditionalGenericConverter();
|
||||
conversionService.addConverter(converter);
|
||||
assertThat(conversionService.convert(3, Integer.class)).isEqualTo(3);
|
||||
assertThat(converter.getSourceTypes().size()).isGreaterThan(2);
|
||||
assertThat(converter.getSourceTypes()).hasSizeGreaterThan(2);
|
||||
assertThat(converter.getSourceTypes().stream().allMatch(td -> Integer.class.equals(td.getType()))).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,7 +65,7 @@ class MapToMapConverterTests {
|
||||
conversionService.convert(map, sourceType, targetType);
|
||||
}
|
||||
catch (ConversionFailedException ex) {
|
||||
assertThat(ex.getCause() instanceof ConverterNotFoundException).isTrue();
|
||||
assertThat(ex.getCause()).isInstanceOf(ConverterNotFoundException.class);
|
||||
}
|
||||
|
||||
conversionService.addConverterFactory(new StringToNumberConverterFactory());
|
||||
@@ -100,7 +100,7 @@ class MapToMapConverterTests {
|
||||
conversionService.convert(map, sourceType, targetType);
|
||||
}
|
||||
catch (ConversionFailedException ex) {
|
||||
assertThat(ex.getCause() instanceof ConverterNotFoundException).isTrue();
|
||||
assertThat(ex.getCause()).isInstanceOf(ConverterNotFoundException.class);
|
||||
}
|
||||
|
||||
conversionService.addConverterFactory(new StringToNumberConverterFactory());
|
||||
@@ -125,7 +125,7 @@ class MapToMapConverterTests {
|
||||
conversionService.convert(map, sourceType, targetType);
|
||||
}
|
||||
catch (ConversionFailedException ex) {
|
||||
assertThat(ex.getCause() instanceof ConverterNotFoundException).isTrue();
|
||||
assertThat(ex.getCause()).isInstanceOf(ConverterNotFoundException.class);
|
||||
}
|
||||
|
||||
conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,7 +57,7 @@ class SimpleCommandLinePropertySourceTests {
|
||||
assertThat(ps.containsProperty("o2")).isTrue();
|
||||
assertThat(ps.containsProperty("o3")).isFalse();
|
||||
assertThat(ps.getProperty("o1")).isEqualTo("v1");
|
||||
assertThat(ps.getProperty("o2")).isEqualTo("");
|
||||
assertThat(ps.getProperty("o2")).isEmpty();
|
||||
assertThat(ps.getProperty("o3")).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,14 +53,14 @@ class ResourceEditorTests {
|
||||
void setAndGetAsTextWithNull() {
|
||||
PropertyEditor editor = new ResourceEditor();
|
||||
editor.setAsText(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAndGetAsTextWithWhitespaceResource() {
|
||||
PropertyEditor editor = new ResourceEditor();
|
||||
editor.setAsText(" ");
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -393,7 +393,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
|
||||
assertThat(buffer.capacity()).isEqualTo(1);
|
||||
buffer.write((byte) 'b');
|
||||
|
||||
assertThat(buffer.capacity() > 1).isTrue();
|
||||
assertThat(buffer.capacity()).isGreaterThan(1);
|
||||
|
||||
release(buffer);
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ class AnnotationMetadataTests {
|
||||
assertThat(specialAttrs.getEnum("state").equals(Thread.State.NEW)).isTrue();
|
||||
|
||||
AnnotationAttributes nestedAnno = specialAttrs.getAnnotation("nestedAnno");
|
||||
assertThat("na").isEqualTo(nestedAnno.getString("value"));
|
||||
assertThat(nestedAnno.getString("value")).isEqualTo("na");
|
||||
assertThat(nestedAnno.getEnum("anEnum").equals(SomeEnum.LABEL1)).isTrue();
|
||||
assertThat((Class<?>[]) nestedAnno.get("classArray")).isEqualTo(new Class<?>[] {String.class});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,7 @@ public abstract class MockitoUtils {
|
||||
private static void verifySameInvocations(List<Invocation> expectedInvocations, List<Invocation> actualInvocations,
|
||||
InvocationArgumentsAdapter... argumentAdapters) {
|
||||
|
||||
assertThat(expectedInvocations).hasSize(actualInvocations.size());
|
||||
assertThat(expectedInvocations).hasSameSizeAs(actualInvocations);
|
||||
for (int i = 0; i < expectedInvocations.size(); i++) {
|
||||
verifySameInvocation(expectedInvocations.get(i), actualInvocations.get(i), argumentAdapters);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -300,7 +300,7 @@ class AntPathMatcherTests {
|
||||
|
||||
@Test
|
||||
void extractPathWithinPattern() throws Exception {
|
||||
assertThat(pathMatcher.extractPathWithinPattern("/docs/commit.html", "/docs/commit.html")).isEqualTo("");
|
||||
assertThat(pathMatcher.extractPathWithinPattern("/docs/commit.html", "/docs/commit.html")).isEmpty();
|
||||
|
||||
assertThat(pathMatcher.extractPathWithinPattern("/docs/*", "/docs/cvs/commit")).isEqualTo("cvs/commit");
|
||||
assertThat(pathMatcher.extractPathWithinPattern("/docs/cvs/*.html", "/docs/cvs/commit.html")).isEqualTo("commit.html");
|
||||
@@ -410,7 +410,7 @@ class AntPathMatcherTests {
|
||||
|
||||
@Test
|
||||
void combine() {
|
||||
assertThat(pathMatcher.combine(null, null)).isEqualTo("");
|
||||
assertThat(pathMatcher.combine(null, null)).isEmpty();
|
||||
assertThat(pathMatcher.combine("/hotels", null)).isEqualTo("/hotels");
|
||||
assertThat(pathMatcher.combine(null, "/hotels")).isEqualTo("/hotels");
|
||||
assertThat(pathMatcher.combine("/hotels/*", "booking")).isEqualTo("/hotels/booking");
|
||||
@@ -622,7 +622,7 @@ class AntPathMatcherTests {
|
||||
@Test
|
||||
void defaultCacheSetting() {
|
||||
match();
|
||||
assertThat(pathMatcher.stringMatcherCache.size() > 20).isTrue();
|
||||
assertThat(pathMatcher.stringMatcherCache).hasSizeGreaterThan(20);
|
||||
|
||||
for (int i = 0; i < 65536; i++) {
|
||||
pathMatcher.match("test" + i, "test");
|
||||
@@ -635,13 +635,13 @@ class AntPathMatcherTests {
|
||||
void cachePatternsSetToTrue() {
|
||||
pathMatcher.setCachePatterns(true);
|
||||
match();
|
||||
assertThat(pathMatcher.stringMatcherCache.size() > 20).isTrue();
|
||||
assertThat(pathMatcher.stringMatcherCache).hasSizeGreaterThan(20);
|
||||
|
||||
for (int i = 0; i < 65536; i++) {
|
||||
pathMatcher.match("test" + i, "test" + i);
|
||||
}
|
||||
// Cache keeps being alive due to the explicit cache setting
|
||||
assertThat(pathMatcher.stringMatcherCache.size() > 65536).isTrue();
|
||||
assertThat(pathMatcher.stringMatcherCache).hasSizeGreaterThan(65536);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -334,7 +334,7 @@ class ClassUtilsTests {
|
||||
void getAllInterfaces() {
|
||||
DerivedTestObject testBean = new DerivedTestObject();
|
||||
List<Class<?>> ifcs = Arrays.asList(ClassUtils.getAllInterfaces(testBean));
|
||||
assertThat(ifcs.size()).as("Correct number of interfaces").isEqualTo(4);
|
||||
assertThat(ifcs).as("Correct number of interfaces").hasSize(4);
|
||||
assertThat(ifcs.contains(Serializable.class)).as("Contains Serializable").isTrue();
|
||||
assertThat(ifcs.contains(ITestObject.class)).as("Contains ITestBean").isTrue();
|
||||
assertThat(ifcs.contains(ITestInterface.class)).as("Contains IOther").isTrue();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,17 +39,17 @@ class FileSystemUtilsTests {
|
||||
File bar = new File(child, "bar.txt");
|
||||
bar.createNewFile();
|
||||
|
||||
assertThat(root.exists()).isTrue();
|
||||
assertThat(child.exists()).isTrue();
|
||||
assertThat(grandchild.exists()).isTrue();
|
||||
assertThat(bar.exists()).isTrue();
|
||||
assertThat(root).exists();
|
||||
assertThat(child).exists();
|
||||
assertThat(grandchild).exists();
|
||||
assertThat(bar).exists();
|
||||
|
||||
FileSystemUtils.deleteRecursively(root);
|
||||
|
||||
assertThat(root.exists()).isFalse();
|
||||
assertThat(child.exists()).isFalse();
|
||||
assertThat(grandchild.exists()).isFalse();
|
||||
assertThat(bar.exists()).isFalse();
|
||||
assertThat(root).doesNotExist();
|
||||
assertThat(child).doesNotExist();
|
||||
assertThat(grandchild).doesNotExist();
|
||||
assertThat(bar).doesNotExist();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,19 +63,19 @@ class FileSystemUtilsTests {
|
||||
File bar = new File(child, "bar.txt");
|
||||
bar.createNewFile();
|
||||
|
||||
assertThat(src.exists()).isTrue();
|
||||
assertThat(child.exists()).isTrue();
|
||||
assertThat(grandchild.exists()).isTrue();
|
||||
assertThat(bar.exists()).isTrue();
|
||||
assertThat(src).exists();
|
||||
assertThat(child).exists();
|
||||
assertThat(grandchild).exists();
|
||||
assertThat(bar).exists();
|
||||
|
||||
File dest = new File("./dest");
|
||||
FileSystemUtils.copyRecursively(src, dest);
|
||||
|
||||
assertThat(dest.exists()).isTrue();
|
||||
assertThat(new File(dest, child.getName()).exists()).isTrue();
|
||||
assertThat(dest).exists();
|
||||
assertThat(new File(dest, child.getName())).exists();
|
||||
|
||||
FileSystemUtils.deleteRecursively(src);
|
||||
assertThat(src.exists()).isFalse();
|
||||
assertThat(src).doesNotExist();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -297,18 +297,18 @@ class MimeTypeTests {
|
||||
String s = "text/plain, text/html, text/x-dvi, text/x-c";
|
||||
List<MimeType> mimeTypes = MimeTypeUtils.parseMimeTypes(s);
|
||||
assertThat(mimeTypes).as("No mime types returned").isNotNull();
|
||||
assertThat(mimeTypes.size()).as("Invalid amount of mime types").isEqualTo(4);
|
||||
assertThat(mimeTypes).as("Invalid amount of mime types").hasSize(4);
|
||||
|
||||
mimeTypes = MimeTypeUtils.parseMimeTypes(null);
|
||||
assertThat(mimeTypes).as("No mime types returned").isNotNull();
|
||||
assertThat(mimeTypes.size()).as("Invalid amount of mime types").isEqualTo(0);
|
||||
assertThat(mimeTypes).as("Invalid amount of mime types").isEmpty();
|
||||
}
|
||||
|
||||
@Test // gh-23241
|
||||
void parseMimeTypesWithTrailingComma() {
|
||||
List<MimeType> mimeTypes = MimeTypeUtils.parseMimeTypes("text/plain, text/html,");
|
||||
assertThat(mimeTypes).as("No mime types returned").isNotNull();
|
||||
assertThat(mimeTypes.size()).as("Incorrect number of mime types").isEqualTo(2);
|
||||
assertThat(mimeTypes).as("Incorrect number of mime types").hasSize(2);
|
||||
}
|
||||
|
||||
@Test // SPR-17459
|
||||
@@ -328,7 +328,7 @@ class MimeTypeTests {
|
||||
type = new MimeType("application", "vdn.something");
|
||||
assertThat(type.getSubtypeSuffix()).isNull();
|
||||
type = new MimeType("application", "vdn.something+");
|
||||
assertThat(type.getSubtypeSuffix()).isEqualTo("");
|
||||
assertThat(type.getSubtypeSuffix()).isEmpty();
|
||||
type = new MimeType("application", "vdn.some+thing+json");
|
||||
assertThat(type.getSubtypeSuffix()).isEqualTo("json");
|
||||
}
|
||||
@@ -344,7 +344,7 @@ class MimeTypeTests {
|
||||
String s = String.join(",", mimeTypes);
|
||||
List<MimeType> actual = MimeTypeUtils.parseMimeTypes(s);
|
||||
|
||||
assertThat(actual).hasSize(mimeTypes.length);
|
||||
assertThat(actual).hasSameSizeAs(mimeTypes);
|
||||
for (int i = 0; i < mimeTypes.length; i++) {
|
||||
assertThat(actual.get(i).toString()).isEqualTo(mimeTypes[i]);
|
||||
}
|
||||
@@ -362,7 +362,7 @@ class MimeTypeTests {
|
||||
assertThat(audio.compareTo(audio)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(audioBasicLevel.compareTo(audioBasicLevel)).as("Invalid comparison result").isEqualTo(0);
|
||||
|
||||
assertThat(audioBasicLevel.compareTo(audio) > 0).as("Invalid comparison result").isTrue();
|
||||
assertThat(audioBasicLevel.compareTo(audio)).as("Invalid comparison result").isGreaterThan(0);
|
||||
|
||||
List<MimeType> expected = new ArrayList<>();
|
||||
expected.add(audio);
|
||||
@@ -398,8 +398,8 @@ class MimeTypeTests {
|
||||
|
||||
m1 = new MimeType("audio", "basic", singletonMap("foo", "bar"));
|
||||
m2 = new MimeType("audio", "basic", singletonMap("foo", "Bar"));
|
||||
assertThat(m1.compareTo(m2) != 0).as("Invalid comparison result").isTrue();
|
||||
assertThat(m2.compareTo(m1) != 0).as("Invalid comparison result").isTrue();
|
||||
assertThat(m1.compareTo(m2)).as("Invalid comparison result").isNotEqualTo(0);
|
||||
assertThat(m2.compareTo(m1)).as("Invalid comparison result").isNotEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -141,7 +141,7 @@ class ObjectUtilsTests {
|
||||
void toObjectArray() {
|
||||
int[] a = new int[] {1, 2, 3, 4, 5};
|
||||
Integer[] wrapper = (Integer[]) ObjectUtils.toObjectArray(a);
|
||||
assertThat(wrapper.length == 5).isTrue();
|
||||
assertThat(wrapper.length).isEqualTo(5);
|
||||
for (int i = 0; i < wrapper.length; i++) {
|
||||
assertThat(wrapper[i].intValue()).isEqualTo(a[i]);
|
||||
}
|
||||
@@ -794,7 +794,7 @@ class ObjectUtilsTests {
|
||||
private void assertEqualHashCodes(int expected, Object array) {
|
||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(array.hashCode() != actual).isTrue();
|
||||
assertThat(array.hashCode()).isNotEqualTo(actual);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -125,10 +125,10 @@ class PropertiesPersisterTests {
|
||||
propCopy = new String(propOut.toByteArray());
|
||||
}
|
||||
if (header != null) {
|
||||
assertThat(propCopy.contains(header)).isTrue();
|
||||
assertThat(propCopy).contains(header);
|
||||
}
|
||||
assertThat(propCopy.contains("\ncode1=message1")).isTrue();
|
||||
assertThat(propCopy.contains("\ncode2=message2")).isTrue();
|
||||
assertThat(propCopy).contains("\ncode1=message1");
|
||||
assertThat(propCopy).contains("\ncode2=message2");
|
||||
return propCopy;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -176,7 +176,7 @@ class ReflectionUtilsTests {
|
||||
src.setName("freddie");
|
||||
src.setAge(15);
|
||||
src.setSpouse(new TestObject());
|
||||
assertThat(src.getAge() == dest.getAge()).isFalse();
|
||||
assertThat(src.getAge()).isNotEqualTo(dest.getAge());
|
||||
|
||||
ReflectionUtils.shallowCopyFieldState(src, dest);
|
||||
assertThat(dest.getAge()).isEqualTo(src.getAge());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,11 +70,11 @@ class StringUtilsTests {
|
||||
@Deprecated
|
||||
void trimWhitespace() {
|
||||
assertThat(StringUtils.trimWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace("\t")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace("\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace(" \t\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace("")).isEmpty();
|
||||
assertThat(StringUtils.trimWhitespace(" ")).isEmpty();
|
||||
assertThat(StringUtils.trimWhitespace("\t")).isEmpty();
|
||||
assertThat(StringUtils.trimWhitespace("\n")).isEmpty();
|
||||
assertThat(StringUtils.trimWhitespace(" \t\n")).isEmpty();
|
||||
assertThat(StringUtils.trimWhitespace(" a")).isEqualTo("a");
|
||||
assertThat(StringUtils.trimWhitespace("a ")).isEqualTo("a");
|
||||
assertThat(StringUtils.trimWhitespace(" a ")).isEqualTo("a");
|
||||
@@ -85,11 +85,11 @@ class StringUtilsTests {
|
||||
@Test
|
||||
void trimAllWhitespace() {
|
||||
assertThat(StringUtils.trimAllWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimAllWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace("\t")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace("\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace(" \t\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace("")).isEmpty();
|
||||
assertThat(StringUtils.trimAllWhitespace(" ")).isEmpty();
|
||||
assertThat(StringUtils.trimAllWhitespace("\t")).isEmpty();
|
||||
assertThat(StringUtils.trimAllWhitespace("\n")).isEmpty();
|
||||
assertThat(StringUtils.trimAllWhitespace(" \t\n")).isEmpty();
|
||||
assertThat(StringUtils.trimAllWhitespace(" a")).isEqualTo("a");
|
||||
assertThat(StringUtils.trimAllWhitespace("a ")).isEqualTo("a");
|
||||
assertThat(StringUtils.trimAllWhitespace(" a ")).isEqualTo("a");
|
||||
@@ -101,11 +101,11 @@ class StringUtilsTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
void trimLeadingWhitespace() {
|
||||
assertThat(StringUtils.trimLeadingWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimLeadingWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace("\t")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace("\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" \t\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace("")).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" ")).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingWhitespace("\t")).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingWhitespace("\n")).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" \t\n")).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" a")).isEqualTo("a");
|
||||
assertThat(StringUtils.trimLeadingWhitespace("a ")).isEqualTo("a ");
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" a ")).isEqualTo("a ");
|
||||
@@ -117,11 +117,11 @@ class StringUtilsTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
void trimTrailingWhitespace() {
|
||||
assertThat(StringUtils.trimTrailingWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimTrailingWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace("\t")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace("\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" \t\n")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace("")).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" ")).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingWhitespace("\t")).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingWhitespace("\n")).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" \t\n")).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingWhitespace("a ")).isEqualTo("a");
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" a")).isEqualTo(" a");
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" a ")).isEqualTo(" a");
|
||||
@@ -132,8 +132,8 @@ class StringUtilsTests {
|
||||
@Test
|
||||
void trimLeadingCharacter() {
|
||||
assertThat(StringUtils.trimLeadingCharacter(null, ' ')).isNull();
|
||||
assertThat(StringUtils.trimLeadingCharacter("", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingCharacter(" ", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingCharacter("", ' ')).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingCharacter(" ", ' ')).isEmpty();
|
||||
assertThat(StringUtils.trimLeadingCharacter("\t", ' ')).isEqualTo("\t");
|
||||
assertThat(StringUtils.trimLeadingCharacter(" a", ' ')).isEqualTo("a");
|
||||
assertThat(StringUtils.trimLeadingCharacter("a ", ' ')).isEqualTo("a ");
|
||||
@@ -145,8 +145,8 @@ class StringUtilsTests {
|
||||
@Test
|
||||
void trimTrailingCharacter() {
|
||||
assertThat(StringUtils.trimTrailingCharacter(null, ' ')).isNull();
|
||||
assertThat(StringUtils.trimTrailingCharacter("", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingCharacter(" ", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingCharacter("", ' ')).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingCharacter(" ", ' ')).isEmpty();
|
||||
assertThat(StringUtils.trimTrailingCharacter("\t", ' ')).isEqualTo("\t");
|
||||
assertThat(StringUtils.trimTrailingCharacter("a ", ' ')).isEqualTo("a");
|
||||
assertThat(StringUtils.trimTrailingCharacter(" a", ' ')).isEqualTo(" a");
|
||||
@@ -219,19 +219,19 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void countOccurrencesOf() {
|
||||
assertThat(StringUtils.countOccurrencesOf(null, null) == 0).as("nullx2 = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf("s", null) == 0).as("null string = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(null, "s") == 0).as("null substring = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(null, null)).as("nullx2 = 0").isEqualTo(0);
|
||||
assertThat(StringUtils.countOccurrencesOf("s", null)).as("null string = 0").isEqualTo(0);
|
||||
assertThat(StringUtils.countOccurrencesOf(null, "s")).as("null substring = 0").isEqualTo(0);
|
||||
String s = "erowoiueoiur";
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "WERWER") == 0).as("not found = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "x") == 0).as("not found char = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, " ") == 0).as("not found ws = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "") == 0).as("not found empty string = 0").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "e") == 2).as("found char=2").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "oi") == 2).as("found substring=2").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "oiu") == 2).as("found substring=2").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "oiur") == 1).as("found substring=3").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "r") == 2).as("test last").isTrue();
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "WERWER")).as("not found = 0").isEqualTo(0);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "x")).as("not found char = 0").isEqualTo(0);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, " ")).as("not found ws = 0").isEqualTo(0);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "")).as("not found empty string = 0").isEqualTo(0);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "e")).as("found char=2").isEqualTo(2);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "oi")).as("found substring=2").isEqualTo(2);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "oiu")).as("found substring=2").isEqualTo(2);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "oiur")).as("found substring=3").isEqualTo(1);
|
||||
assertThat(StringUtils.countOccurrencesOf(s, "r")).as("test last").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,7 +242,7 @@ class StringUtilsTests {
|
||||
|
||||
// Simple replace
|
||||
String s = StringUtils.replace(inString, oldPattern, newPattern);
|
||||
assertThat(s.equals("a6AazAfoo77abfoo")).as("Replace 1 worked").isTrue();
|
||||
assertThat(s).as("Replace 1 worked").isEqualTo("a6AazAfoo77abfoo");
|
||||
|
||||
// Non match: no change
|
||||
s = StringUtils.replace(inString, "qwoeiruqopwieurpoqwieur", newPattern);
|
||||
@@ -262,22 +262,23 @@ class StringUtilsTests {
|
||||
String inString = "The quick brown fox jumped over the lazy dog";
|
||||
|
||||
String noThe = StringUtils.delete(inString, "the");
|
||||
assertThat(noThe.equals("The quick brown fox jumped over lazy dog")).as("Result has no the [" + noThe + "]").isTrue();
|
||||
assertThat(noThe).as("Result has no the [" + noThe + "]")
|
||||
.isEqualTo("The quick brown fox jumped over lazy dog");
|
||||
|
||||
String nohe = StringUtils.delete(inString, "he");
|
||||
assertThat(nohe.equals("T quick brown fox jumped over t lazy dog")).as("Result has no he [" + nohe + "]").isTrue();
|
||||
assertThat(nohe).as("Result has no he [" + nohe + "]").isEqualTo("T quick brown fox jumped over t lazy dog");
|
||||
|
||||
String nosp = StringUtils.delete(inString, " ");
|
||||
assertThat(nosp.equals("Thequickbrownfoxjumpedoverthelazydog")).as("Result has no spaces").isTrue();
|
||||
assertThat(nosp).as("Result has no spaces").isEqualTo("Thequickbrownfoxjumpedoverthelazydog");
|
||||
|
||||
String killEnd = StringUtils.delete(inString, "dog");
|
||||
assertThat(killEnd.equals("The quick brown fox jumped over the lazy ")).as("Result has no dog").isTrue();
|
||||
assertThat(killEnd).as("Result has no dog").isEqualTo("The quick brown fox jumped over the lazy ");
|
||||
|
||||
String mismatch = StringUtils.delete(inString, "dxxcxcxog");
|
||||
assertThat(mismatch.equals(inString)).as("Result is unchanged").isTrue();
|
||||
assertThat(mismatch).as("Result is unchanged").isEqualTo(inString);
|
||||
|
||||
String nochange = StringUtils.delete(inString, "");
|
||||
assertThat(nochange.equals(inString)).as("Result is unchanged").isTrue();
|
||||
assertThat(nochange).as("Result is unchanged").isEqualTo(inString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -344,7 +345,7 @@ class StringUtilsTests {
|
||||
@Test
|
||||
void getFilename() {
|
||||
assertThat(StringUtils.getFilename(null)).isNull();
|
||||
assertThat(StringUtils.getFilename("")).isEqualTo("");
|
||||
assertThat(StringUtils.getFilename("")).isEmpty();
|
||||
assertThat(StringUtils.getFilename("myfile")).isEqualTo("myfile");
|
||||
assertThat(StringUtils.getFilename("mypath/myfile")).isEqualTo("myfile");
|
||||
assertThat(StringUtils.getFilename("myfile.")).isEqualTo("myfile.");
|
||||
@@ -360,8 +361,8 @@ class StringUtilsTests {
|
||||
assertThat(StringUtils.getFilenameExtension("myfile")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("myPath/myfile")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("myfile.")).isEqualTo("");
|
||||
assertThat(StringUtils.getFilenameExtension("myPath/myfile.")).isEqualTo("");
|
||||
assertThat(StringUtils.getFilenameExtension("myfile.")).isEmpty();
|
||||
assertThat(StringUtils.getFilenameExtension("myPath/myfile.")).isEmpty();
|
||||
assertThat(StringUtils.getFilenameExtension("myfile.txt")).isEqualTo("txt");
|
||||
assertThat(StringUtils.getFilenameExtension("mypath/myfile.txt")).isEqualTo("txt");
|
||||
assertThat(StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile.txt")).isEqualTo("txt");
|
||||
@@ -369,7 +370,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void stripFilenameExtension() {
|
||||
assertThat(StringUtils.stripFilenameExtension("")).isEqualTo("");
|
||||
assertThat(StringUtils.stripFilenameExtension("")).isEmpty();
|
||||
assertThat(StringUtils.stripFilenameExtension("myfile")).isEqualTo("myfile");
|
||||
assertThat(StringUtils.stripFilenameExtension("myfile.")).isEqualTo("myfile");
|
||||
assertThat(StringUtils.stripFilenameExtension("myfile.txt")).isEqualTo("myfile");
|
||||
@@ -394,8 +395,8 @@ class StringUtilsTests {
|
||||
assertThat(StringUtils.cleanPath("/a/:b/../../mypath/myfile")).isEqualTo("/mypath/myfile");
|
||||
assertThat(StringUtils.cleanPath("/")).isEqualTo("/");
|
||||
assertThat(StringUtils.cleanPath("/mypath/../")).isEqualTo("/");
|
||||
assertThat(StringUtils.cleanPath("mypath/..")).isEqualTo("");
|
||||
assertThat(StringUtils.cleanPath("mypath/../.")).isEqualTo("");
|
||||
assertThat(StringUtils.cleanPath("mypath/..")).isEmpty();
|
||||
assertThat(StringUtils.cleanPath("mypath/../.")).isEmpty();
|
||||
assertThat(StringUtils.cleanPath("mypath/../")).isEqualTo("./");
|
||||
assertThat(StringUtils.cleanPath("././")).isEqualTo("./");
|
||||
assertThat(StringUtils.cleanPath("./")).isEqualTo("./");
|
||||
@@ -511,15 +512,15 @@ class StringUtilsTests {
|
||||
@Test
|
||||
void commaDelimitedListToStringArrayWithNullProducesEmptyArray() {
|
||||
String[] sa = StringUtils.commaDelimitedListToStringArray(null);
|
||||
assertThat(sa != null).as("String array isn't null with null input").isTrue();
|
||||
assertThat(sa.length == 0).as("String array length == 0 with null input").isTrue();
|
||||
assertThat(sa).as("String array isn't null with null input").isNotNull();
|
||||
assertThat(sa.length).as("String array length == 0 with null input").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void commaDelimitedListToStringArrayWithEmptyStringProducesEmptyArray() {
|
||||
String[] sa = StringUtils.commaDelimitedListToStringArray("");
|
||||
assertThat(sa != null).as("String array isn't null with null input").isTrue();
|
||||
assertThat(sa.length == 0).as("String array length == 0 with null input").isTrue();
|
||||
assertThat(sa).as("String array isn't null with null input").isNotNull();
|
||||
assertThat(sa.length).as("String array length == 0 with null input").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -582,8 +583,8 @@ class StringUtilsTests {
|
||||
// Could read these from files
|
||||
String s = "woeirqupoiewuropqiewuorpqiwueopriquwopeiurqopwieur";
|
||||
String[] sa = StringUtils.commaDelimitedListToStringArray(s);
|
||||
assertThat(sa.length == 1).as("Found one String with no delimiters").isTrue();
|
||||
assertThat(sa[0].equals(s)).as("Single array entry matches input String with no delimiters").isTrue();
|
||||
assertThat(sa.length).as("Found one String with no delimiters").isEqualTo(1);
|
||||
assertThat(sa[0]).as("Single array entry matches input String with no delimiters").isEqualTo(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -610,7 +611,7 @@ class StringUtilsTests {
|
||||
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) {
|
||||
String sb = String.join(String.valueOf(','), components);
|
||||
String[] sa = StringUtils.commaDelimitedListToStringArray(sb);
|
||||
assertThat(sa != null).as("String array isn't null with legal match").isTrue();
|
||||
assertThat(sa).as("String array isn't null with legal match").isNotNull();
|
||||
assertThat(sa.length).as("String array length is correct with legal match").isEqualTo(components.length);
|
||||
assertThat(Arrays.equals(sa, components)).as("Output equals input").isTrue();
|
||||
}
|
||||
@@ -692,7 +693,7 @@ class StringUtilsTests {
|
||||
for (Locale locale : Locale.getAvailableLocales()) {
|
||||
Locale parsedLocale = StringUtils.parseLocaleString(locale.toString());
|
||||
if (parsedLocale == null) {
|
||||
assertThat(locale.getLanguage()).isEqualTo("");
|
||||
assertThat(locale.getLanguage()).isEmpty();
|
||||
}
|
||||
else {
|
||||
assertThat(locale.toString()).isEqualTo(parsedLocale.toString());
|
||||
@@ -705,7 +706,7 @@ class StringUtilsTests {
|
||||
for (Locale locale : Locale.getAvailableLocales()) {
|
||||
Locale parsedLocale = StringUtils.parseLocale(locale.toLanguageTag());
|
||||
if (parsedLocale == null) {
|
||||
assertThat(locale.getLanguage()).isEqualTo("");
|
||||
assertThat(locale.getLanguage()).isEmpty();
|
||||
}
|
||||
else {
|
||||
assertThat(locale.toLanguageTag()).isEqualTo(parsedLocale.toLanguageTag());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,7 +110,7 @@ class SystemPropertyUtilsTests {
|
||||
@Test
|
||||
void replaceWithEmptyDefault() {
|
||||
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:}");
|
||||
assertThat(resolved).isEqualTo("");
|
||||
assertThat(resolved).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -62,7 +62,7 @@ class UnmodifiableMultiValueMapTests {
|
||||
list.add("bar");
|
||||
given(mock.get("foo")).willReturn(list);
|
||||
List<String> result = map.get("foo");
|
||||
assertThat(result).isNotNull().containsExactly("bar");
|
||||
assertThat(result).containsExactly("bar");
|
||||
assertThatUnsupportedOperationException().isThrownBy(() -> result.add("baz"));
|
||||
|
||||
given(mock.getOrDefault("foo", List.of("bar"))).willReturn(List.of("baz"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ class ComparableComparatorTests {
|
||||
Comparator<String> c = new ComparableComparator<>();
|
||||
String s1 = "abc";
|
||||
String s2 = "cde";
|
||||
assertThat(c.compare(s1, s2) < 0).isTrue();
|
||||
assertThat(c.compare(s1, s2)).isLessThan(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,15 +35,15 @@ class NullSafeComparatorTests {
|
||||
@Test
|
||||
void shouldCompareWithNullsLow() {
|
||||
Comparator<String> c = NullSafeComparator.NULLS_LOW;
|
||||
assertThat(c.compare(null, "boo") < 0).isTrue();
|
||||
assertThat(c.compare(null, "boo")).isLessThan(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
void shouldCompareWithNullsHigh() {
|
||||
Comparator<String> c = NullSafeComparator.NULLS_HIGH;
|
||||
assertThat(c.compare(null, "boo") > 0).isTrue();
|
||||
assertThat(c.compare(null, null) == 0).isTrue();
|
||||
assertThat(c.compare(null, "boo")).isGreaterThan(0);
|
||||
assertThat(c.compare(null, null)).isEqualTo(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,16 +62,14 @@ class SimpleNamespaceContextTests {
|
||||
.isEqualTo(XMLConstants.XML_NS_URI);
|
||||
|
||||
assertThat(context.getNamespaceURI(unboundPrefix))
|
||||
.as("Returns \"\" for an unbound prefix")
|
||||
.isEqualTo(XMLConstants.NULL_NS_URI);
|
||||
.as("Returns \"\" for an unbound prefix").isEmpty();
|
||||
context.bindNamespaceUri(prefix, namespaceUri);
|
||||
assertThat(context.getNamespaceURI(prefix))
|
||||
.as("Returns the bound namespace URI for a bound prefix")
|
||||
.isEqualTo(namespaceUri);
|
||||
|
||||
assertThat(context.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX))
|
||||
.as("By default returns URI \"\" for the default namespace prefix")
|
||||
.isEqualTo(XMLConstants.NULL_NS_URI);
|
||||
.as("By default returns URI \"\" for the default namespace prefix").isEmpty();
|
||||
context.bindDefaultNamespaceUri(defaultNamespaceUri);
|
||||
assertThat(context.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX))
|
||||
.as("Returns the set URI for the default namespace prefix")
|
||||
@@ -183,14 +181,14 @@ class SimpleNamespaceContextTests {
|
||||
|
||||
context.bindNamespaceUri(prefix, namespaceUri);
|
||||
context.removeBinding(prefix);
|
||||
assertThat(context.getNamespaceURI(prefix)).as("Returns default namespace URI for removed prefix").isEqualTo(XMLConstants.NULL_NS_URI);
|
||||
assertThat(context.getNamespaceURI(prefix)).as("Returns default namespace URI for removed prefix").isEmpty();
|
||||
assertThat(context.getPrefix(namespaceUri)).as("#getPrefix returns null when all prefixes for a namespace URI were removed").isNull();
|
||||
assertThat(context.getPrefixes(namespaceUri).hasNext()).as("#getPrefixes returns an empty iterator when all prefixes for a namespace URI were removed").isFalse();
|
||||
|
||||
context.bindNamespaceUri("prefix1", additionalNamespaceUri);
|
||||
context.bindNamespaceUri("prefix2", additionalNamespaceUri);
|
||||
context.removeBinding("prefix1");
|
||||
assertThat(context.getNamespaceURI("prefix1")).as("Prefix was unbound").isEqualTo(XMLConstants.NULL_NS_URI);
|
||||
assertThat(context.getNamespaceURI("prefix1")).as("Prefix was unbound").isEmpty();
|
||||
assertThat(context.getPrefix(additionalNamespaceUri)).as("#getPrefix returns a bound prefix after removal of another prefix for the same namespace URI").isEqualTo("prefix2");
|
||||
assertThat(getItemSet(context.getPrefixes(additionalNamespaceUri)))
|
||||
.as("Prefix was removed from namespace URI")
|
||||
|
||||
Reference in New Issue
Block a user