I am creating unit tests but the class uses objects that have long JSON. What can I do to improve the readability of this?
In tests, only insert those JSON really needed for the test. The class I tested is responsible in turn that JSON in a modified spreadsheet (xlsx) and it seems difficult to maintain the code.
@Test
public void testBuildSheet_validSheet_NoMedia() throws Exception {
BasicDBObject specPlanilha = (BasicDBObject) JSON.parse("{\"spec_veiculo\" : \"BuscaDescontos\" , \"spec_canal\" : \"Homepage\" , \"spec_formato\" : \"SuperBanner\" , \"spec_linha-criativa\" : null , " +
"\"spec_tamanho\" : \"728x90\" , \"spec_extensao\" : \"jpg/png\" , \"peca_peso\" : \"50kb\" , \"imagem_peso\" : \"50kb\" , " +
"\"peca_flash\" : \"4 até 10\" , \"peca_clicktag\" : \"on (release) {\\n getURL(_root.clickTAG, '_blank');\\n}\" , " +
"\"peca_framerate\" : \"24fps\" , \"peca_tempo\" : \"30s\" , \"spec_observacoes\" : null , " +
"\"peca_nome\" : \"Whirlpool_LinhaBranca_BuscaDescontos_Homepage_SuperBanner_-.jpg\" , \"extras\" : " +
"{ \"linha\" : \"10\" , \"Rich Media\" : \"Não\" , \"Link Especificação\" : \"http://portal.agenciaclick.com.br/midiaSP/Midia/Lists/Tabela%20de%20Especificao%20e%20Formato%20de%20Peas/DispForm.aspx?ID=3405&Source=http%3A%2F%2Fportal%2Eagenciaclick%2Ecom%2Ebr%2FmidiaSP%2FMidia%2FLists%2FTabela%2520de%2520Especificao%2520e%2520Formato%2520de%2520Peas%2FSites%2Easpx\" ," +
" \"Data Entrega Mídia\" : null , \"Data Disparo/Subida\" : null }}");
List<BasicDBObject> listSpec = new ArrayList<>();
listSpec.add(specPlanilha);
BasicDBObject specFields = (BasicDBObject) JSON.parse("{\"peca_nome\": \"Whirlpool_LinhaBranca_BuscaDescontos_Homepage_SuperBanner_-.jpg\",\n" +
" \"extras\": {\n" +
" \"linha\": \"10\",\n" +
" \"Rich Media\": \"Não\",\n" +
" \"Link Especificação\": \"http://portal.agenciaclick.com.br/midiaSP/Midia/Lists/Tabela%20de%20Especificao%20e%20Formato%20de%20Peas/DispForm.aspx?ID=3405&Source=http%3A%2F%2Fportal%2Eagenciaclick%2Ecom%2Ebr%2FmidiaSP%2FMidia%2FLists%2FTabela%2520de%2520Especificao%2520e%2520Formato%2520de%2520Peas%2FSites%2Easpx\",\n" +
" \"Data Entrega Mídia\": null,\n" +
" \"Data Disparo/Subida\": null\n" +
" }}");
ValidacaoResultado myValidation = new ValidacaoResultado().setId("123")
.setResultadoConsolidado("NO_MEDIA")
.setResultado(new BasicDBObject())
.setSpec(specFields);
oknok.validacao.entities.Planilha planilha = new Planilha()
.setPath(PlanilhaWorkbook.class.getClass().getResource("/planilhaWorkbook/T001.xlsx").getPath())
.setNomeHash("noMediaTest.xlsx")
.setSpec(listSpec);
List<ValidacaoResultado> myList = new ArrayList<>();
myList.add(myValidation);
File actual = planilhaWorkbook.buildSheet(myList, planilha);
SoftAssertions soft = new SoftAssertions();
soft.assertThat(actual.getName()).isEqualTo(planilha.getNomeHash());
soft.assertAll();
}