Skip to content

Commit

Permalink
Test Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ohbus committed Nov 21, 2022
1 parent b5baaa2 commit 1da8d6d
Show file tree
Hide file tree
Showing 23 changed files with 2,100 additions and 1,720 deletions.
34 changes: 24 additions & 10 deletions src/test/java/xyz/subho/lunchbooking/config/AsyncConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Lunch Booking - Lunch Booking REST Application
* Copyright © 2022 Subhrodip Mohanta ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package xyz.subho.lunchbooking.config;

import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -12,15 +30,11 @@
@ContextConfiguration(classes = {AsyncConfig.class})
@ExtendWith(SpringExtension.class)
class AsyncConfigTest {
@Autowired
private AsyncConfig asyncConfig;
@Autowired private AsyncConfig asyncConfig;

/**
* Method under test: {@link AsyncConfig#taskExecutor()}
*/
@Test
void testTaskExecutor() {
assertTrue(asyncConfig.taskExecutor() instanceof ThreadPoolTaskExecutor);
}
/** Method under test: {@link AsyncConfig#taskExecutor()} */
@Test
void testTaskExecutor() {
assertTrue(asyncConfig.taskExecutor() instanceof ThreadPoolTaskExecutor);
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
/*
* Lunch Booking - Lunch Booking REST Application
* Copyright © 2022 Subhrodip Mohanta ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package xyz.subho.lunchbooking.controllers;

import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.when;

import java.security.Principal;
import java.time.LocalDate;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,109 +41,96 @@
@ContextConfiguration(classes = {BookingController.class})
@ExtendWith(SpringExtension.class)
class BookingControllerTest {
@Autowired
private BookingController bookingController;
@Autowired private BookingController bookingController;

@MockBean
private BookingService bookingService;
@MockBean private BookingService bookingService;

/**
* Method under test: {@link BookingController#availBooking(long)}
*/
@Test
void testAvailBooking() throws Exception {
when(bookingService.availBooking(anyLong()))
.thenReturn(new BookingResponseModel(123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L));
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/booking/avail/{bookingId}", 123L);
MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andExpect(MockMvcResultMatchers.content()
.string(
"{\"id\":123,\"firstName\":\"Jane\",\"lastName\":\"Doe\",\"date\":[1970,1,2],\"mealOption\":\"Meal Option\",\"mealOptionId"
+ "\":123,\"availedAt\":1}"));
}
/** Method under test: {@link BookingController#availBooking(long)} */
@Test
void testAvailBooking() throws Exception {
when(bookingService.availBooking(anyLong()))
.thenReturn(
new BookingResponseModel(
123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L));
MockHttpServletRequestBuilder requestBuilder =
MockMvcRequestBuilders.put("/booking/avail/{bookingId}", 123L);
MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andExpect(
MockMvcResultMatchers.content()
.string(
"{\"id\":123,\"firstName\":\"Jane\",\"lastName\":\"Doe\",\"date\":[1970,1,2],\"mealOption\":\"Meal Option\",\"mealOptionId"
+ "\":123,\"availedAt\":1}"));
}

/**
* Method under test: {@link BookingController#availBooking(long)}
*/
@Test
void testAvailBooking2() throws Exception {
when(bookingService.availBooking(anyLong()))
.thenReturn(new BookingResponseModel(123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L));
SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders
.formLogin();
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound());
}
/** Method under test: {@link BookingController#availBooking(long)} */
@Test
void testAvailBooking2() throws Exception {
when(bookingService.availBooking(anyLong()))
.thenReturn(
new BookingResponseModel(
123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L));
SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder =
SecurityMockMvcRequestBuilders.formLogin();
ResultActions actualPerformResult =
MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound());
}

/**
* Method under test: {@link BookingController#cancelBooking(long, Principal)}
*/
@Test
void testCancelBooking() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/booking/{bookingId}",
"Uri Variables", "Uri Variables");
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}
/** Method under test: {@link BookingController#cancelBooking(long, Principal)} */
@Test
void testCancelBooking() throws Exception {
MockHttpServletRequestBuilder requestBuilder =
MockMvcRequestBuilders.delete("/booking/{bookingId}", "Uri Variables", "Uri Variables");
ResultActions actualPerformResult =
MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}

/**
* Method under test: {@link BookingController#createBooking(long, Principal)}
*/
@Test
void testCreateBooking() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/booking/create/{mealOptionId}",
"Uri Variables", "Uri Variables");
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}
/** Method under test: {@link BookingController#createBooking(long, Principal)} */
@Test
void testCreateBooking() throws Exception {
MockHttpServletRequestBuilder requestBuilder =
MockMvcRequestBuilders.post(
"/booking/create/{mealOptionId}", "Uri Variables", "Uri Variables");
ResultActions actualPerformResult =
MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}

/**
* Method under test: {@link BookingController#createBookingFromAvailableOptions(long, Principal)}
*/
@Test
void testCreateBookingFromAvailableOptions() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/booking/pickup/{mealOptionId}",
"Uri Variables", "Uri Variables");
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}
/**
* Method under test: {@link BookingController#createBookingFromAvailableOptions(long, Principal)}
*/
@Test
void testCreateBookingFromAvailableOptions() throws Exception {
MockHttpServletRequestBuilder requestBuilder =
MockMvcRequestBuilders.put(
"/booking/pickup/{mealOptionId}", "Uri Variables", "Uri Variables");
ResultActions actualPerformResult =
MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}

/**
* Method under test: {@link BookingController#getAllBookingsForDate(LocalDate)}
*/
@Test
void testGetAllBookingsForDate() throws Exception {
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/booking/{date}",
LocalDate.ofEpochDay(1L));
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}
/** Method under test: {@link BookingController#getAllBookingsForDate(LocalDate)} */
@Test
void testGetAllBookingsForDate() throws Exception {
MockHttpServletRequestBuilder requestBuilder =
MockMvcRequestBuilders.get("/booking/{date}", LocalDate.ofEpochDay(1L));
ResultActions actualPerformResult =
MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400));
}

/**
* Method under test: {@link BookingController#getTodayBookingForUser(Principal)}
*/
@Test
void testGetTodayBookingForUser() throws Exception {
SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders
.formLogin();
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController)
.build()
.perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound());
}
/** Method under test: {@link BookingController#getTodayBookingForUser(Principal)} */
@Test
void testGetTodayBookingForUser() throws Exception {
SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder =
SecurityMockMvcRequestBuilders.formLogin();
ResultActions actualPerformResult =
MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder);
actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound());
}
}

Loading

0 comments on commit 1da8d6d

Please sign in to comment.