DATACMNS-1483 - Polishing.
Statically import Assertions to align assertThat(…) calls with Java code. Use placeholder for MockK version. Original pull request: #338.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -266,7 +266,7 @@
|
||||
<dependency>
|
||||
<groupId>io.mockk</groupId>
|
||||
<artifactId>mockk</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<version>${mockk}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ package org.springframework.data.convert
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import org.springframework.data.annotation.PersistenceConstructor
|
||||
import org.springframework.data.mapping.PersistentEntity
|
||||
@@ -25,7 +26,6 @@ import org.springframework.data.mapping.context.SamplePersistentProperty
|
||||
import org.springframework.data.mapping.model.MappingInstantiationException
|
||||
import org.springframework.data.mapping.model.ParameterValueProvider
|
||||
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
/**
|
||||
* Unit tests for [KotlinClassGeneratingEntityInstantiator] creating instances using Kotlin data classes.
|
||||
@@ -51,8 +51,8 @@ class KotlinClassGeneratingEntityInstantiatorUnitTests {
|
||||
|
||||
val instance: Contact = KotlinClassGeneratingEntityInstantiator().createInstance(entity, provider)
|
||||
|
||||
Assertions.assertThat(instance.firstname).isEqualTo("Walter")
|
||||
Assertions.assertThat(instance.lastname).isEqualTo("White")
|
||||
assertThat(instance.firstname).isEqualTo("Walter")
|
||||
assertThat(instance.lastname).isEqualTo("White")
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
@@ -73,12 +73,12 @@ class KotlinClassGeneratingEntityInstantiatorUnitTests {
|
||||
|
||||
val instance: ContactWithDefaulting = KotlinClassGeneratingEntityInstantiator().createInstance(entity, provider)
|
||||
|
||||
Assertions.assertThat(instance.prop0).isEqualTo("Walter")
|
||||
Assertions.assertThat(instance.prop2).isEqualTo("Skyler")
|
||||
Assertions.assertThat(instance.prop31).isEqualTo("Walter")
|
||||
Assertions.assertThat(instance.prop32).isEqualTo("White")
|
||||
Assertions.assertThat(instance.prop33).isEqualTo("Junior")
|
||||
Assertions.assertThat(instance.prop34).isEqualTo("White")
|
||||
assertThat(instance.prop0).isEqualTo("Walter")
|
||||
assertThat(instance.prop2).isEqualTo("Skyler")
|
||||
assertThat(instance.prop31).isEqualTo("Walter")
|
||||
assertThat(instance.prop32).isEqualTo("White")
|
||||
assertThat(instance.prop33).isEqualTo("Junior")
|
||||
assertThat(instance.prop34).isEqualTo("White")
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1200
|
||||
@@ -92,7 +92,7 @@ class KotlinClassGeneratingEntityInstantiatorUnitTests {
|
||||
every { entity.type } returns constructor.constructor.declaringClass
|
||||
every { entity.typeInformation } returns mockk()
|
||||
|
||||
Assertions.assertThatThrownBy { KotlinClassGeneratingEntityInstantiator().createInstance(entity, provider) } //
|
||||
assertThatThrownBy { KotlinClassGeneratingEntityInstantiator().createInstance(entity, provider) } //
|
||||
.isInstanceOf(MappingInstantiationException::class.java) //
|
||||
.hasMessageContaining("fun <init>(kotlin.Boolean)") //
|
||||
.hasCauseInstanceOf(IllegalArgumentException::class.java)
|
||||
@@ -118,14 +118,14 @@ class KotlinClassGeneratingEntityInstantiatorUnitTests {
|
||||
|
||||
val instance: WithPrimitiveDefaulting = KotlinClassGeneratingEntityInstantiator().createInstance(entity, provider)
|
||||
|
||||
Assertions.assertThat(instance.aByte).isEqualTo(0)
|
||||
Assertions.assertThat(instance.aShort).isEqualTo(0)
|
||||
Assertions.assertThat(instance.anInt).isEqualTo(0)
|
||||
Assertions.assertThat(instance.aLong).isEqualTo(0L)
|
||||
Assertions.assertThat(instance.aFloat).isEqualTo(0.0f)
|
||||
Assertions.assertThat(instance.aDouble).isEqualTo(0.0)
|
||||
Assertions.assertThat(instance.aChar).isEqualTo('a')
|
||||
Assertions.assertThat(instance.aBool).isTrue()
|
||||
assertThat(instance.aByte).isEqualTo(0)
|
||||
assertThat(instance.aShort).isEqualTo(0)
|
||||
assertThat(instance.anInt).isEqualTo(0)
|
||||
assertThat(instance.aLong).isEqualTo(0L)
|
||||
assertThat(instance.aFloat).isEqualTo(0.0f)
|
||||
assertThat(instance.aDouble).isEqualTo(0.0)
|
||||
assertThat(instance.aChar).isEqualTo('a')
|
||||
assertThat(instance.aBool).isTrue()
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1338
|
||||
@@ -141,7 +141,7 @@ class KotlinClassGeneratingEntityInstantiatorUnitTests {
|
||||
|
||||
val instance: CustomUser = KotlinClassGeneratingEntityInstantiator().createInstance(entity, provider)
|
||||
|
||||
Assertions.assertThat(instance.id).isEqualTo("Walter")
|
||||
assertThat(instance.id).isEqualTo("Walter")
|
||||
}
|
||||
|
||||
data class Contact(val firstname: String, val lastname: String)
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.convert
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import org.springframework.data.mapping.PersistentEntity
|
||||
import org.springframework.data.mapping.context.SamplePersistentProperty
|
||||
@@ -46,8 +46,8 @@ class ReflectionEntityInstantiatorDataClassUnitTests {
|
||||
|
||||
val instance: Contact = ReflectionEntityInstantiator.INSTANCE.createInstance(entity, provider)
|
||||
|
||||
Assertions.assertThat(instance.firstname).isEqualTo("Walter")
|
||||
Assertions.assertThat(instance.lastname).isEqualTo("White")
|
||||
assertThat(instance.firstname).isEqualTo("Walter")
|
||||
assertThat(instance.lastname).isEqualTo("White")
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
@@ -61,8 +61,8 @@ class ReflectionEntityInstantiatorDataClassUnitTests {
|
||||
|
||||
val instance: ContactWithDefaulting = ReflectionEntityInstantiator.INSTANCE.createInstance(entity, provider)
|
||||
|
||||
Assertions.assertThat(instance.firstname).isEqualTo("Walter")
|
||||
Assertions.assertThat(instance.lastname).isEqualTo("White")
|
||||
assertThat(instance.firstname).isEqualTo("Walter")
|
||||
assertThat(instance.lastname).isEqualTo("White")
|
||||
}
|
||||
|
||||
data class Contact(val firstname: String, val lastname: String)
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.mapping.model
|
||||
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import org.springframework.data.annotation.PersistenceConstructor
|
||||
import org.springframework.data.mapping.model.AbstractPersistentPropertyUnitTests.*
|
||||
import org.springframework.data.mapping.model.AbstractPersistentPropertyUnitTests.SamplePersistentProperty
|
||||
|
||||
/**
|
||||
* Unit tests for [PreferredConstructorDiscoverer].
|
||||
@@ -32,7 +32,7 @@ class PreferredConstructorDiscovererUnitTests {
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<Simple, SamplePersistentProperty>(Simple::class.java)
|
||||
|
||||
Assertions.assertThat(constructor.parameters.size).isEqualTo(1)
|
||||
assertThat(constructor.parameters.size).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
@@ -40,7 +40,7 @@ class PreferredConstructorDiscovererUnitTests {
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<TwoConstructors, SamplePersistentProperty>(TwoConstructors::class.java)
|
||||
|
||||
Assertions.assertThat(constructor.parameters.size).isEqualTo(1)
|
||||
assertThat(constructor.parameters.size).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1170
|
||||
@@ -48,7 +48,7 @@ class PreferredConstructorDiscovererUnitTests {
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<TwoConstructorsWithoutDefault, SamplePersistentProperty>(TwoConstructorsWithoutDefault::class.java)
|
||||
|
||||
Assertions.assertThat(constructor.parameters).isEmpty()
|
||||
assertThat(constructor.parameters).isEmpty()
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
@@ -56,7 +56,7 @@ class PreferredConstructorDiscovererUnitTests {
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<AnnotatedConstructors, SamplePersistentProperty>(AnnotatedConstructors::class.java)
|
||||
|
||||
Assertions.assertThat(constructor.parameters.size).isEqualTo(2)
|
||||
assertThat(constructor.parameters.size).isEqualTo(2)
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
@@ -64,7 +64,7 @@ class PreferredConstructorDiscovererUnitTests {
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<DefaultConstructor, SamplePersistentProperty>(DefaultConstructor::class.java)
|
||||
|
||||
Assertions.assertThat(constructor.parameters.size).isEqualTo(1)
|
||||
assertThat(constructor.parameters.size).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1126
|
||||
@@ -72,18 +72,18 @@ class PreferredConstructorDiscovererUnitTests {
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<TwoDefaultConstructorsAnnotated, SamplePersistentProperty>(TwoDefaultConstructorsAnnotated::class.java)
|
||||
|
||||
Assertions.assertThat(constructor.parameters.size).isEqualTo(3)
|
||||
assertThat(constructor.parameters.size).isEqualTo(3)
|
||||
}
|
||||
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun `should not resolve constructor for synthetic Kotlin class`() {
|
||||
|
||||
val c = Class.forName("org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt") as Class<Any>
|
||||
|
||||
|
||||
val constructor = PreferredConstructorDiscoverer.discover<Any, SamplePersistentProperty>(c)
|
||||
|
||||
Assertions.assertThat(constructor).isNull()
|
||||
assertThat(constructor).isNull()
|
||||
}
|
||||
|
||||
data class Simple(val firstname: String)
|
||||
|
||||
@@ -18,16 +18,16 @@ package org.springframework.data.repository
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import org.springframework.data.repository.sample.User
|
||||
import java.util.*
|
||||
import kotlin.test.assertNull
|
||||
|
||||
/**
|
||||
* Unit tests for CrudRepositoryExtensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class CrudRepositoryExtensionsTests {
|
||||
|
||||
@@ -35,10 +35,13 @@ class CrudRepositoryExtensionsTests {
|
||||
|
||||
@Test // DATACMNS-1346
|
||||
fun `CrudRepository#findByIdOrNull() extension should call its Java counterpart`() {
|
||||
|
||||
val user = User()
|
||||
|
||||
every { repository.findById("foo") }.returnsMany(Optional.of(user), Optional.empty())
|
||||
assertEquals(user, repository.findByIdOrNull("foo"))
|
||||
assertNull(repository.findByIdOrNull("foo"))
|
||||
|
||||
assertThat(repository.findByIdOrNull("foo")).isEqualTo(user)
|
||||
assertThat(repository.findByIdOrNull("foo")).isNull()
|
||||
verify(exactly = 2) { repository.findById("foo") }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user