Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
daaexample
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
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Martín Vázquez Torres
daaexample
Commits
967b883c
Commit
967b883c
authored
Mar 07, 2017
by
cyanide4all
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test for entity pet
parent
ba522393
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
+79
-0
Pet.java
src/main/java/es/uvigo/esei/daa/entities/Pet.java
+1
-0
PetUnitTest.java
src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java
+78
-0
No files found.
src/main/java/es/uvigo/esei/daa/entities/Pet.java
View file @
967b883c
...
@@ -28,6 +28,7 @@ public class Pet {
...
@@ -28,6 +28,7 @@ public class Pet {
this
.
setownerID
(
ownerID
);
this
.
setownerID
(
ownerID
);
}
}
/**
/**
* Returns the identifier of the pet.
* Returns the identifier of the pet.
*
*
...
...
src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java
0 → 100644
View file @
967b883c
package
es
.
uvigo
.
esei
.
daa
.
entities
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Created by cya on 3/7/17.
*/
public
class
PetUnitTest
{
@Test
public
void
testPetIntStringInt
()
{
final
int
id
=
1
;
final
String
name
=
"John"
;
final
int
ownerID
=
2
;
final
Pet
pet
=
new
Pet
(
id
,
name
,
ownerID
);
assertThat
(
pet
.
getId
(),
is
(
equalTo
(
id
)));
assertThat
(
pet
.
getName
(),
is
(
equalTo
(
name
)));
assertThat
(
pet
.
getownerID
(),
is
(
equalTo
(
ownerID
)));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testPetIntStringStringNullName
()
{
new
Pet
(
1
,
null
,
2
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testPetIntStringStringInvalidOwnerID
()
{
new
Pet
(
1
,
"Pet McPetface"
,
(
Integer
)
null
);
}
@Test
public
void
testSetName
()
{
final
int
id
=
1
;
final
int
ownerID
=
2
;
final
Pet
pet
=
new
Pet
(
id
,
"Mr. Friskies"
,
ownerID
);
pet
.
setName
(
"Pet McPetface"
);
assertThat
(
pet
.
getId
(),
is
(
equalTo
(
id
)));
assertThat
(
pet
.
getName
(),
is
(
equalTo
(
"Pet McPetface"
)));
assertThat
(
pet
.
getownerID
(),
is
(
equalTo
(
ownerID
)));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testSetNullName
()
{
final
Pet
pet
=
new
Pet
(
1
,
"Pet McPetface"
,
2
);
pet
.
setName
(
null
);
}
@Test
public
void
testSetOwnerID
()
{
final
int
id
=
1
;
final
String
name
=
"Pet McPetface"
;
final
Pet
pet
=
new
Pet
(
id
,
name
,
2
);
pet
.
setownerID
(
3
);
assertThat
(
pet
.
getId
(),
is
(
equalTo
(
id
)));
assertThat
(
pet
.
getName
(),
is
(
equalTo
(
name
)));
assertThat
(
pet
.
getownerID
(),
is
(
equalTo
(
3
)));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testSetNullOwnerID
()
{
final
Pet
pet
=
new
Pet
(
1
,
"Pet McPetface"
,
2
);
pet
.
setownerID
((
Integer
)
null
);
}
//TODO ownerID can't be less than 1. Also comparing and hashing methods are not implemented
}
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