Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
junit-testcases
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
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
Narendar Vakiti
junit-testcases
Commits
3d883d8b
Commit
3d883d8b
authored
Apr 02, 2020
by
Narendar Vakiti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
movkito testcases
parent
f754fbf6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
186 additions
and
1 deletion
+186
-1
pom.xml
pom.xml
+8
-0
Product.java
src/main/java/com/junit/bean/Product.java
+54
-0
EmployeeResource.java
src/main/java/com/junit/resource/EmployeeResource.java
+11
-1
ProductResource.java
src/main/java/com/junit/resource/ProductResource.java
+35
-0
CalculatorService.java
src/main/java/com/junit/service/CalculatorService.java
+7
-0
ProductService.java
src/main/java/com/junit/service/ProductService.java
+11
-0
ProductServiceImpl.java
src/main/java/com/junit/service/ProductServiceImpl.java
+31
-0
ProductResourceTest.java
src/test/java/com/junit/resource/ProductResourceTest.java
+29
-0
No files found.
pom.xml
View file @
3d883d8b
...
@@ -51,6 +51,14 @@
...
@@ -51,6 +51,14 @@
<version>
1.7.30
</version>
<version>
1.7.30
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-all
</artifactId>
<version>
2.0.2-beta
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
...
...
src/main/java/com/junit/bean/Product.java
0 → 100644
View file @
3d883d8b
package
com
.
junit
.
bean
;
public
class
Product
{
private
int
productId
;
private
String
productName
;
private
double
price
;
private
int
quantity
;
public
Product
()
{
}
public
Product
(
int
productId
,
String
productName
,
double
price
,
int
quantity
)
{
super
();
this
.
productId
=
productId
;
this
.
productName
=
productName
;
this
.
price
=
price
;
this
.
quantity
=
quantity
;
}
public
int
getProductId
()
{
return
productId
;
}
public
void
setProductId
(
int
productId
)
{
this
.
productId
=
productId
;
}
public
String
getProductName
()
{
return
productName
;
}
public
void
setProductName
(
String
productName
)
{
this
.
productName
=
productName
;
}
public
double
getPrice
()
{
return
price
;
}
public
void
setPrice
(
double
price
)
{
this
.
price
=
price
;
}
public
int
getQuantity
()
{
return
quantity
;
}
public
void
setQuantity
(
int
quantity
)
{
this
.
quantity
=
quantity
;
}
}
src/main/java/com/junit/resource/EmployeeResource.java
View file @
3d883d8b
...
@@ -11,6 +11,12 @@ public class EmployeeResource {
...
@@ -11,6 +11,12 @@ public class EmployeeResource {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EmployeeResource
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EmployeeResource
.
class
);
/**
* Calculate total salary per annum of each employee
* @param employee
* @return perAnnum
*/
public
double
calculateYearlySal
(
Employee
employee
)
{
public
double
calculateYearlySal
(
Employee
employee
)
{
logger
.
info
(
"Calculating Yearly Salary"
);
logger
.
info
(
"Calculating Yearly Salary"
);
double
perAnnum
=
0
;
double
perAnnum
=
0
;
...
@@ -24,7 +30,11 @@ public class EmployeeResource {
...
@@ -24,7 +30,11 @@ public class EmployeeResource {
return
perAnnum
;
return
perAnnum
;
}
}
/**
* Calculating appraisal based on salary of each employee
* @param employee
* @return appraisal
*/
public
double
calculateAppraisal
(
Employee
employee
)
{
public
double
calculateAppraisal
(
Employee
employee
)
{
logger
.
info
(
"Calculating appraisal based on salary"
);
logger
.
info
(
"Calculating appraisal based on salary"
);
double
appraisal
=
0
;
double
appraisal
=
0
;
...
...
src/main/java/com/junit/resource/ProductResource.java
0 → 100644
View file @
3d883d8b
package
com
.
junit
.
resource
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
com.junit.bean.Product
;
import
com.junit.service.ProductService
;
@Controller
public
class
ProductResource
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ProductResource
.
class
);
@Autowired
ProductService
productService
;
/**
* Get total price of product
* @return totalPrice
*/
public
double
getPrice
()
{
double
totalPrice
=
0
;
Product
pen
=
new
Product
(
101
,
"Pen"
,
15
,
10
);
try
{
totalPrice
=
productService
.
getTotalPrice
(
pen
);
logger
.
info
(
"Total Price "
+
totalPrice
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"Exception "
+
e
);
e
.
printStackTrace
();
}
return
totalPrice
;
}
}
src/main/java/com/junit/service/CalculatorService.java
0 → 100644
View file @
3d883d8b
package
com
.
junit
.
service
;
public
interface
CalculatorService
{
public
double
add
(
double
input1
,
double
input2
);
public
double
subtract
(
double
input1
,
double
input2
);
public
double
multiply
(
double
input1
,
double
input2
);
public
double
divide
(
double
input1
,
double
input2
);
}
\ No newline at end of file
src/main/java/com/junit/service/ProductService.java
0 → 100644
View file @
3d883d8b
package
com
.
junit
.
service
;
import
java.util.List
;
import
com.junit.bean.Product
;
public
interface
ProductService
{
public
List
<
Product
>
getProducts
();
public
Double
getTotalPrice
(
Product
pens
);
}
src/main/java/com/junit/service/ProductServiceImpl.java
0 → 100644
View file @
3d883d8b
package
com
.
junit
.
service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
com.junit.bean.Product
;
@Service
public
class
ProductServiceImpl
implements
ProductService
{
Product
pen
=
new
Product
(
101
,
"Pen"
,
15
,
10
);
Product
book
=
new
Product
(
102
,
"Book"
,
30
,
10
);
Product
bag
=
new
Product
(
101
,
"Bag"
,
200
,
5
);
List
<
Product
>
productList
=
new
ArrayList
<>();
@Override
public
List
<
Product
>
getProducts
()
{
productList
.
add
(
pen
);
productList
.
add
(
book
);
productList
.
add
(
bag
);
return
null
;
}
@Override
public
Double
getTotalPrice
(
Product
pens
)
{
double
toalPrice
=
pens
.
getPrice
()
*
pens
.
getQuantity
();
return
toalPrice
;
}
}
src/test/java/com/junit/resource/ProductResourceTest.java
0 → 100644
View file @
3d883d8b
package
com
.
junit
.
resource
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
org.junit.jupiter.api.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
com.junit.bean.Product
;
import
com.junit.service.ProductService
;
import
com.junit.service.ProductServiceImpl
;
class
ProductResourceTest
{
/*
* @Mock ProductService productService;
*/
@Test
void
testGetPrice
()
{
ProductService
productService
=
mock
(
ProductService
.
class
);
Product
pen
=
new
Product
(
101
,
"Pen"
,
15
,
10
);
when
(
productService
.
getTotalPrice
(
pen
)).
thenReturn
(
150.0
);
assertEquals
(
productService
.
getTotalPrice
(
pen
),
150.0
);
}
}
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