Use AssertJ in spring-boot-samples

See gh-5083
This commit is contained in:
Phillip Webb
2016-02-06 14:53:10 -08:00
parent 962a598531
commit 1cc1fc6431
97 changed files with 580 additions and 733 deletions

View File

@@ -34,7 +34,7 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -74,9 +74,9 @@ public class SampleDataJpaApplicationTests {
@Test
public void testJmx() throws Exception {
assertEquals(1, ManagementFactory.getPlatformMBeanServer()
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null)
.size());
assertThat(ManagementFactory.getPlatformMBeanServer()
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null))
.hasSize(1);
}
}

View File

@@ -26,9 +26,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link CityRepository}.
@@ -46,6 +44,6 @@ public class CityRepositoryIntegrationTests {
public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
assertThat(cities.getTotalElements(), is(greaterThan(20L)));
assertThat(cities.getTotalElements()).isGreaterThan(20L);
}
}

View File

@@ -33,10 +33,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link HotelRepository}.
@@ -57,17 +54,17 @@ public class HotelRepositoryIntegrationTests {
City city = this.cityRepository
.findAll(new PageRequest(0, 1, Direction.ASC, "name")).getContent()
.get(0);
assertThat(city.getName(), is("Atlanta"));
assertThat(city.getName()).isEqualTo("Atlanta");
Page<HotelSummary> hotels = this.repository.findByCity(city,
new PageRequest(0, 10, Direction.ASC, "name"));
Hotel hotel = this.repository.findByCityAndName(city,
hotels.getContent().get(0).getName());
assertThat(hotel.getName(), is("Doubletree"));
assertThat(hotel.getName()).isEqualTo("Doubletree");
List<RatingCount> counts = this.repository.findRatingCounts(hotel);
assertThat(counts, hasSize(1));
assertThat(counts.get(0).getRating(), is(Rating.AVERAGE));
assertThat(counts.get(0).getCount(), is(greaterThan(1L)));
assertThat(counts).hasSize(1);
assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE);
assertThat(counts.get(0).getCount()).isGreaterThan(1L);
}
}