Skip to content

Commit

Permalink
Apply google java format AOSP to the test file
Browse files Browse the repository at this point in the history
  • Loading branch information
imertetsu committed Oct 2, 2024
1 parent f454552 commit 33835a3
Showing 1 changed file with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ public void testGetCarInformationLevel1_CarPresent() throws SQLException {
// return rse.extractData(mockResultSet); indicates that the ResultSetExtractor extracts the
// data from the mockResultSet (which mocks the query result)
when(jdbcTemplate.query(anyString(), any(ResultSetExtractor.class)))
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);

return rse.extractData(mockResultSet);
});
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});

// Act
ResponseEntity<String> response =
blindSQLInjectionVulnerability.getCarInformationLevel1(queryParams);
blindSQLInjectionVulnerability.getCarInformationLevel1(queryParams);

// Assert
assertEquals(HttpStatus.OK, response.getStatusCode());
Expand All @@ -73,20 +72,20 @@ public void testGetCarInformationLevel1_CarNotPresent() throws SQLException {
// return rse.extractData(mockResultSet); indicates that the ResultSetExtractor extracts the
// data from the mockResultSet (which mocks the query result)
when(jdbcTemplate.query(anyString(), any(ResultSetExtractor.class)))
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});

// Act
ResponseEntity<String> response =
blindSQLInjectionVulnerability.getCarInformationLevel1(queryParams);
blindSQLInjectionVulnerability.getCarInformationLevel1(queryParams);

// Assert
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE, response.getBody());
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE, response.getBody());
}

@Test
Expand All @@ -102,15 +101,15 @@ public void testGetCarInformationLevel2_CarPresent() throws SQLException {

// Mock the query method of JdbcTemplate
when(jdbcTemplate.query(anyString(), any(ResultSetExtractor.class)))
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});

// Act
ResponseEntity<String> response =
blindSQLInjectionVulnerability.getCarInformationLevel2(queryParams);
blindSQLInjectionVulnerability.getCarInformationLevel2(queryParams);

// Assert
assertEquals(HttpStatus.OK, response.getStatusCode());
Expand All @@ -130,20 +129,20 @@ public void testGetCarInformationLevel2_CarNotPresent() throws SQLException {

// Mock the query method of JdbcTemplate
when(jdbcTemplate.query(anyString(), any(ResultSetExtractor.class)))
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(1);
return rse.extractData(mockResultSet);
});

// Act
ResponseEntity<String> response =
blindSQLInjectionVulnerability.getCarInformationLevel2(queryParams);
blindSQLInjectionVulnerability.getCarInformationLevel2(queryParams);

// Assert
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE, response.getBody());
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE, response.getBody());
}

@Test
Expand All @@ -159,15 +158,15 @@ public void testGetCarInformationLevel3_CarPresent() throws SQLException {

// Mock the query method of JdbcTemplate
when(jdbcTemplate.query((PreparedStatementCreator) any(), any(), any(ResultSetExtractor.class)))
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(2);
return rse.extractData(mockResultSet);
});
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(2);
return rse.extractData(mockResultSet);
});

// Act
ResponseEntity<String> response =
blindSQLInjectionVulnerability.getCarInformationLevel3(queryParams);
blindSQLInjectionVulnerability.getCarInformationLevel3(queryParams);

// Assert
assertEquals(HttpStatus.OK, response.getStatusCode());
Expand All @@ -187,19 +186,20 @@ public void testGetCarInformationLevel3_CarNotPresent() throws SQLException {

// Mock the query method of JdbcTemplate
when(jdbcTemplate.query((PreparedStatementCreator) any(), any(), any(ResultSetExtractor.class)))
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(2);
return rse.extractData(mockResultSet);
});
.thenAnswer(
invocation -> {
ResultSetExtractor<ResponseEntity<String>> rse = invocation.getArgument(2);
return rse.extractData(mockResultSet);
});

// Act
ResponseEntity<String> response =
blindSQLInjectionVulnerability.getCarInformationLevel3(queryParams);
blindSQLInjectionVulnerability.getCarInformationLevel3(queryParams);

// Assert
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE, response.getBody());
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE, response.getBody());
}
}

0 comments on commit 33835a3

Please sign in to comment.