Lean Mind Semana 5

👨‍💻 Aprendizaje
📘 Prácticas Lean Mind
📅 2021-04-27

Está semana está marcada por el desarrollo del ejemplo de TDD con Spring y Selenium. Hubieron dificultades con Mockito. Dejo el código aquí:

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@WithMockUser("spring")
public class CsvFilterAppShould {
    @Autowired
    MockMvc mvc;

    final String fileName = "invoices.csv";
    final String filepath = System.getProperty("java.io.tmpdir") + fileName;
    File csvFile;

    @Before
    public void setUp() {
        csvFile = new File(filepath);
    }

    @After
    public void tearDown() {
        csvFile.delete();
    }

    @MockBean
    CsvFilter stubCsvFilter;

    @Test
    public void display_lines_after_filtering_csv_file() throws Exception {
        List<String> lines = List.of(
                "Num_factura, Fecha, Bruto, Neto, IVA, IGIC, Concepto, CIF_cliente, NIF_cliente",
                "1,02/05/2019,1000,810,19,,ACER Laptop,B76430134,",
                "2,03/12/2019,1000,2000,19,8,Lenovo Laptop,,78544372A");

        createCsv(lines);

        String pageSource = mvc.perform(
                MockMvcRequestBuilders.multipart(Configuration.WEBURL + "/postcsv")
                        .file(new MockMultipartFile(
                                "file", filepath,
                                "text/plain",
                                new FileInputStream(csvFile))))
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andReturn().getResponse().getContentAsString();


        assertThat(pageSource).contains(lines.get(0));
        assertThat(pageSource).contains(lines.get(1));
        assertThat(pageSource).doesNotContain(lines.get(2));
    }



    @Test
    public void filters_csv_file() {
        List<String> lines = List.of(
                "Num_factura, Fecha, Bruto, Neto, IVA, IGIC, Concepto, CIF_cliente, NIF_cliente",
                "1,02/05/2019,1000,810,19,,ACER Laptop,B76430134,",
                "2,03/12/2019,1000,2000,19,8,Lenovo Laptop,,78544372A");
        createCsv(lines);
        // this is the new line:
        given(stubCsvFilter.apply(lines)).willReturn(List.of(lines.get(0), lines.get(1)));
        /* ... same lines here ... */
    }

    private void createCsv(List<String> lines) {
        try {
            PrintWriter printWriter = new PrintWriter(filepath);
            for (String line : lines) {
                printWriter.println(line);
            }
            printWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Se desarrolló el kata propuesto por Mireia Range Parser, en el leguaje de Clojure. Una experiencia agridulce en la qué se aprende formas más fáciles de trabajar datos.

El viernes hubo una charla de “Plan de carrera”, la cuál la necesitaba, gracias Carlos Blé. La charla ayuda a enfocar la vida personal y laboral. Para ampliar conocimientos del tema desde otro punto de vista, he empezado un curso de magnament 3.0, para ver con se gestiona esto desde otra perspectiva.