Skip to content

Instantly share code, notes, and snippets.

@djkeh
Created September 11, 2020 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djkeh/f430b1e0254c7d546ec662d3d70da102 to your computer and use it in GitHub Desktop.
Save djkeh/f430b1e0254c7d546ec662d3d70da102 to your computer and use it in GitHub Desktop.
Test case which shows a bug on AbstractSerializableParameter in io.swagger:swagger-models:1.5.20
package com.example.bootdemo;
import io.swagger.models.parameters.AbstractSerializableParameter;
import io.swagger.models.properties.BaseIntegerProperty;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.assertj.core.api.Assertions.*;
/**
* @see io.swagger.annotations.ApiImplicitParam @ApiImplicitParam
*/
public class LogicTest {
private AbstractSerializableParameter<AnyParameter> parameter;
private static class AnyParameter extends AbstractSerializableParameter<AnyParameter> {} // just a dummy
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
@BeforeEach
void beforeEach() {
parameter = new AbstractSerializableParameter<>() {};
System.setOut(new PrintStream(out));
}
@AfterEach
void afterEach() {
System.setOut(System.out);
}
@Test
void givenNull_whenGettingExample_thenShowNoWarningLog() {
// Given
parameter.setExample(null);
parameter.setType(BaseIntegerProperty.TYPE);
// When
parameter.getExample();
// Then
assertThat(out.toString()).isEqualTo("");
}
/**
* Test that fails
*/
@Test
void givenEmptyString_whenGettingExample_thenShowNoWarningLog() {
// Given
parameter.setExample("");
parameter.setType(BaseIntegerProperty.TYPE);
// When
parameter.getExample();
// Then
assertThat(out.toString()).isEqualTo("");
}
}
@djkeh
Copy link
Author

djkeh commented Sep 11, 2020

This bug has been fixed already in the later verion 1.5.21 of swagger-models. But the latest version of springfox-boot-starter 3.0.0 still has this dependency. I raised an issue for solving this problem at:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment