Skip to content

Commit

Permalink
Review: Improve test readability
Browse files Browse the repository at this point in the history
Issue: TNG#236
  • Loading branch information
codecholeric committed Nov 3, 2019
1 parent 192c0a3 commit 1e2401c
Showing 1 changed file with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.apache.logging.log4j.Level;
import org.assertj.core.api.Condition;
import org.assertj.core.util.Objects;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -663,18 +664,14 @@ public void imports_complex_method_with_correct_parameters() throws Exception {
JavaClass clazz = classesIn("testexamples/complexmethodimport").get(ClassWithComplexMethod.class);

assertThat(clazz.getMethods()).as("Methods of %s", ClassWithComplexMethod.class.getSimpleName()).hasSize(1);
assertThat(clazz.getMethod("complex", String.class, long.class, long.class, Serializable.class, Serializable.class))
.isEquivalentTo(ClassWithComplexMethod.class.getDeclaredMethod(
"complex", String.class, long.class, long.class, Serializable.class, Serializable.class));
assertThat(clazz.tryGetMethod("complex", String.class, long.class, long.class, Serializable.class, Serializable.class).get())
.isEquivalentTo(ClassWithComplexMethod.class.getDeclaredMethod(
"complex", String.class, long.class, long.class, Serializable.class, Serializable.class));
assertThat(clazz.getMethod("complex", "java.lang.String", "long", "long", "java.io.Serializable", "java.io.Serializable"))
.isEquivalentTo(ClassWithComplexMethod.class.getDeclaredMethod(
"complex", String.class, long.class, long.class, Serializable.class, Serializable.class));
assertThat(clazz.tryGetMethod("complex", "java.lang.String", "long", "long", "java.io.Serializable", "java.io.Serializable").get())
.isEquivalentTo(ClassWithComplexMethod.class.getDeclaredMethod(
"complex", String.class, long.class, long.class, Serializable.class, Serializable.class));

Class<?>[] parameterTypes = {String.class, long.class, long.class, Serializable.class, Serializable.class};
Method expectedMethod = ClassWithComplexMethod.class.getDeclaredMethod("complex", parameterTypes);

assertThat(clazz.getMethod("complex", parameterTypes)).isEquivalentTo(expectedMethod);
assertThat(clazz.tryGetMethod("complex", parameterTypes).get()).isEquivalentTo(expectedMethod);
assertThat(clazz.getMethod("complex", Objects.namesOf(parameterTypes))).isEquivalentTo(expectedMethod);
assertThat(clazz.tryGetMethod("complex", Objects.namesOf(parameterTypes)).get()).isEquivalentTo(expectedMethod);
}

@Test
Expand Down Expand Up @@ -898,14 +895,16 @@ public void imports_simple_constructors_with_correct_parameters() throws Excepti

assertThat(clazz.getConstructors()).as("Constructors").hasSize(3);
assertThat(clazz.getConstructor()).isEquivalentTo(ClassWithSimpleConstructors.class.getDeclaredConstructor());
assertThat(clazz.getConstructor(Object.class))
.isEquivalentTo(ClassWithSimpleConstructors.class.getDeclaredConstructor(Object.class));
assertThat(clazz.getConstructor("java.lang.Object"))
.isEquivalentTo(ClassWithSimpleConstructors.class.getDeclaredConstructor(Object.class));
assertThat(clazz.getConstructor(int.class, int.class))
.isEquivalentTo(ClassWithSimpleConstructors.class.getDeclaredConstructor(int.class, int.class));
assertThat(clazz.getConstructor("int", "int"))
.isEquivalentTo(ClassWithSimpleConstructors.class.getDeclaredConstructor(int.class, int.class));

Class<?>[] parameterTypes = {Object.class};
Constructor<ClassWithSimpleConstructors> expectedConstructor = ClassWithSimpleConstructors.class.getDeclaredConstructor(parameterTypes);
assertThat(clazz.getConstructor(parameterTypes)).isEquivalentTo(expectedConstructor);
assertThat(clazz.getConstructor(Objects.namesOf(parameterTypes))).isEquivalentTo(expectedConstructor);

parameterTypes = new Class[]{int.class, int.class};
expectedConstructor = ClassWithSimpleConstructors.class.getDeclaredConstructor(parameterTypes);
assertThat(clazz.getConstructor(parameterTypes)).isEquivalentTo(expectedConstructor);
assertThat(clazz.getConstructor(Objects.namesOf(parameterTypes))).isEquivalentTo(expectedConstructor);
}

@Test
Expand Down

0 comments on commit 1e2401c

Please sign in to comment.