<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=449156&amp;view=findpost&amp;p=3908441</guid>
        <pubDate>Fri, 09 Aug 2024 12:14:38 +0000</pubDate>
        <title>Mockito тестирование контроллера</title>
        <link>https://forum.sources.ru/index.php?showtopic=449156&amp;view=findpost&amp;p=3908441</link>
        <description><![CDATA[kopilov: Есть stacktrace этой ошибки? Есть полный код проекта?]]></description>
        <author>kopilov</author>
        <category>Java</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=449156&amp;view=findpost&amp;p=3908435</guid>
        <pubDate>Fri, 09 Aug 2024 11:51:59 +0000</pubDate>
        <title>Mockito тестирование контроллера</title>
        <link>https://forum.sources.ru/index.php?showtopic=449156&amp;view=findpost&amp;p=3908435</link>
        <description><![CDATA[wind: Сдаётся мне, вместо <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">when(personService.save(person)).thenReturn(person);</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
надо <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">when(personService.save(ArgumentMatchers.any(Person.class))).thenReturn(person);</div></ol></div></div></div></div>]]></description>
        <author>wind</author>
        <category>Java</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=449156&amp;view=findpost&amp;p=3908369</guid>
        <pubDate>Thu, 08 Aug 2024 10:24:29 +0000</pubDate>
        <title>Mockito тестирование контроллера</title>
        <link>https://forum.sources.ru/index.php?showtopic=449156&amp;view=findpost&amp;p=3908369</link>
        <description><![CDATA[Дмитрий591: Всем привет<br>
<br>
Изучаю тему тестирования и столкнулся с ошибкой которая не понятна для меня. Если кто может подсказать в чем проблема и как ее решить буду признателен.<br>
<br>
class Person:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">@Entity</div><div class="code_line">@Setter</div><div class="code_line">@Getter</div><div class="code_line">@Table(name = &quot;person&quot;)</div><div class="code_line">public class Person {</div><div class="code_line">&nbsp;&nbsp; &nbsp;@Id</div><div class="code_line">&nbsp;&nbsp; &nbsp;@GeneratedValue(strategy = GenerationType.IDENTITY)</div><div class="code_line">&nbsp;&nbsp; &nbsp;private Integer id;</div><div class="code_line">&nbsp;&nbsp; &nbsp;private String firstName;</div><div class="code_line">&nbsp;&nbsp; &nbsp;private String lastName;</div><div class="code_line">&nbsp;&nbsp; &nbsp;private String patronymicName;</div><div class="code_line">&nbsp;&nbsp; &nbsp;private Integer age;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;public Person(String firstName, String lastName, Integer age) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this.firstName = firstName;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this.lastName = lastName;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this.age = age;</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
<br>
<br>
PersonRepository:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">public interface PersonRepository extends JpaRepository&#60;Person, Integer&#62; {</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
PersonService:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">@Service</div><div class="code_line">public class PersonService {</div><div class="code_line">&nbsp;&nbsp; &nbsp;private final PersonRepository personRepository;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;public PersonService(PersonRepository personRepository) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this.personRepository = personRepository;</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;public Person save(Person person) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return personRepository.save(person);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
PersonController:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">@RestController</div><div class="code_line">@RequestMapping(&quot;/api/person&quot;)</div><div class="code_line">public class PersonController {</div><div class="code_line">&nbsp;&nbsp; &nbsp;private final PersonService personService;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;public PersonController(PersonService personService) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;this.personService = personService;</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;@PostMapping(&quot;/savePerson&quot;)</div><div class="code_line">&nbsp;&nbsp; &nbsp;public Person savePerson(@RequestBody Person person) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return personService.save(person);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
PersonTest:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">@WebMvcTest(controllers = PersonController.class)</div><div class="code_line">class PersonControllerTest {</div><div class="code_line">&nbsp;&nbsp; &nbsp;@MockBean</div><div class="code_line">&nbsp;&nbsp; &nbsp;private PersonService personService;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;@Autowired</div><div class="code_line">&nbsp;&nbsp; &nbsp;private MockMvc mockMVc;</div><div class="code_line">&nbsp;&nbsp; &nbsp;@Autowired</div><div class="code_line">&nbsp;&nbsp; &nbsp;private ObjectMapper objectMapper;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;@Test</div><div class="code_line">&nbsp;&nbsp; &nbsp;void savePerson() throws Exception {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Person person = new Person(&quot;Ivan&quot;, &quot;Ivanov&quot;, 34);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;when(personService.save(person)).thenReturn(person);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mockMVc.perform(post(&quot;/api/person/savePerson&quot;)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.contentType(MediaType.APPLICATION_JSON)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.content(objectMapper.writeValueAsString(person)))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.andExpect(status().isOk())</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.andExpect(jsonPath(&quot;$.firstName&quot;).value(person.getFirstName()));</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div></ol></div></div></div></div><br>
<br>
Возникает ошибка:  <strong class='tag-b'><span class="tag-color tag-color-named" data-value="red" style="color: red">json can not be null or empty</span></strong>]]></description>
        <author>Дмитрий591</author>
        <category>Java</category>
      </item>
	
      </channel>
      </rss>
	