"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-web/src/test/kotlin/org/springframework/http/codec/json/KotlinSerializationJsonEncoderTests.kt" between
spring-framework-5.3.23.tar.gz and spring-framework-5.3.24.tar.gz

About: Spring Framework is an application framework for the Java platform and .NET Framework. Community edition.

KotlinSerializationJsonEncoderTests.kt  (spring-framework-5.3.23):KotlinSerializationJsonEncoderTests.kt  (spring-framework-5.3.24)
skipping to change at line 20 skipping to change at line 20
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.http.codec.json package org.springframework.http.codec.json
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.Ordered import org.springframework.core.Ordered
import org.springframework.core.ResolvableType import org.springframework.core.ResolvableType
import org.springframework.core.io.buffer.DataBuffer import org.springframework.core.io.buffer.DataBuffer
import org.springframework.core.io.buffer.DataBufferUtils import org.springframework.core.io.buffer.DataBufferUtils
import org.springframework.core.testfixture.codec.AbstractEncoderTests import org.springframework.core.testfixture.codec.AbstractEncoderTests
import org.springframework.http.MediaType import org.springframework.http.MediaType
import org.springframework.http.codec.ServerSentEvent import org.springframework.http.codec.ServerSentEvent
import reactor.core.publisher.Flux import reactor.core.publisher.Flux
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
skipping to change at line 46 skipping to change at line 46
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
@Suppress("UsePropertyAccessSyntax") @Suppress("UsePropertyAccessSyntax")
class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa tionJsonEncoder>(KotlinSerializationJsonEncoder()) { class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa tionJsonEncoder>(KotlinSerializationJsonEncoder()) {
@Test @Test
override fun canEncode() { override fun canEncode() {
val pojoType = ResolvableType.forClass(Pojo::class.java) val pojoType = ResolvableType.forClass(Pojo::class.java)
val jsonSubtype = MediaType("application", "vnd.test-micro-type+j son") val jsonSubtype = MediaType("application", "vnd.test-micro-type+j son")
Assertions.assertThat(encoder.canEncode(pojoType, MediaType.APPLI assertThat(encoder.canEncode(pojoType, MediaType.APPLICATION_JSON
CATION_JSON)).isTrue() )).isTrue()
Assertions.assertThat(encoder.canEncode(pojoType, jsonSubtype)).i assertThat(encoder.canEncode(pojoType, jsonSubtype)).isTrue()
sTrue() assertThat(encoder.canEncode(pojoType, null)).isTrue()
Assertions.assertThat(encoder.canEncode(pojoType, null)).isTrue() assertThat(encoder.canEncode(ResolvableType.forClass(Pojo::class.
Assertions.assertThat(encoder.canEncode(ResolvableType.forClass(P java),
ojo::class.java),
MediaType("application", "json", StandardCharsets .UTF_8))).isTrue() MediaType("application", "json", StandardCharsets .UTF_8))).isTrue()
Assertions.assertThat(encoder.canEncode(ResolvableType.forClass(P ojo::class.java), assertThat(encoder.canEncode(ResolvableType.forClass(Pojo::class. java),
MediaType("application", "json", StandardCharsets .US_ASCII))).isTrue() MediaType("application", "json", StandardCharsets .US_ASCII))).isTrue()
Assertions.assertThat(encoder.canEncode(ResolvableType.forClassWi assertThat(encoder.canEncode(ResolvableType.forClassWithGenerics(
thGenerics(List::class.java, Int::class.java), MediaType.APPLICATION_JSON)).isTr List::class.java, Int::class.java), MediaType.APPLICATION_JSON)).isTrue()
ue() assertThat(encoder.canEncode(ResolvableType.forClassWithGenerics(
Assertions.assertThat(encoder.canEncode(ResolvableType.forClassWi List::class.java, Ordered::class.java), MediaType.APPLICATION_JSON)).isFalse()
thGenerics(List::class.java, Ordered::class.java), MediaType.APPLICATION_JSON)). assertThat(encoder.canEncode(ResolvableType.forClassWithGenerics(
isFalse() List::class.java, Pojo::class.java), MediaType.APPLICATION_JSON)).isTrue()
Assertions.assertThat(encoder.canEncode(ResolvableType.forClassWi assertThat(encoder.canEncode(ResolvableType.forClassWithGenerics(
thGenerics(List::class.java, Pojo::class.java), MediaType.APPLICATION_JSON)).isT ArrayList::class.java, Int::class.java), MediaType.APPLICATION_JSON)).isTrue()
rue() assertThat(encoder.canEncode(ResolvableType.forClassWithGenerics(
Assertions.assertThat(encoder.canEncode(ResolvableType.forClassWi ArrayList::class.java, Int::class.java), MediaType.APPLICATION_PDF)).isFalse()
thGenerics(ArrayList::class.java, Int::class.java), MediaType.APPLICATION_JSON))
.isTrue()
Assertions.assertThat(encoder.canEncode(ResolvableType.forClassWi
thGenerics(ArrayList::class.java, Int::class.java), MediaType.APPLICATION_PDF)).
isFalse()
} }
@Test @Test
override fun encode() { override fun encode() {
val input = Flux.just( val input = Flux.just(
Pojo("foo", "bar"), Pojo("foo", "bar"),
Pojo("foofoo", "barbar"), Pojo("foofoo", "barbar"),
Pojo("foofoofoo", "barbarbar") Pojo("foofoofoo", "barbarbar")
) )
testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer? > -> step testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer? > -> step
skipping to change at line 90 skipping to change at line 90
val input = Mono.just(Pojo("foo", "bar")) val input = Mono.just(Pojo("foo", "bar"))
testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer? > -> step testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer? > -> step
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\ "bar\"}") .consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\ "bar\"}")
.andThen { dataBuffer: DataBuffer? -> DataBufferU tils.release(dataBuffer) }) .andThen { dataBuffer: DataBuffer? -> DataBufferU tils.release(dataBuffer) })
.verifyComplete() .verifyComplete()
}) })
} }
@Test @Test
fun canNotEncode() { fun canNotEncode() {
Assertions.assertThat(encoder.canEncode(ResolvableType.forClass(S assertThat(encoder.canEncode(ResolvableType.forClass(String::clas
tring::class.java), null)).isFalse() s.java), null)).isFalse()
Assertions.assertThat(encoder.canEncode(ResolvableType.forClass(P assertThat(encoder.canEncode(ResolvableType.forClass(Pojo::class.
ojo::class.java), MediaType.APPLICATION_XML)).isFalse() java), MediaType.APPLICATION_XML)).isFalse()
val sseType = ResolvableType.forClass(ServerSentEvent::class.java ) val sseType = ResolvableType.forClass(ServerSentEvent::class.java )
Assertions.assertThat(encoder.canEncode(sseType, MediaType.APPLIC assertThat(encoder.canEncode(sseType, MediaType.APPLICATION_JSON)
ATION_JSON)).isFalse() ).isFalse()
Assertions.assertThat(encoder.canEncode(ResolvableType.forClass(O assertThat(encoder.canEncode(ResolvableType.forClass(Ordered::cla
rdered::class.java), MediaType.APPLICATION_JSON)).isFalse() ss.java), MediaType.APPLICATION_JSON)).isFalse()
} }
@Serializable @Serializable
data class Pojo(val foo: String, val bar: String, val pojo: Pojo? = null) data class Pojo(val foo: String, val bar: String, val pojo: Pojo? = null)
} }
 End of changes. 6 change blocks. 
32 lines changed or deleted 26 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)