Skip to content

Commit

Permalink
Merge branch '5.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed May 28, 2020
2 parents d706899 + 3201671 commit 967478b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
Expand Down Expand Up @@ -142,10 +142,10 @@ protected static final class DefaultCustomCodecs implements CustomCodecs {
* @since 5.1.12
*/
DefaultCustomCodecs(DefaultCustomCodecs other) {
other.typedReaders.putAll(this.typedReaders);
other.typedWriters.putAll(this.typedWriters);
other.objectReaders.putAll(this.objectReaders);
other.objectWriters.putAll(this.objectWriters);
this.typedReaders.putAll(other.typedReaders);
this.typedWriters.putAll(other.typedWriters);
this.objectReaders.putAll(other.objectReaders);
this.objectWriters.putAll(other.objectWriters);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
*/
public class CodecConfigurerTests {
class CodecConfigurerTests {

private final CodecConfigurer configurer = new TestCodecConfigurer();

private final AtomicInteger index = new AtomicInteger(0);


@Test
public void defaultReaders() {
void defaultReaders() {
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
assertThat(readers.size()).isEqualTo(12);
assertThat(getNextDecoder(readers).getClass()).isEqualTo(ByteArrayDecoder.class);
Expand All @@ -95,7 +95,7 @@ public void defaultReaders() {
}

@Test
public void defaultWriters() {
void defaultWriters() {
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
assertThat(writers.size()).isEqualTo(11);
assertThat(getNextEncoder(writers).getClass()).isEqualTo(ByteArrayEncoder.class);
Expand All @@ -112,7 +112,7 @@ public void defaultWriters() {
}

@Test
public void defaultAndCustomReaders() {
void defaultAndCustomReaders() {
Decoder<?> customDecoder1 = mock(Decoder.class);
Decoder<?> customDecoder2 = mock(Decoder.class);

Expand Down Expand Up @@ -153,7 +153,7 @@ public void defaultAndCustomReaders() {
}

@Test
public void defaultAndCustomWriters() {
void defaultAndCustomWriters() {
Encoder<?> customEncoder1 = mock(Encoder.class);
Encoder<?> customEncoder2 = mock(Encoder.class);

Expand Down Expand Up @@ -193,7 +193,7 @@ public void defaultAndCustomWriters() {
}

@Test
public void defaultsOffCustomReaders() {
void defaultsOffCustomReaders() {
Decoder<?> customDecoder1 = mock(Decoder.class);
Decoder<?> customDecoder2 = mock(Decoder.class);

Expand Down Expand Up @@ -224,7 +224,7 @@ public void defaultsOffCustomReaders() {
}

@Test
public void defaultsOffWithCustomWriters() {
void defaultsOffWithCustomWriters() {
Encoder<?> customEncoder1 = mock(Encoder.class);
Encoder<?> customEncoder2 = mock(Encoder.class);

Expand Down Expand Up @@ -255,7 +255,7 @@ public void defaultsOffWithCustomWriters() {
}

@Test
public void encoderDecoderOverrides() {
void encoderDecoderOverrides() {
Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
Jackson2SmileDecoder smileDecoder = new Jackson2SmileDecoder();
Expand Down Expand Up @@ -285,23 +285,45 @@ public void encoderDecoderOverrides() {
}

@Test
public void cloneCustomCodecs() {
void cloneEmptyCustomCodecs() {
this.configurer.registerDefaults(false);
CodecConfigurer clone = this.configurer.clone();
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();

CodecConfigurer clone = this.configurer.clone();
clone.customCodecs().register(new Jackson2JsonEncoder());
clone.customCodecs().register(new Jackson2JsonDecoder());
clone.customCodecs().register(new ServerSentEventHttpMessageReader());
clone.customCodecs().register(new ServerSentEventHttpMessageWriter());

assertThat(this.configurer.getReaders().size()).isEqualTo(0);
assertThat(this.configurer.getWriters().size()).isEqualTo(0);
assertThat(clone.getReaders().size()).isEqualTo(2);
assertThat(clone.getWriters().size()).isEqualTo(2);
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();
assertThat(clone.getReaders()).hasSize(2);
assertThat(clone.getWriters()).hasSize(2);
}

@Test
void cloneCustomCodecs() {
this.configurer.registerDefaults(false);
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();

this.configurer.customCodecs().register(new Jackson2JsonEncoder());
this.configurer.customCodecs().register(new Jackson2JsonDecoder());
this.configurer.customCodecs().register(new ServerSentEventHttpMessageReader());
this.configurer.customCodecs().register(new ServerSentEventHttpMessageWriter());
assertThat(this.configurer.getReaders()).hasSize(2);
assertThat(this.configurer.getWriters()).hasSize(2);

CodecConfigurer clone = this.configurer.clone();
assertThat(this.configurer.getReaders()).hasSize(2);
assertThat(this.configurer.getWriters()).hasSize(2);
assertThat(clone.getReaders()).hasSize(2);
assertThat(clone.getWriters()).hasSize(2);
}

@Test
public void cloneDefaultCodecs() {
void cloneDefaultCodecs() {
CodecConfigurer clone = this.configurer.clone();

Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
Expand Down

0 comments on commit 967478b

Please sign in to comment.