Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
order-management-backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
order-management-backend
Commits
7a746815
Commit
7a746815
authored
May 11, 2021
by
Alex Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-91]
⚰
️ Trash 'Manager' model unit tests (
@asegers
)
parent
503b9bc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
83 deletions
+0
-83
ValidatableEntity.java
.../ordermanagement/UNIT_TESTS/helper/ValidatableEntity.java
+0
-49
ManagerTests.java
...om/afp/ordermanagement/UNIT_TESTS/model/ManagerTests.java
+0
-34
No files found.
src/test/java/com/afp/ordermanagement/UNIT_TESTS/helper/ValidatableEntity.java
deleted
100644 → 0
View file @
503b9bc0
package
com
.
afp
.
ordermanagement
.
UNIT_TESTS
.
helper
;
import
com.github.javafaker.Faker
;
//import com.sun.tools.javac.util.List;
import
org.junit.jupiter.api.Assertions
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
javax.validation.ConstraintViolation
;
import
javax.validation.Validation
;
import
javax.validation.Validator
;
import
java.lang.reflect.ParameterizedType
;
import
java.util.List
;
public
abstract
class
ValidatableEntity
<
E
>
{
private
final
Class
<
E
>
childClass
;
static
private
final
Faker
FAKER
=
new
Faker
();
@SuppressWarnings
(
"unchecked"
)
public
ValidatableEntity
()
{
this
.
childClass
=
(
(
Class
<
E
>)
(
(
ParameterizedType
)
this
.
getClass
()
.
getGenericSuperclass
()
)
.
getActualTypeArguments
()[
0
]
);
}
private
static
final
Validator
validator
=
Validation
.
buildDefaultValidatorFactory
().
getValidator
();
// assertFieldValidation(String fieldName, Object input, boolean isValidInput)
public
ConstraintViolation
<
E
>
createViolation
(
String
fieldName
,
Object
fieldValue
)
{
return
validator
.
validateValue
(
this
.
childClass
,
fieldName
,
fieldValue
)
.
stream
()
.
findAny
()
.
orElse
(
null
);
}
// assertFieldValidation(String fieldName, Object input, boolean isValidInput)
public
void
assertFieldValidation
(
String
fieldName
,
Object
input
,
boolean
expected
)
{
boolean
isValid
=
validator
.
validateValue
(
this
.
childClass
,
fieldName
,
input
).
isEmpty
();
String
v
=
expected
?
"valid"
:
"invalid"
;
String
errMsg
=
String
.
format
(
"Expected '%s' to be a %s value for field '%s'"
,
input
,
v
,
fieldName
);
if
(
isValid
!=
expected
)
fail
(
errMsg
);
}
}
src/test/java/com/afp/ordermanagement/UNIT_TESTS/model/ManagerTests.java
deleted
100644 → 0
View file @
503b9bc0
package
com
.
afp
.
ordermanagement
.
UNIT_TESTS
.
model
;
import
com.afp.ordermanagement.UNIT_TESTS.helper.ValidatableEntity
;
import
com.afp.ordermanagement.model.Manager
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
public
class
ManagerTests
extends
ValidatableEntity
<
Manager
>
{
@ParameterizedTest
@CsvSource
(
value
=
{
"null:false"
,
"\"\":false"
,
"Jerry:true"
},
delimiter
=
':'
)
public
void
shouldValidateNameFields
(
String
input
,
boolean
expected
)
{
assertFieldValidation
(
"firstName"
,
input
,
expected
);
assertFieldValidation
(
"lastName"
,
input
,
expected
);
}
@ParameterizedTest
@CsvSource
(
value
=
{
"null:false"
,
"\"\":false"
,
"poop:false"
,
"jerry@hotmail.com:true"
},
delimiter
=
':'
)
public
void
shouldValidateEmailField
(
String
input
,
boolean
expected
)
{
assertFieldValidation
(
"email"
,
input
,
expected
);
}
@ParameterizedTest
@CsvSource
(
value
=
{
"null:false"
,
"\"\":false"
},
delimiter
=
':'
)
public
void
shouldValidateGoogleIdField
(
String
input
,
boolean
expected
)
{
assertFieldValidation
(
"googleId"
,
input
,
expected
);
}
@ParameterizedTest
@CsvSource
(
value
=
{
"\"\",false"
,
"https://picsum.photos/200,true"
,
"htps: picsum.photos/200,false"
})
public
void
shouldValidateImageUrl
(
String
input
,
boolean
expected
)
{
assertFieldValidation
(
"imageUrl"
,
input
,
expected
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment