Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
8edd19fc0f
@ -16,21 +16,8 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jmx</groupId>
|
||||
<artifactId>jmxri</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jdmk</groupId>
|
||||
<artifactId>jmxtools</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.jms</groupId>
|
||||
<artifactId>jms</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>3.4.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
@ -7,38 +7,42 @@
|
||||
<name>spring-mvc-java</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-5</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-5</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring -->
|
||||
<!-- Spring Boot Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Jackson -->
|
||||
@ -63,11 +67,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- AOP -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
@ -118,7 +117,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@ -294,8 +292,6 @@
|
||||
|
||||
<properties>
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
|
||||
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
|
||||
<thymeleaf.version>2.1.5.RELEASE</thymeleaf.version>
|
||||
<jackson.version>2.9.4</jackson.version>
|
||||
|
||||
@ -317,7 +313,7 @@
|
||||
<!-- testing -->
|
||||
<httpcore.version>4.4.5</httpcore.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
<rest-assured.version>3.0.7</rest-assured.version>
|
||||
<net.sourceforge.htmlunit>2.23</net.sourceforge.htmlunit>
|
||||
|
||||
<!-- maven plugins -->
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.baeldung.app;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan(value = {"com.baeldung.web.controller"}, resourcePattern = "**/FileUploadController.class")
|
||||
@SpringBootApplication
|
||||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
public class City extends Location {
|
||||
String name;
|
||||
String state;
|
||||
|
||||
public City(String name, String state) {
|
||||
this.name = name;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.name == null && this.state == null) return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
sb.append("Name: ");
|
||||
sb.append(this.name);
|
||||
sb.append(", ");
|
||||
sb.append("State: ");
|
||||
sb.append(this.state);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
public class Location {
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.hamcrest.Matchers.samePropertyValuesAs;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.beans.PropertyUtil.getPropertyDescriptor;
|
||||
import static org.hamcrest.beans.PropertyUtil.propertyDescriptorsFor;
|
||||
|
||||
public class HamcrestBeansUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenACity_whenHasProperty_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, hasProperty("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenNotHasProperty_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, not(hasProperty("country")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenHasPropertyWithValueEqualTo_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, hasProperty("name", equalTo("San Francisco")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenHasPropertyWithValueEqualToIgnoringCase_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, hasProperty("state", equalToIgnoringCase("ca")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenSamePropertyValuesAs_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
City city2 = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, samePropertyValuesAs(city2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenNotSamePropertyValuesAs_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
City city2 = new City("Los Angeles", "CA");
|
||||
|
||||
assertThat(city, not(samePropertyValuesAs(city2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenGetPropertyDescriptor_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
PropertyDescriptor descriptor = getPropertyDescriptor("state", city);
|
||||
|
||||
assertThat(descriptor
|
||||
.getReadMethod()
|
||||
.getName(), is(equalTo("getState")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenGetPropertyDescriptorsFor_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
PropertyDescriptor[] descriptors = propertyDescriptorsFor(city, Object.class);
|
||||
List<String> getters = Arrays
|
||||
.stream(descriptors)
|
||||
.map(x -> x
|
||||
.getReadMethod()
|
||||
.getName())
|
||||
.collect(toList());
|
||||
|
||||
assertThat(getters, containsInAnyOrder("getName", "getState"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package org.baeldung.hamcrest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasToString;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.hamcrest.Matchers.emptyOrNullString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.typeCompatibleWith;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class HamcrestObjectUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenACity_whenHasToString_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, hasToString("[Name: San Francisco, State: CA]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenHasToStringEqualToIgnoringCase_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city, hasToString(equalToIgnoringCase("[NAME: SAN FRANCISCO, STATE: CA]")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenHasToStringEmptyOrNullString_thenCorrect() {
|
||||
City city = new City(null, null);
|
||||
|
||||
assertThat(city, hasToString(emptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenTypeCompatibleWithLocation_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city.getClass(), is(typeCompatibleWith(Location.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenTypeNotCompatibleWithString_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city.getClass(), is(not(typeCompatibleWith(String.class))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenACity_whenTypeCompatibleWithObject_thenCorrect() {
|
||||
City city = new City("San Francisco", "CA");
|
||||
|
||||
assertThat(city.getClass(), is(typeCompatibleWith(Object.class)));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user