2bittester/rbp-data-set huggingface dataset:
Question: How does the method queryCredentials work for AuthDB?
Answer:
public Boolean queryCredentials(Auth auth) throws SQLException
{
    PreparedStatement ps = connection.prepareStatement(SELECT_BY_CREDENTIALS);
    ps.setString(1, auth.getUsername());
    ps.setString(2, auth.getPassword());
    ResultSet result = ps.executeQuery();
    result.next();
    return result.getRow() > 0;
}
Question: How does the method executeSqlFile work for AuthDB?
Answer:
private void executeSqlFile(String filename) throws IOException, SQLException
{
    Reader reader = new InputStreamReader(new ClassPathResource(filename).getInputStream());
    Scanner sc = new Scanner(reader);
    StringBuffer sb = new StringBuffer();
    while (sc.hasNext()) {
        sb.append(sc.nextLine());
    }
    connection.prepareStatement(sb.toString()).executeUpdate();
}
Question: How does the method resetDB work for AuthDB?
Answer:
public void resetDB() throws SQLException, IOException
{
    PreparedStatement ps = connection.prepareStatement(DELETE_ALL_TOKENS);
    ps.executeUpdate();
    executeSqlFile("seed.sql");
}
Question: What package does AuthController belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for AuthController
Answer:
@RestController
public class AuthController {

}
Question: List variables declared in AuthController
Answer:
@Autowired
private AuthService authService;
Question: How does the method createToken work for AuthController?
Answer:
@RequestMapping
public ResponseEntity<Token> createToken(@RequestBody Auth auth, HttpServletResponse response) throws SQLException
{
    Decision decision = authService.queryCredentials(auth);
    if (decision.getStatus() == HttpStatus.OK) {
        Cookie cookie = new Cookie("token", decision.getToken().getToken());
        cookie.setPath("/");
        response.addCookie(cookie);
        return ResponseEntity.ok().build();
    } else {
        return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null);
    }
}
Question: How does the method validateToken work for AuthController?
Answer:
@RequestMapping
public ResponseEntity<Token> validateToken(@RequestBody Token token) throws SQLException
{
    HttpStatus httpStatus = authService.verify(token);
    return ResponseEntity.status(httpStatus).build();
}
Question: How does the method clearToken work for AuthController?
Answer:
@RequestMapping
public ResponseEntity clearToken(@RequestBody Token token) throws SQLException
{
    HttpStatus httpStatus = authService.deleteToken(token);
    return ResponseEntity.status(httpStatus).build();
}
Question: What package does AuthApplication belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for AuthApplication
Answer:
@SpringBootApplication
@ComponentScan
public class AuthApplication {

}
Question: How does the method main work for AuthApplication?
Answer:
public static void main(String[] args)
{
    SpringApplication.run(AuthApplication.class, args);
}
Question: How does the method openAPI work for SwaggerConfig?
Answer:
@Bean
public OpenAPI openAPI()
{
    return new OpenAPI().addServersItem(new Server().url("/auth/"));
}
Question: How does the method publicApi work for SwaggerConfig?
Answer:
@Bean
public GroupedOpenApi publicApi()
{
    return GroupedOpenApi.builder().group("auth-api").pathsToMatch("/**").build();
}
Question: How does the method startScheduler work for DatabaseScheduler?
Answer:
public void startScheduler(AuthDB authDB, TimeUnit timeUnit)
{
    if (resetCount > 0) {
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        Runnable r = () -> {
            if (!stop) {
                try {
                    logger.info("Resetting database");
                    authDB.resetDB();
                } catch (Exception e) {
                    logger.error("Scheduler failed " + e.getMessage());
                }
            }
        };
        executor.scheduleAtFixedRate(r, 0L, resetCount, timeUnit);
    } else {
        logger.info("No env var was set for DB refresh (or set as 0) so not running DB reset");
    }
}
Question: What package does AuthService belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for AuthService
Answer:
@Service
public class AuthService {

}
Question: List variables declared in AuthService
Answer:
@Autowired
private AuthDB authDB;
Question: How does the method beginDbScheduler work for AuthService?
Answer:
@EventListener
public void beginDbScheduler()
{
    DatabaseScheduler databaseScheduler = new DatabaseScheduler();
    databaseScheduler.startScheduler(authDB, TimeUnit.MINUTES);
}
Question: How does the method verify work for AuthService?
Answer:
public HttpStatus verify(Token token) throws SQLException
{
    System.out.println(token.toString());
    Token returnedToken = authDB.queryToken(token);
    if (returnedToken != null) {
        return HttpStatus.OK;
    } else {
        return HttpStatus.FORBIDDEN;
    }
}
Question: How does the method deleteToken work for AuthService?
Answer:
public HttpStatus deleteToken(Token token) throws SQLException
{
    Boolean successfulDeletion = authDB.deleteToken(token);
    if (successfulDeletion) {
        return HttpStatus.OK;
    } else {
        return HttpStatus.NOT_FOUND;
    }
}
Question: How does the method queryCredentials work for AuthService?
Answer:
public Decision queryCredentials(Auth auth) throws SQLException
{
    if (authDB.queryCredentials(auth)) {
        Token token = new Token(new RandomString(16, ThreadLocalRandom.current()).nextString());
        Boolean successfulStorage = authDB.insertToken(token);
        if (successfulStorage) {
            return new Decision(HttpStatus.OK, token);
        } else {
            return new Decision(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    } else {
        return new Decision(HttpStatus.FORBIDDEN);
    }
}
Question: What package does RandomString belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for RandomString
Answer:
public class RandomString {

}
Question: What is the variable upper assigned to in RandomString?
Answer:
public String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Question: What is the variable lower assigned to in RandomString?
Answer:
public String lower = upper.toLowerCase(Locale.ENGLISH);
Question: What is the variable digits assigned to in RandomString?
Answer:
public String digits = "0123456789";
Question: What is the variable alphanum assigned to in RandomString?
Answer:
public String alphanum = upper + lower + digits;
Question: List variables declared in RandomString
Answer:
private Random random;
Question: List variables declared in RandomString
Answer:
private char symbols;
Question: List variables declared in RandomString
Answer:
private char buf;
Question: How does the method nextString work for RandomString?
Answer:
public String nextString()
{
    for (int idx = 0; idx < buf.length; ++idx) buf[idx] = symbols[random.nextInt(symbols.length)];
    return new String(buf);
}
Question: What package does BaseTest belong to
Answer:
package com.automationintesting.unit;
Question: List variables declared in BaseTest
Answer:
protected BookingDB bookingDB;
Question: How does the method createBookingDb work for BaseTest?
Answer:
@BeforeAll
public static void createBookingDb() throws SQLException, IOException
{
    if (!dbOpen) {
        bookingDB = new BookingDB();
        dbOpen = true;
    }
    bookingDB.resetDB();
}
Question: List variables declared in SqlTest
Answer:
private int currentBookingId;
Question: How does the method resetDb work for SqlTest?
Answer:
@BeforeEach
public void resetDb() throws SQLException, IOException
{
    bookingDB.resetDB();
    Booking booking = new Booking.BookingBuilder().setRoomid(1).setFirstname("James").setLastname("Dean").setDepositpaid(true).setCheckin(LocalDate.of(2018, Month.FEBRUARY, 26)).setCheckout(LocalDate.of(2018, Month.FEBRUARY, 26)).build();
    CreatedBooking createdBooking = bookingDB.create(booking);
    currentBookingId = createdBooking.getBookingid();
}
Question: How does the method testQuerySql work for SqlTest?
Answer:
@Test
public void testQuerySql() throws SQLException
{
    Booking booking = bookingDB.query(currentBookingId);
    String bookingString = booking.toString();
    assertThat(bookingString, is("Booking{roomid=1, firstname='James', lastname='Dean', depositpaid=true, bookingDates=BookingDates{checkin=2018-02-26, checkout=2018-02-26}}"));
}
Question: How does the method testCreateSql work for SqlTest?
Answer:
@Test
public void testCreateSql() throws SQLException
{
    Booking booking = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(LocalDate.of(2013, Month.JANUARY, 31)).setCheckout(LocalDate.of(2013, Month.JANUARY, 31)).build();
    CreatedBooking createdBooking = bookingDB.create(booking);
    String createdBookingString = createdBooking.toString();
    assertThat(createdBookingString, is("CreatedBooking{bookingid=" + (currentBookingId + 1) + ", booking=Booking{roomid=1, firstname='Mark', lastname='Winteringham', depositpaid=true, bookingDates=BookingDates{checkin=2013-01-31, checkout=2013-01-31}}}"));
}
Question: How does the method testDeleteSql work for SqlTest?
Answer:
@Test
public void testDeleteSql() throws SQLException
{
    boolean result = bookingDB.delete(currentBookingId);
    assertThat(result, is(true));
}
Question: How does the method testUpdateSql work for SqlTest?
Answer:
@Test
public void testUpdateSql() throws SQLException
{
    Booking booking = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(LocalDate.of(2013, Month.JANUARY, 31)).setCheckout(LocalDate.of(2013, Month.JANUARY, 31)).build();
    CreatedBooking updatedBooking = bookingDB.update(currentBookingId, booking);
    String updatedBookingString = updatedBooking.toString();
    assertThat(updatedBookingString, is("CreatedBooking{bookingid=" + currentBookingId + ", booking=Booking{roomid=1, firstname='Mark', lastname='Winteringham', depositpaid=true, bookingDates=BookingDates{checkin=2013-01-31, checkout=2013-01-31}}}"));
}
Question: What package does MessageBuilderTest belong to
Answer:
package com.automationintesting.unit.model;
Question: What is the class declaration for MessageBuilderTest
Answer:
public class MessageBuilderTest {

}
Question: How does the method messageBuiltFromBookingTest work for MessageBuilderTest?
Answer:
@Test
public void messageBuiltFromBookingTest()
{
    LocalDate checkindate = LocalDate.of(1990, Month.FEBRUARY, 1);
    LocalDate checkoutdate = LocalDate.of(1990, Month.FEBRUARY, 2);
    Booking booking = new Booking.BookingBuilder().setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(checkindate).setCheckout(checkoutdate).setEmail("mark@mwtestconsultancy.co.uk").setPhone("01392123928").build();
    MessageBuilder messageBuilder = new MessageBuilder();
    Message message = messageBuilder.build(booking);
    assertThat(message.toString(), is("Message{, name='Mark Winteringham', email='mark@mwtestconsultancy.co.uk', phone='01392123928', subject='You have a new booking!', description='You have a new booking from Mark Winteringham. They have booked a room for the following dates: 1990-02-01 to 1990-02-02'}"));
}
Question: What package does DateConflictTest belong to
Answer:
package com.automationintesting.unit.db;
Question: What is the class declaration for DateConflictTest
Answer:
public class DateConflictTest {

}
Question: How does the method resetDb work for DateConflictTest?
Answer:
@BeforeEach
public void resetDb() throws SQLException, IOException
{
    bookingDB.resetDB();
}
Question: How does the method testBookingWithNoConflict work for DateConflictTest?
Answer:
@Test
public void testBookingWithNoConflict() throws SQLException
{
    LocalDate checkin = LocalDate.of(2100, Month.JANUARY, 1);
    LocalDate checkout = LocalDate.of(2100, Month.JANUARY, 5);
    Booking booking = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(checkin).setCheckout(checkout).build();
    Boolean noConflict = bookingDB.checkForBookingConflict(booking);
    assertThat(noConflict, is(false));
}
Question: How does the method testConflictingBooking work for DateConflictTest?
Answer:
@Test
public void testConflictingBooking() throws SQLException
{
    LocalDate bookingOneCheckin = LocalDate.of(2018, Month.JANUARY, 1);
    LocalDate bookingOneCheckout = LocalDate.of(2018, Month.JANUARY, 5);
    LocalDate bookingTwoCheckin = LocalDate.of(2018, Month.JANUARY, 1);
    LocalDate bookingTwoCheckout = LocalDate.of(2018, Month.JANUARY, 5);
    Booking bookingOne = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingOneCheckin).setCheckout(bookingOneCheckout).build();
    CreatedBooking booking = bookingDB.create(bookingOne);
    Booking bookingTwo = new Booking.BookingBuilder().setBookingid(booking.getBookingid() + 1).setRoomid(1).setFirstname("James").setLastname("Dean").setDepositpaid(true).setCheckin(bookingTwoCheckin).setCheckout(bookingTwoCheckout).build();
    Boolean conflict = bookingDB.checkForBookingConflict(bookingTwo);
    assertThat(conflict, is(true));
}
Question: How does the method testPartialConflict work for DateConflictTest?
Answer:
@Test
public void testPartialConflict() throws SQLException
{
    LocalDate bookingOneCheckin = LocalDate.of(2018, Month.JANUARY, 1);
    LocalDate bookingOneCheckout = LocalDate.of(2018, Month.JANUARY, 5);
    LocalDate bookingTwoCheckin = LocalDate.of(2018, Month.JANUARY, 3);
    LocalDate bookingTwoCheckout = LocalDate.of(2018, Month.JANUARY, 8);
    Booking bookingOne = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingOneCheckin).setCheckout(bookingOneCheckout).build();
    CreatedBooking booking = bookingDB.create(bookingOne);
    Booking bookingTwo = new Booking.BookingBuilder().setBookingid(booking.getBookingid() + 1).setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingTwoCheckin).setCheckout(bookingTwoCheckout).build();
    Boolean conflict = bookingDB.checkForBookingConflict(bookingTwo);
    assertThat(conflict, is(true));
}
Question: How does the method testConflictForSpecificRoom work for DateConflictTest?
Answer:
@Test
public void testConflictForSpecificRoom() throws SQLException
{
    LocalDate bookingOneCheckin = LocalDate.of(2018, Month.JANUARY, 1);
    LocalDate bookingOneCheckout = LocalDate.of(2018, Month.JANUARY, 5);
    LocalDate bookingTwoCheckin = LocalDate.of(2018, Month.JANUARY, 1);
    LocalDate bookingTwoCheckout = LocalDate.of(2018, Month.JANUARY, 5);
    Booking bookingOne = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingOneCheckin).setCheckout(bookingOneCheckout).build();
    Booking bookingTwo = new Booking.BookingBuilder().setRoomid(2).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingTwoCheckin).setCheckout(bookingTwoCheckout).build();
    bookingDB.create(bookingOne);
    Boolean conflict = bookingDB.checkForBookingConflict(bookingTwo);
    assertThat(conflict, is(false));
}
Question: How does the method testNoConflictForOverlapOnCheckoutCheckinDate work for DateConflictTest?
Answer:
@Test
public void testNoConflictForOverlapOnCheckoutCheckinDate() throws SQLException
{
    LocalDate bookingOneCheckin = LocalDate.of(2018, Month.JANUARY, 1);
    LocalDate bookingOneCheckout = LocalDate.of(2018, Month.JANUARY, 5);
    LocalDate bookingTwoCheckin = LocalDate.of(2018, Month.JANUARY, 5);
    LocalDate bookingTwoCheckout = LocalDate.of(2018, Month.JANUARY, 7);
    Booking bookingOne = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingOneCheckin).setCheckout(bookingOneCheckout).build();
    Booking bookingTwo = new Booking.BookingBuilder().setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(bookingTwoCheckin).setCheckout(bookingTwoCheckout).build();
    bookingDB.create(bookingOne);
    Boolean conflict = bookingDB.checkForBookingConflict(bookingTwo);
    assertThat(conflict, is(false));
}
Question: How does the method testNoConflictIfReturnedBookingIsSameRoom work for DateConflictTest?
Answer:
@Test
public void testNoConflictIfReturnedBookingIsSameRoom() throws SQLException
{
    int currentBookingCount = bookingDB.queryAllBookings().size();
    LocalDate checkin = LocalDate.of(2100, Month.JANUARY, 1);
    LocalDate checkout = LocalDate.of(2100, Month.JANUARY, 5);
    Booking booking = new Booking.BookingBuilder().setBookingid(currentBookingCount + 1).setRoomid(1).setFirstname("Mark").setLastname("Winteringham").setDepositpaid(true).setCheckin(checkin).setCheckout(checkout).build();
    bookingDB.create(booking);
    Boolean conflict = bookingDB.checkForBookingConflict(booking);
    assertThat(conflict, is(false));
}
Question: What package does DateCheckValidatorTest belong to
Answer:
package com.automationintesting.unit.service;
Question: What is the class declaration for DateCheckValidatorTest
Answer:
public class DateCheckValidatorTest {

}
Question: List variables declared in DateCheckValidatorTest
Answer:
private DateCheckValidator dateCheckValidator;
Question: List variables declared in DateCheckValidatorTest
Answer:
private BookingDates bookingDates;
Question: How does the method setup work for DateCheckValidatorTest?
Answer:
@BeforeEach
public void setup()
{
    dateCheckValidator = new DateCheckValidator();
    bookingDates = new BookingDates();
}
Question: How does the method invalidIfDatesNotProvided work for DateCheckValidatorTest?
Answer:
@Test
public void invalidIfDatesNotProvided()
{
    boolean validDate = dateCheckValidator.isValid(bookingDates);
    assertThat("Should be invalid if dates not provided", !validDate);
}
Question: How does the method invalidIfCheckinAfterCheckout work for DateCheckValidatorTest?
Answer:
@Test
public void invalidIfCheckinAfterCheckout()
{
    bookingDates.setCheckout(Date.valueOf("2018-01-01").toLocalDate());
    bookingDates.setCheckin(Date.valueOf("2018-01-05").toLocalDate());
    boolean validDate = dateCheckValidator.isValid(bookingDates);
    assertThat("Should be invalid if checkin after checkout", !validDate);
}
Question: How does the method invalidIfCheckinAndCheckoutSameDay work for DateCheckValidatorTest?
Answer:
@Test
public void invalidIfCheckinAndCheckoutSameDay()
{
    bookingDates.setCheckout(Date.valueOf("2018-01-01").toLocalDate());
    bookingDates.setCheckin(Date.valueOf("2018-01-01").toLocalDate());
    boolean validDate = dateCheckValidator.isValid(bookingDates);
    assertThat("Should be invalid if checkin same date as checkout", !validDate);
}
Question: How does the method validIfCheckinBeforeCheckout work for DateCheckValidatorTest?
Answer:
@Test
public void validIfCheckinBeforeCheckout()
{
    bookingDates.setCheckin(Date.valueOf("2018-01-01").toLocalDate());
    bookingDates.setCheckout(Date.valueOf("2018-01-05").toLocalDate());
    boolean validDate = dateCheckValidator.isValid(bookingDates);
    assertThat("Should be valid if checkin before checkout", validDate);
}
Question: What package does BookingServiceTest belong to
Answer:
package com.automationintesting.unit.service;
Question: What is the class declaration for BookingServiceTest
Answer:
public class BookingServiceTest {

}
Question: List variables declared in BookingServiceTest
Answer:
@Mock
private AuthRequests authRequests;
Question: List variables declared in BookingServiceTest
Answer:
@Mock
private BookingDB bookingDB;
Question: List variables declared in BookingServiceTest
Answer:
@Mock
private DateCheckValidator dateCheckValidator;
Question: List variables declared in BookingServiceTest
Answer:
@InjectMocks
@Autowired
private BookingService bookingService;
Question: How does the method initialiseMocks work for BookingServiceTest?
Answer:
@BeforeEach
public void initialiseMocks()
{
    MockitoAnnotations.openMocks(this);
}
Question: How does the method returnAllBookingsTest work for BookingServiceTest?
Answer:
@Test
public void returnAllBookingsTest() throws SQLException
{
    List<Booking> bookings = new ArrayList<Booking>() {

        {
            this.add(createGenericBooking());
            this.add(createGenericBooking());
        }
    };
    when(bookingDB.queryAllBookings()).thenReturn(bookings);
    when(authRequests.postCheckAuth("abc123")).thenReturn(true);
    Optional<String> emptyOptional = Optional.empty();
    BookingResult bookingResults = bookingService.getBookings(emptyOptional, "abc123");
    assertEquals(2, bookingResults.getBookings().getBookings().size());
}
Question: How does the method returnBookingsByRoomIdTest work for BookingServiceTest?
Answer:
@Test
public void returnBookingsByRoomIdTest() throws SQLException
{
    List<Booking> bookings = new ArrayList<Booking>() {

        {
            this.add(createGenericBooking());
        }
    };
    when(bookingDB.queryBookingsById("2")).thenReturn(bookings);
    when(authRequests.postCheckAuth("abc123")).thenReturn(true);
    Optional<String> roomid = Optional.of("2");
    BookingResult bookingResults = bookingService.getBookings(roomid, "abc123");
    assertEquals(1, bookingResults.getBookings().getBookings().size());
}
Question: How does the method returnSpecificBookingTest work for BookingServiceTest?
Answer:
@Test
public void returnSpecificBookingTest() throws SQLException
{
    Booking booking = this.createGenericBooking();
    when(bookingDB.query(2)).thenReturn(booking);
    when(authRequests.postCheckAuth("abc123")).thenReturn(true);
    BookingResult bookingResult = bookingService.getIndividualBooking(2, "abc123");
    assertEquals(HttpStatus.OK, bookingResult.getStatus());
    assertEquals("Booking{roomid=2, firstname='Mark', lastname='Dean', depositpaid=true, bookingDates=BookingDates{checkin=2019-09-01, checkout=2019-09-02}}", bookingResult.getBooking().toString());
}
Question: How does the method returnBookingNotFoundTest work for BookingServiceTest?
Answer:
@Test
public void returnBookingNotFoundTest() throws SQLException
{
    when(bookingDB.query(100)).thenThrow(new JdbcSQLNonTransientException("a", "b", "c", 1, new Throwable(), "d"));
    when(authRequests.postCheckAuth("abc123")).thenReturn(true);
    BookingResult bookingResult = bookingService.getIndividualBooking(100, "abc123");
    assertEquals(HttpStatus.NOT_FOUND, bookingResult.getStatus());
    assertNull(bookingResult.getBooking());
}
Question: How does the method deleteBookingTest work for BookingServiceTest?
Answer:
@Test
public void deleteBookingTest() throws SQLException
{
    when(authRequests.postCheckAuth("abc123")).thenReturn(true);
    when(bookingDB.delete(1)).thenReturn(true);
    HttpStatus bookingResult = bookingService.deleteBooking(1, "abc123");
    assertEquals(HttpStatus.ACCEPTED, bookingResult);
}
Question: How does the method deleteBookingNotFoundTest work for BookingServiceTest?
Answer:
@Test
public void deleteBookingNotFoundTest() throws SQLException
{
    when(authRequests.postCheckAuth("abc123")).thenReturn(true);
    when(bookingDB.delete(100)).thenReturn(false);
    HttpStatus bookingResult = bookingService.deleteBooking(100, "abc123");
    assertEquals(HttpStatus.NOT_FOUND, bookingResult);
}