A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4698

Backtrace:

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 693
Function: getPaste

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once

Re: Untitled - Stikked
From Mature Owl, 6 Years ago, written in HTML5.
This paste is a reply to Untitled from Buff Marten - go back
Embed
Viewing differences between Untitled and Re: Untitled
package com.fosspowered.peist.controller;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fosspowered.peist.model.exceptions.PeistInvalidRequestException;
import com.fosspowered.peist.model.json.PasteRequest;
import com.fosspowered.peist.model.json.PasteResponse;
import com.fosspowered.peist.service.CRUDService;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;

@ExtendWith(SpringExtension.class)
@WebMvcTest(PasteController.class)
class PasteControllerTest {
  @Autowired private MockMvc mvc;

  @Autowired private ObjectMapper objectMapper;

  @MockBean private CRUDService CRUDService;

  @Test
  void whenPing_Normal_ReturnPong() throws Exception {
    mvc.perform(get("/paste/ping")).andExpect(content().string("pong"));
  }

  @Test
  void whenAddPaste_ValidRequest_PersistAndReturnPaste() throws Exception {
    given(CRUDService.addPaste(Mockito.any(PasteRequest.class)))
        .willReturn(PasteResponse.builder().title("title").build());

    MvcResult mvcResult =
        mvc.perform(
                post("/paste")
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(objectMapper.writeValueAsString(PasteRequest.builder().build())))
            .andExpect(status().isCreated())
            .andReturn();

    PasteResponse pasteResponse =
        objectMapper.readValue(mvcResult.getResponse().getContentAsString(), PasteResponse.class);
    assertThat(pasteResponse).isNotNull();
    assertThat(pasteResponse.getTitle()).isEqualTo("title");
  }

  @Test
  void whenGetPaste_PasteExists_ReturnsPaste() throws Exception {
    given(CRUDService.fetchPaste(Mockito.eq("id")))
        .willReturn(PasteResponse.builder().title("title").build());

    MvcResult mvcResult = mvc.perform(get("/paste/id")).andExpect(status().isOk()).andReturn();

    PasteResponse pasteResponse =
        objectMapper.readValue(mvcResult.getResponse().getContentAsString(), PasteResponse.class);
    assertThat(pasteResponse).isNotNull();
    assertThat(pasteResponse.getTitle()).isEqualTo("title");
  }

  @Test
  void whenGetPaste_NoPasteExists_Show404() throws Exception {
    given(CRUDService.fetchPaste(Mockito.eq("id"))).willThrow(PeistInvalidRequestException.class);

    mvc.perform(get("/paste/id")).andExpect(status().isNotFound());
  }

  @Test
  void whenGetAllPaste_Normal_ReturnsAll() throws Exception {
    given(CRUDService.fetchRecentPastes())
        .willReturn(
            IntStream.of(1, 2, 3)
                .mapToObj(i -> PasteResponse.builder().build())
                .collect(Collectors.toList()));

    MvcResult mvcResult = mvc.perform(get("/paste")).andExpect(status().isOk()).andReturn();
    @SuppressWarnings("unchecked")
    List<PasteResponse> response =
        objectMapper.readValue(mvcResult.getResponse().getContentAsString(), List.class);
    assertThat(response).hasSize(3);
  }
}