ATS-532 : Code improvements (#89)

- move startup message from controllers to the Application classes (SpringBoot configuration beans)
- added static imports for most static variables and static methods
- simplified a few nested *if*s
- replaced Arrays.asList() with explicit immutable collections
- fixed a few IntelliJ code inspection warnings
This commit is contained in:
CezarLeahu
2019-08-18 18:45:14 +03:00
committed by GitHub
parent 485347729b
commit 22de0ce5df
40 changed files with 391 additions and 329 deletions

View File

@@ -66,13 +66,12 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
@Import({SelectingTransformer.class})
public class MiscControllerTest extends AbstractTransformerControllerTest
{
@Autowired
private MiscController controller;
private String sourceEncoding = "UTF-8";
private String targetEncoding = "UTF-8";
private String targetMimetype = MIMETYPE_TEXT_PLAIN;
private final String sourceEncoding = "UTF-8";
private final String targetEncoding = "UTF-8";
private final String targetMimetype = MIMETYPE_TEXT_PLAIN;
@Before
public void before() throws Exception
@@ -157,8 +156,8 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
@Test
public void testStringToString() throws Exception
{
String expected = null;
byte[] content = null;
String expected;
byte[] content;
try
{
content = "azAz10!<21>$%^&*()\t\r\n".getBytes(UTF_8);
@@ -204,14 +203,13 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
public void textToPdf() throws Exception
{
StringBuilder sb = new StringBuilder();
String expected = null;
for (int i = 1; i <= 5; i++)
{
sb.append(i);
sb.append(" I must not talk in class or feed my homework to my cat.\n");
}
sb.append("\nBart\n");
expected = sb.toString();
String expected = sb.toString();
MvcResult result = sendText("txt",
"UTF-8",
@@ -301,13 +299,12 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
.param("sourceEncoding", sourceEncoding)
.param("sourceMimetype", sourceMimetype);
MvcResult result = mockMvc
return mockMvc
.perform(requestBuilder)
.andExpect(status().is(OK.value()))
.andExpect(header().string("Content-Disposition",
"attachment; filename*= " + targetEncoding + "''test_file." + targetExtension))
.andReturn();
return result;
}
private String clean(String text)

View File

@@ -159,10 +159,8 @@ public class HtmlParserContentTransformerTest
}
}
private String readFromFile(File file, String encoding) throws Exception
private String readFromFile(File file, final String encoding) throws Exception
{
String content = "wrong content";
content = new String(Files.readAllBytes(file.toPath()), encoding);
return content;
return new String(Files.readAllBytes(file.toPath()), encoding);
}
}