Skip to content

Commit 45fa88d

Browse files
unit-test case added
1 parent f28ce4d commit 45fa88d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.gourav.restApi.controllers;
2+
3+
import org.junit.runner.RunWith;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
6+
import org.springframework.boot.test.mock.mockito.MockBean;
7+
import org.springframework.test.context.junit4.SpringRunner;
8+
import org.springframework.test.web.servlet.MockMvc;
9+
10+
@RunWith(SpringRunner.class)
11+
@WebMvcTest(value = PetsController.class)
12+
public class PetsControllerTest {
13+
14+
@Autowired
15+
private MockMvc mvc;
16+
17+
@MockBean
18+
private PetsController petsController;
19+
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.gourav.restApi.models;
2+
3+
import static org.junit.Assert.*;
4+
import org.bson.types.ObjectId;
5+
import org.junit.Test;
6+
7+
public class PetsTest {
8+
9+
ObjectId _id = ObjectId.get();
10+
Pets pets = new Pets();
11+
12+
@Test
13+
public void testSet_id(){
14+
pets.set_id(_id);
15+
assertTrue(pets.get_id().equals(_id.toHexString()));
16+
}
17+
18+
@Test
19+
public void testSetName(){
20+
pets.setName("Liam");
21+
assertTrue(pets.getName().equals("Liam"));
22+
}
23+
24+
@Test
25+
public void testSetSpecies(){
26+
pets.setSpecies("cat");
27+
assertTrue(pets.getSpecies().equals("cat"));
28+
}
29+
30+
@Test
31+
public void testSetBreed(){
32+
pets.setBreed("tabby");
33+
assertTrue(pets.getBreed().equals("tabby"));
34+
}
35+
}

0 commit comments

Comments
 (0)