>(persons, HttpStatus.OK);
120 | }
121 |
122 | public PersonDto createAddressFromPerson(PersonDto personDto, AddressDto addressDto) {
123 | // Mapping to entity
124 | Person person = new PersonImpl("muster");
125 | person.setName("Mustermann");
126 |
127 | Address address = new AddressImpl();
128 |
129 | Person createdPerson = null;
130 | try {
131 | createdPerson = personService.createAddressFromPerson(address, person);
132 | } catch (CreatePersonException e) {
133 | logger.error("Error: ", e);
134 | }
135 |
136 | // Mapping to DTO
137 | PersonDto createdPersonDto = buildPerson(createdPerson);
138 |
139 | return createdPersonDto;
140 | }
141 |
142 | private PersonDto buildPerson(Person person) {
143 | PersonDto personDto = new PersonDto();
144 | personDto.setName(person.getName());
145 | personDto.setNickname(person.getNickname());
146 | return personDto;
147 | }
148 |
149 | private void addTestDateToDb() {
150 | PersonImpl personImpl = new PersonImpl("muster");
151 | personImpl.setName("Mustermann");
152 | personRepository.save(personImpl);
153 |
154 | personImpl = new PersonImpl("baur");
155 | personImpl.setName("Bauer");
156 | personRepository.save(personImpl);
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/src/test/java/com/lofidewanto/demo/client/ui/person/PersonPanelViewTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package com.lofidewanto.demo.client.ui.person;
20 |
21 | import com.google.gwt.event.shared.EventBus;
22 | import com.google.gwtmockito.GwtMockitoTestRunner;
23 | import com.lofidewanto.demo.client.common.ErrorFormatter;
24 | import com.lofidewanto.demo.client.common.LoadingMessagePopupPanel;
25 | import com.lofidewanto.demo.client.domain.PersonClient;
26 | import org.gwtbootstrap3.extras.select.client.ui.Option;
27 | import org.junit.Before;
28 | import org.junit.Test;
29 | import org.junit.runner.RunWith;
30 | import org.mockito.Mock;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import static org.mockito.Matchers.anyString;
36 | import static org.mockito.Mockito.*;
37 |
38 | /**
39 | * Unit test with GwtMockito.
40 | *
41 | * Created by dewanto on 29.05.2017.
42 | */
43 | @RunWith(GwtMockitoTestRunner.class)
44 | public class PersonPanelViewTest {
45 |
46 | // CUT: Class Under Test
47 | private PersonPanelView view;
48 |
49 | @Mock
50 | private ErrorFormatter errorFormatter;
51 |
52 | @Mock
53 | private LoadingMessagePopupPanel loadingMessagePopupPanel;
54 |
55 | @Mock
56 | private EventBus eventBus;
57 |
58 | @Mock
59 | private PersonClient personClient;
60 |
61 | @Mock
62 | private Option mustardOption;
63 |
64 | @Before
65 | public void setUp() throws Exception {
66 | // CUT create
67 | view = new PersonPanelView(eventBus, errorFormatter,
68 | loadingMessagePopupPanel, personClient);
69 |
70 | // Create a spy on the view to mock view.runtimer()
71 | view = spy(view);
72 | }
73 |
74 | /**
75 | * Partial Mocking using Spy in the method: runTimerRefreshButton.
76 | *
77 | * @throws Exception
78 | */
79 | @Test
80 | public void testOnButtonClickNoSelectedFoodRuntimerTrue() throws Exception {
81 | // Prepare
82 | // Empty list no food selected
83 | List