-
Notifications
You must be signed in to change notification settings - Fork 0
tema validator raffa #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MobR10
wants to merge
5
commits into
feature/controller-service-repository-test-raffa
Choose a base branch
from
feature/raffa-tema-validator
base: feature/controller-service-repository-test-raffa
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,12 @@ | |
| @SpringBootTest | ||
| @ActiveProfiles("local") | ||
| public class CarValidatorTest { | ||
|
|
||
|
|
||
| @Test | ||
| void validateCar_name_null() { | ||
| try { | ||
| CarValidator.validateCar(createCar(null)); | ||
| CarValidator.validateCar(carForMaker(null)); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(90001, e.getErrorCode()); | ||
| } | ||
|
|
@@ -28,7 +30,7 @@ void validateCar_name_null() { | |
| @Test | ||
| void validateCar_name_empty() { | ||
| try { | ||
| CarValidator.validateCar(createCar("")); | ||
| CarValidator.validateCar(carForMaker("")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(90001, e.getErrorCode()); | ||
| } | ||
|
|
@@ -38,7 +40,7 @@ void validateCar_name_empty() { | |
| @Test | ||
| void validateCar_name_over_15() { | ||
| try { | ||
| CarValidator.validateCar(createCar("Kiewjiejfiejefwefwewef")); | ||
| CarValidator.validateCar(carForMaker("Kiewjiejfiejefwefwewef")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(90002, e.getErrorCode()); | ||
| } | ||
|
|
@@ -48,7 +50,7 @@ void validateCar_name_over_15() { | |
| @Test | ||
| void validateCar_name_firstChar_lowerCase() { | ||
| try { | ||
| CarValidator.validateCar(createCar("mercedes")); | ||
| CarValidator.validateCar(carForMaker("mercedes")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(90003, e.getErrorCode()); | ||
| } | ||
|
|
@@ -57,18 +59,201 @@ void validateCar_name_firstChar_lowerCase() { | |
|
|
||
| @Test | ||
| void validateCar_name_okay() { | ||
| Boolean result = CarValidator.validateCar(createCar("Mercedes")); | ||
| Boolean result = CarValidator.validateCar(carForMaker("Mercedes")); | ||
| assertTrue(result); | ||
| } | ||
|
|
||
| Car createCar(String maker) { | ||
| @Test | ||
| void validateCar_model_null() { | ||
| try { | ||
| CarValidator.validateCar(carForModel(null)); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9008, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_model_empty() { | ||
| try { | ||
| CarValidator.validateCar(carForModel("")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9008, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_model_firstChar_lowerCase() { | ||
| try { | ||
| CarValidator.validateCar(carForModel("toronto")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9009, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_model_ok() { | ||
| assertTrue(CarValidator.validateCar(carForMaker("Toronto"))); | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_color_null() { | ||
| try { | ||
| CarValidator.validateCar(carForColor(null)); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9010, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_color_empty() { | ||
| try { | ||
| CarValidator.validateCar(carForColor("")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9010, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_color_firstChar_lowerCase() { | ||
| try { | ||
| CarValidator.validateCar(carForColor("color")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9011, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_color_ok() { | ||
| assertTrue(CarValidator.validateCar(carForColor("Color"))); | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_year_is0() { | ||
| try { | ||
| CarValidator.validateCar(carForYear(0)); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9007, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_year_over_current_year() { | ||
| try { | ||
| CarValidator.validateCar(carForYear(2024)); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9012, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_year_ok() { | ||
| assertTrue(CarValidator.validateCar(carForYear(2005))); | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_price_is0() { | ||
| try { | ||
| CarValidator.validateCar(carForPrice(BigDecimal.valueOf(0))); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9006, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_price_ok() { | ||
| assertTrue(CarValidator.validateCar(carForPrice(BigDecimal.valueOf(250000)))); | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_currency_null() { | ||
| try { | ||
| CarValidator.validateCar(carForCurrency(null)); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9004, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_currency_empty() { | ||
| try { | ||
| CarValidator.validateCar(carForCurrency("")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9004, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void validateCar_incorrect_currency() { | ||
| try { | ||
| CarValidator.validateCar(carForCurrency("RON")); | ||
| } catch (CarValidatorException e) { | ||
| assertEquals(9005, e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| Car carForMaker(String maker) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can move all these private functions and used them from a static class re-usable for all tests |
||
| Car car = new Car(); | ||
| car.setMaker(maker); | ||
| car.setColor("yellow"); | ||
| car.setModel("x5"); | ||
| car.setColor("Yellow"); | ||
| car.setModel("X5"); | ||
| car.setYear(2023); | ||
| car.setCurrency("EUR"); | ||
| car.setPrice(BigDecimal.valueOf(98000)); | ||
| return car; | ||
| } | ||
|
|
||
| Car carForModel(String model) { | ||
| Car car = new Car(); | ||
| car.setMaker("Mercedes"); | ||
| car.setColor("Yellow"); | ||
| car.setModel(model); | ||
| car.setYear(2023); | ||
| car.setCurrency("EUR"); | ||
| car.setPrice(BigDecimal.valueOf(98000)); | ||
| return car; | ||
| } | ||
|
|
||
| Car carForColor(String color) { | ||
| Car car = new Car(); | ||
| car.setMaker("Mercedes"); | ||
| car.setColor(color); | ||
| car.setModel("X5"); | ||
| car.setYear(2023); | ||
| car.setCurrency("EUR"); | ||
| car.setPrice(BigDecimal.valueOf(98000)); | ||
| return car; | ||
| } | ||
|
|
||
| Car carForYear(Integer year) { | ||
| Car car = new Car(); | ||
| car.setMaker("Mercedes"); | ||
| car.setColor("Yellow"); | ||
| car.setModel("X5"); | ||
| car.setYear(year); | ||
| car.setCurrency("EUR"); | ||
| car.setPrice(BigDecimal.valueOf(98000)); | ||
| return car; | ||
| } | ||
|
|
||
| Car carForPrice(BigDecimal price) { | ||
| Car car = new Car(); | ||
| car.setMaker("Mercedes"); | ||
| car.setColor("Yellow"); | ||
| car.setModel("X5"); | ||
| car.setYear(2023); | ||
| car.setCurrency("EUR"); | ||
| car.setPrice(price); | ||
| return car; | ||
| } | ||
|
|
||
| Car carForCurrency(String currency) { | ||
| Car car = new Car(); | ||
| car.setMaker("Mercedes"); | ||
| car.setColor("Yellow"); | ||
| car.setModel("X5"); | ||
| car.setYear(2023); | ||
| car.setCurrency(currency); | ||
| car.setPrice(BigDecimal.valueOf(98000)); | ||
| return car; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateCar_year_null test fails because of missing year == null check in this function ?