Skip to content

Commit

Permalink
[refs #1] - test code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjoy-sust committed Jan 21, 2018
1 parent d9d1da9 commit 8deb67b
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions src/test/java/com/fm/assignment/repository/PlaceRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fm.assignment.core.dao.PlaceRepository;
import com.fm.assignment.core.entity.PathEntity;
import com.fm.assignment.core.entity.PlaceEntity;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,18 +19,14 @@
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class PlaceRepositoryTest {
@Autowired
PlaceRepository placeRepository;

@Test
public void addTest() {
PlaceEntity placeEntity = new PlaceEntity();
placeEntity.setName("Sylhet");
placeEntity.setCode("SYL");
placeEntity.setLatitude(24.894929);
placeEntity.setLongitude(91.868706);
PlaceEntity save = placeRepository.save(placeEntity);
PlaceEntity save = savePlaceData();
long id = save.getId();
Assert.assertNotNull(save);
placeRepository.delete(save);
Expand All @@ -44,13 +41,47 @@ public void addEmptyObj() {

@Test
public void findPathByName() {
PlaceEntity placeEntity = placeRepository.findByName("Comilla");
Assert.assertEquals(placeEntity.getName(), "Comilla");
PlaceEntity placeEntity = savePlaceData();
Assert.assertEquals(placeEntity.getName(), "DD");
}

@Test
public void findPathByVal() {
PlaceEntity placeEntity = placeRepository.findByCode("CML");
Assert.assertEquals(placeEntity.getName(), "Comilla");
PlaceEntity pe = savePlaceData();
PlaceEntity save = placeRepository.save(pe);
PlaceEntity placeEntity = placeRepository.findByCode("CMI");
Assert.assertEquals(placeEntity.getName(), "DD");
placeRepository.delete(save);
}

@Test
public void findPathByValNotExits() {
PlaceEntity placeEntity = null;
placeEntity = placeRepository.findByCode("CMI");
if(placeEntity != null)
{
placeRepository.delete(placeEntity);
PlaceEntity pe = savePlaceData();
PlaceEntity save = placeRepository.save(pe);
placeRepository.delete(save);
}
placeEntity = placeRepository.findByCode("CMI");
Assert.assertNull(placeEntity);
}

@Test(expected = NullPointerException.class)
public void findPathByValNullPointer() {
PlaceEntity placeEntity = placeRepository.findByCode("CMI");
String name = placeEntity.getName();
log.error(name);
}

private PlaceEntity savePlaceData() {
PlaceEntity pe = new PlaceEntity();
pe.setName("DD");
pe.setCode("CMI");
pe.setLatitude(23.894929);
pe.setLongitude(90.868706);
return pe;
}
}

0 comments on commit 8deb67b

Please sign in to comment.