Skip to content

Commit

Permalink
Merge branch 'db-testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Oct 30, 2012
2 parents b7ce89b + 430fe99 commit 401f069
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/ee/devclub/rest/PhotoSpotResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
@Produces("application/json")
public class PhotoSpotResource extends SpringAwareResource {
@Autowired PhotoSpotRepository repo;
int maxSpots = 1000;
int maxSpots = 1000;

@GET
@GET
public List<PhotoSpot> getAllSpots() {
List<PhotoSpot> allSpots = repo.getAllSpots();
return allSpots.subList(0, Math.min(maxSpots, allSpots.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@
import org.junit.Test;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.List;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;

public class JDBCPhotoSpotRepositoryIntegrationTest {
DataSource dataSource;
Connection conn;
JDBCPhotoSpotRepository repo = new JDBCPhotoSpotRepository();

@Before
public void initMockDB() throws Exception {
dataSource = new DriverManagerDataSource("jdbc:h2:mem:test", "sa", "sa");
conn = dataSource.getConnection();
repo.dataSource = new DriverManagerDataSource("jdbc:h2:mem:test", "sa", "sa");
conn = repo.dataSource.getConnection();

conn.createStatement().execute("create table PhotoSpot (id int auto_increment primary key, name varchar, description varchar, latitude float, longitude float)");

repo.dataSource = dataSource;
}

@After
Expand Down
23 changes: 11 additions & 12 deletions test/ee/devclub/rest/PhotoSpotResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import static java.util.Collections.nCopies;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static java.util.Collections.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class PhotoSpotResourceTest {
Expand All @@ -21,16 +20,16 @@ public void initMocks() throws Exception {
resource.repo = mock(PhotoSpotRepository.class, RETURNS_DEEP_STUBS);
}

@Test
public void resourceLimitedNumberOfSpotsInRepo() throws Exception {
resource.maxSpots = 10;
PhotoSpot photoSpot = mock(PhotoSpot.class);
when(resource.repo.getAllSpots()).thenReturn(nCopies(15, photoSpot));
@Test
public void resourceLimitedNumberOfSpotsInRepo() throws Exception {
resource.maxSpots = 10;
PhotoSpot photoSpot = mock(PhotoSpot.class);
when(resource.repo.getAllSpots()).thenReturn(nCopies(15, photoSpot));

assertEquals(10, resource.getAllSpots().size());
}
assertEquals(10, resource.getAllSpots().size());
}

@Test
@Test
public void newPhotoSpotsArePersisted() throws Exception {
resource.newPhotoSpot("Aegna island", "WWI defence structures", 59.583771f, 24.749720f);

Expand Down

0 comments on commit 401f069

Please sign in to comment.