Polish
This commit is contained in:
@@ -47,28 +47,28 @@ public class UserEntityTests {
|
||||
private TestEntityManager entityManager;
|
||||
|
||||
@Test
|
||||
public void createWhenUsernameIsNullShouldThrowException() throws Exception {
|
||||
public void createWhenUsernameIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Username must not be empty");
|
||||
new User(null, VIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenUsernameIsEmptyShouldThrowException() throws Exception {
|
||||
public void createWhenUsernameIsEmptyShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Username must not be empty");
|
||||
new User("", VIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenVinIsNullShouldThrowException() throws Exception {
|
||||
public void createWhenVinIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("VIN must not be null");
|
||||
new User("sboot", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveShouldPersistData() throws Exception {
|
||||
public void saveShouldPersistData() {
|
||||
User user = this.entityManager.persistFlushFind(new User("sboot", VIN));
|
||||
assertThat(user.getUsername()).isEqualTo("sboot");
|
||||
assertThat(user.getVin()).isEqualTo(VIN);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class UserRepositoryTests {
|
||||
private UserRepository repository;
|
||||
|
||||
@Test
|
||||
public void findByUsernameShouldReturnUser() throws Exception {
|
||||
public void findByUsernameShouldReturnUser() {
|
||||
this.entityManager.persist(new User("sboot", VIN));
|
||||
User user = this.repository.findByUsername("sboot");
|
||||
assertThat(user.getUsername()).isEqualTo("sboot");
|
||||
@@ -53,7 +53,7 @@ public class UserRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByUsernameWhenNoUserShouldReturnNull() throws Exception {
|
||||
public void findByUsernameWhenNoUserShouldReturnNull() {
|
||||
this.entityManager.persist(new User("sboot", VIN));
|
||||
User user = this.repository.findByUsername("mmouse");
|
||||
assertThat(user).isNull();
|
||||
|
||||
@@ -38,34 +38,34 @@ public class VehicleIdentificationNumberTests {
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenVinIsNullShouldThrowException() throws Exception {
|
||||
public void createWhenVinIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("VIN must not be null");
|
||||
new VehicleIdentificationNumber(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenVinIsMoreThan17CharsShouldThrowException() throws Exception {
|
||||
public void createWhenVinIsMoreThan17CharsShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("VIN must be exactly 17 characters");
|
||||
new VehicleIdentificationNumber("012345678901234567");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenVinIsLessThan17CharsShouldThrowException() throws Exception {
|
||||
public void createWhenVinIsLessThan17CharsShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("VIN must be exactly 17 characters");
|
||||
new VehicleIdentificationNumber("0123456789012345");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringShouldReturnVin() throws Exception {
|
||||
public void toStringShouldReturnVin() {
|
||||
VehicleIdentificationNumber vin = new VehicleIdentificationNumber(SAMPLE_VIN);
|
||||
assertThat(vin.toString()).isEqualTo(SAMPLE_VIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsAndHashCodeShouldBeBasedOnVin() throws Exception {
|
||||
public void equalsAndHashCodeShouldBeBasedOnVin() {
|
||||
VehicleIdentificationNumber vin1 = new VehicleIdentificationNumber(SAMPLE_VIN);
|
||||
VehicleIdentificationNumber vin2 = new VehicleIdentificationNumber(SAMPLE_VIN);
|
||||
VehicleIdentificationNumber vin3 = new VehicleIdentificationNumber(
|
||||
|
||||
@@ -58,15 +58,14 @@ public class RemoteVehicleDetailsServiceTests {
|
||||
private MockRestServiceServer server;
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsWhenVinIsNullShouldThrowException() throws Exception {
|
||||
public void getVehicleDetailsWhenVinIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("VIN must not be null");
|
||||
this.service.getVehicleDetails(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails()
|
||||
throws Exception {
|
||||
public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() {
|
||||
this.server.expect(requestTo("/vehicle/" + VIN + "/details"))
|
||||
.andRespond(withSuccess(getClassPathResource("vehicledetails.json"),
|
||||
MediaType.APPLICATION_JSON));
|
||||
@@ -77,8 +76,7 @@ public class RemoteVehicleDetailsServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsWhenResultIsNotFoundShouldThrowException()
|
||||
throws Exception {
|
||||
public void getVehicleDetailsWhenResultIsNotFoundShouldThrowException() {
|
||||
this.server.expect(requestTo("/vehicle/" + VIN + "/details"))
|
||||
.andRespond(withStatus(HttpStatus.NOT_FOUND));
|
||||
this.thrown.expect(VehicleIdentificationNumberNotFoundException.class);
|
||||
@@ -86,8 +84,7 @@ public class RemoteVehicleDetailsServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsWhenResultIServerErrorShouldThrowException()
|
||||
throws Exception {
|
||||
public void getVehicleDetailsWhenResultIServerErrorShouldThrowException() {
|
||||
this.server.expect(requestTo("/vehicle/" + VIN + "/details"))
|
||||
.andRespond(withServerError());
|
||||
this.thrown.expect(HttpServerErrorException.class);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class UserVehicleControllerApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void welcomeCommandLineRunnerShouldBeAvailable() throws Exception {
|
||||
public void welcomeCommandLineRunnerShouldBeAvailable() {
|
||||
// Since we're a @SpringBootTest all beans should be available.
|
||||
assertThat(this.applicationContext.getBean(WelcomeCommandLineRunner.class))
|
||||
.isNotNull();
|
||||
|
||||
@@ -47,7 +47,7 @@ public class UserVehicleControllerSeleniumTests {
|
||||
private UserVehicleService userVehicleService;
|
||||
|
||||
@Test
|
||||
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
|
||||
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() {
|
||||
given(this.userVehicleService.getVehicleDetails("sboot"))
|
||||
.willReturn(new VehicleDetails("Honda", "Civic"));
|
||||
this.webDriver.get("/sboot/vehicle.html");
|
||||
|
||||
@@ -101,7 +101,7 @@ public class UserVehicleControllerTests {
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||
public void welcomeCommandLineRunnerShouldBeAvailable() throws Exception {
|
||||
public void welcomeCommandLineRunnerShouldBeAvailable() {
|
||||
// Since we're a @WebMvcTest WelcomeCommandLineRunner should not be available.
|
||||
assertThat(this.applicationContext.getBean(WelcomeCommandLineRunner.class));
|
||||
}
|
||||
|
||||
@@ -61,23 +61,21 @@ public class UserVehicleServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsWhenUsernameIsNullShouldThrowException()
|
||||
throws Exception {
|
||||
public void getVehicleDetailsWhenUsernameIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Username must not be null");
|
||||
this.service.getVehicleDetails(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsWhenUsernameNotFoundShouldThrowException()
|
||||
throws Exception {
|
||||
public void getVehicleDetailsWhenUsernameNotFoundShouldThrowException() {
|
||||
given(this.userRepository.findByUsername(anyString())).willReturn(null);
|
||||
this.thrown.expect(UserNameNotFoundException.class);
|
||||
this.service.getVehicleDetails("sboot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVehicleDetailsShouldReturnMakeAndModel() throws Exception {
|
||||
public void getVehicleDetailsShouldReturnMakeAndModel() {
|
||||
given(this.userRepository.findByUsername(anyString()))
|
||||
.willReturn(new User("sboot", VIN));
|
||||
VehicleDetails details = new VehicleDetails("Honda", "Civic");
|
||||
|
||||
Reference in New Issue
Block a user