Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-17473
This commit is contained in:
commit
0518c39a4f
|
@ -7,3 +7,4 @@
|
|||
- [Array Operations in Java](https://www.baeldung.com/java-common-array-operations)
|
||||
- [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection)
|
||||
- [Removing an Element from an Array in Java](https://www.baeldung.com/java-array-remove-element)
|
||||
- [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.list.removefirst;
|
||||
package com.baeldung.array.removefirst;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
|
@ -12,4 +12,3 @@
|
|||
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
|
||||
- [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max)
|
||||
- [Remove All Occurrences of a Specific Value from a List](https://www.baeldung.com/java-remove-value-from-list)
|
||||
- [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [Apache Maven Tutorial](https://www.baeldung.com/maven)
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [Maven Compiler Plugin](http://www.baeldung.com/maven-compiler-plugin)
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [Eclipse Error: web.xml is missing and failOnMissingWebXml is set to true](https://www.baeldung.com/eclipse-error-web-xml-missing)
|
|
@ -1,29 +1,29 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-war-plugin-property</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>maven-war-plugin-property</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<!-- Update maven war plugin to 3.1.0 or higher -->
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<!-- Set failOnMissingWebXml configuration for maven war plugin -->
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<!-- Set failOnMissingWebXml as false in properties section -->
|
||||
<properties>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</properties>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>maven-war-plugin</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<!-- Update maven war plugin to 3.1.0 or higher -->
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<!-- Set failOnMissingWebXml configuration for maven war plugin -->
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<!-- Set failOnMissingWebXml as false in properties section -->
|
||||
<properties>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</properties>
|
||||
</project>
|
|
@ -11,9 +11,4 @@
|
|||
- [Maven Project with Multiple Source Directories](https://www.baeldung.com/maven-project-multiple-src-directories)
|
||||
- [Integration Testing with Maven](https://www.baeldung.com/maven-integration-test)
|
||||
- [Apache Maven Standard Directory Layout](https://www.baeldung.com/maven-directory-structure)
|
||||
- [Apache Maven Tutorial](https://www.baeldung.com/maven)
|
||||
- [Use the Latest Version of a Dependency in Maven](https://www.baeldung.com/maven-dependency-latest-version)
|
||||
- [Multi-Module Project with Maven](https://www.baeldung.com/maven-multi-module)
|
||||
- [Maven Enforcer Plugin](https://www.baeldung.com/maven-enforcer-plugin)
|
||||
- [Eclipse Error: web.xml is missing and failOnMissingWebXml is set to true](https://www.baeldung.com/eclipse-error-web-xml-missing)
|
||||
- [Guide to Maven Profiles](https://www.baeldung.com/maven-profiles)
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,3 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [Maven Enforcer Plugin](https://www.baeldung.com/maven-enforcer-plugin)
|
|
@ -11,6 +11,7 @@
|
|||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [Guide to Maven Profiles](https://www.baeldung.com/maven-profiles)
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [Use the Latest Version of a Dependency in Maven](https://www.baeldung.com/maven-dependency-latest-version)
|
|
@ -36,7 +36,7 @@
|
|||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.1-SNAPSHOT</version>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
0
maven/versions-maven-plugin/run-the-demo.sh → maven-all/versions-maven-plugin/run-the-demo.sh
Executable file → Normal file
0
maven/versions-maven-plugin/run-the-demo.sh → maven-all/versions-maven-plugin/run-the-demo.sh
Executable file → Normal file
|
@ -1,4 +1,8 @@
|
|||
# Relevant Articles
|
||||
|
||||
- [JPA Query Parameters Usage](http://www.baeldung.com/jpa-query-parameters-usage)
|
||||
- [JPA Query Parameters Usage](https://www.baeldung.com/jpa-query-parameters-usage)
|
||||
- [Mapping Entitiy Class Names to SQL Table Names with JPA](https://www.baeldung.com/jpa-entity-table-names)
|
||||
- [Default Column Values in JPA](https://www.baeldung.com/jpa-default-column-values)
|
||||
- [Types of JPA Queries](https://www.baeldung.com/jpa-queries)
|
||||
- [JPA/Hibernate Projections](https://www.baeldung.com/jpa-hibernate-projections)
|
||||
- [Combining JPA And/Or Criteria Predicates](https://www.baeldung.com/jpa-and-or-criteria-predicates)
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package com.baeldung.jpa.criteria.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.jpa.criteria.entity.Item;
|
||||
|
||||
public interface CustomItemRepository {
|
||||
|
||||
List<Item> findItemsByColorAndGrade();
|
||||
|
||||
List<Item> findItemByColorOrGrade();
|
||||
}
|
||||
package com.baeldung.jpa.criteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CustomItemRepository {
|
||||
|
||||
List<Item> findItemsByColorAndGrade();
|
||||
|
||||
List<Item> findItemByColorOrGrade();
|
||||
}
|
|
@ -1,77 +1,72 @@
|
|||
package com.baeldung.jpa.criteria.repository.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import com.baeldung.jpa.criteria.entity.Item;
|
||||
import com.baeldung.jpa.criteria.repository.CustomItemRepository;
|
||||
|
||||
public class CustomItemRepositoryImpl implements CustomItemRepository {
|
||||
|
||||
private EntityManager entityManager;
|
||||
|
||||
public CustomItemRepositoryImpl() {
|
||||
super();
|
||||
EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-h2-criteria");
|
||||
entityManager = factory.createEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> findItemsByColorAndGrade() {
|
||||
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Item> criteriaQuery = criteriaBuilder.createQuery(Item.class);
|
||||
Root<Item> itemRoot = criteriaQuery.from(Item.class);
|
||||
|
||||
Predicate predicateForBlueColor = criteriaBuilder.equal(itemRoot.get("color"), "blue");
|
||||
Predicate predicateForRedColor = criteriaBuilder.equal(itemRoot.get("color"), "red");
|
||||
Predicate predicateForColor = criteriaBuilder.or(predicateForBlueColor, predicateForRedColor);
|
||||
|
||||
Predicate predicateForGradeA = criteriaBuilder.equal(itemRoot.get("grade"), "A");
|
||||
Predicate predicateForGradeB = criteriaBuilder.equal(itemRoot.get("grade"), "B");
|
||||
Predicate predicateForGrade = criteriaBuilder.or(predicateForGradeA, predicateForGradeB);
|
||||
|
||||
// final search filter
|
||||
Predicate finalPredicate = criteriaBuilder.and(predicateForColor, predicateForGrade);
|
||||
|
||||
criteriaQuery.where(finalPredicate);
|
||||
|
||||
List<Item> items = entityManager.createQuery(criteriaQuery)
|
||||
.getResultList();
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> findItemByColorOrGrade() {
|
||||
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Item> criteriaQuery = criteriaBuilder.createQuery(Item.class);
|
||||
Root<Item> itemRoot = criteriaQuery.from(Item.class);
|
||||
|
||||
Predicate predicateForBlueColor = criteriaBuilder.equal(itemRoot.get("color"), "red");
|
||||
Predicate predicateForGradeA = criteriaBuilder.equal(itemRoot.get("grade"), "D");
|
||||
Predicate predicateForBlueColorAndGradeA = criteriaBuilder.and(predicateForBlueColor, predicateForGradeA);
|
||||
|
||||
Predicate predicateForRedColor = criteriaBuilder.equal(itemRoot.get("color"), "blue");
|
||||
Predicate predicateForGradeB = criteriaBuilder.equal(itemRoot.get("grade"), "B");
|
||||
Predicate predicateForRedColorAndGradeB = criteriaBuilder.and(predicateForRedColor, predicateForGradeB);
|
||||
|
||||
// final search filter
|
||||
Predicate finalPredicate = criteriaBuilder.or(predicateForBlueColorAndGradeA, predicateForRedColorAndGradeB);
|
||||
|
||||
criteriaQuery.where(finalPredicate);
|
||||
|
||||
List<Item> items = entityManager.createQuery(criteriaQuery)
|
||||
.getResultList();
|
||||
return items;
|
||||
}
|
||||
}
|
||||
package com.baeldung.jpa.criteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
public class CustomItemRepositoryImpl implements CustomItemRepository {
|
||||
|
||||
private EntityManager entityManager;
|
||||
|
||||
public CustomItemRepositoryImpl() {
|
||||
super();
|
||||
EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-h2-criteria");
|
||||
entityManager = factory.createEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> findItemsByColorAndGrade() {
|
||||
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Item> criteriaQuery = criteriaBuilder.createQuery(Item.class);
|
||||
Root<Item> itemRoot = criteriaQuery.from(Item.class);
|
||||
|
||||
Predicate predicateForBlueColor = criteriaBuilder.equal(itemRoot.get("color"), "blue");
|
||||
Predicate predicateForRedColor = criteriaBuilder.equal(itemRoot.get("color"), "red");
|
||||
Predicate predicateForColor = criteriaBuilder.or(predicateForBlueColor, predicateForRedColor);
|
||||
|
||||
Predicate predicateForGradeA = criteriaBuilder.equal(itemRoot.get("grade"), "A");
|
||||
Predicate predicateForGradeB = criteriaBuilder.equal(itemRoot.get("grade"), "B");
|
||||
Predicate predicateForGrade = criteriaBuilder.or(predicateForGradeA, predicateForGradeB);
|
||||
|
||||
// final search filter
|
||||
Predicate finalPredicate = criteriaBuilder.and(predicateForColor, predicateForGrade);
|
||||
|
||||
criteriaQuery.where(finalPredicate);
|
||||
|
||||
List<Item> items = entityManager.createQuery(criteriaQuery)
|
||||
.getResultList();
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> findItemByColorOrGrade() {
|
||||
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Item> criteriaQuery = criteriaBuilder.createQuery(Item.class);
|
||||
Root<Item> itemRoot = criteriaQuery.from(Item.class);
|
||||
|
||||
Predicate predicateForBlueColor = criteriaBuilder.equal(itemRoot.get("color"), "red");
|
||||
Predicate predicateForGradeA = criteriaBuilder.equal(itemRoot.get("grade"), "D");
|
||||
Predicate predicateForBlueColorAndGradeA = criteriaBuilder.and(predicateForBlueColor, predicateForGradeA);
|
||||
|
||||
Predicate predicateForRedColor = criteriaBuilder.equal(itemRoot.get("color"), "blue");
|
||||
Predicate predicateForGradeB = criteriaBuilder.equal(itemRoot.get("grade"), "B");
|
||||
Predicate predicateForRedColorAndGradeB = criteriaBuilder.and(predicateForRedColor, predicateForGradeB);
|
||||
|
||||
// final search filter
|
||||
Predicate finalPredicate = criteriaBuilder.or(predicateForBlueColorAndGradeA, predicateForRedColorAndGradeB);
|
||||
|
||||
criteriaQuery.where(finalPredicate);
|
||||
|
||||
List<Item> items = entityManager.createQuery(criteriaQuery)
|
||||
.getResultList();
|
||||
return items;
|
||||
}
|
||||
}
|
|
@ -1,49 +1,49 @@
|
|||
package com.baeldung.jpa.criteria.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Table(name = "item")
|
||||
@Entity
|
||||
public class Item {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String color;
|
||||
private String grade;
|
||||
private String name;
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getGrade() {
|
||||
return grade;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setGrade(String grade) {
|
||||
this.grade = grade;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
package com.baeldung.jpa.criteria;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Table(name = "item")
|
||||
@Entity
|
||||
public class Item {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String color;
|
||||
private String grade;
|
||||
private String name;
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getGrade() {
|
||||
return grade;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setGrade(String grade) {
|
||||
this.grade = grade;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
|
@ -32,4 +32,91 @@
|
|||
value="queryparams.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="entity-default-values">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.defaultvalues.User</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-query-types">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.querytypes.UserEntity</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
<property name="javax.persistence.sql-load-script-source"
|
||||
value="users.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-projections">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.projections.Product</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
<property name="javax.persistence.sql-load-script-source"
|
||||
value="products_jpa.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-h2-criteria">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.criteria.Item</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
<property name="javax.persistence.sql-load-script-source"
|
||||
value="item.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
|
@ -1,4 +1,4 @@
|
|||
insert into item(id,grade,color) values (10,'C','blue');
|
||||
insert into item(id,grade,color) values (11,'C','red');
|
||||
insert into item(id,grade,color) values (12,'A','blue');
|
||||
insert into item(id,grade,color) values (10,'C','blue');
|
||||
insert into item(id,grade,color) values (11,'C','red');
|
||||
insert into item(id,grade,color) values (12,'A','blue');
|
||||
insert into item(id,grade,color) values (13,'D','red');
|
|
@ -1,44 +1,44 @@
|
|||
package com.baeldung.jpa.criteria.repository.impl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jpa.criteria.entity.Item;
|
||||
import com.baeldung.jpa.criteria.repository.CustomItemRepository;
|
||||
|
||||
public class CustomItemRepositoryIntegrationTest {
|
||||
|
||||
CustomItemRepository customItemRepository = new CustomItemRepositoryImpl();
|
||||
|
||||
@Test
|
||||
public void givenItems_whenFindItemsByColorAndGrade_thenReturnItems() {
|
||||
|
||||
List<Item> items = customItemRepository.findItemsByColorAndGrade();
|
||||
|
||||
assertFalse("No items found", items.isEmpty());
|
||||
assertEquals("There should be only one item", 1, items.size());
|
||||
|
||||
Item item = items.get(0);
|
||||
|
||||
assertEquals("this item do not have blue color", "blue", item.getColor());
|
||||
assertEquals("this item does not belong to A grade", "A", item.getGrade());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenItems_whenFindItemByColorOrGrade_thenReturnItems() {
|
||||
|
||||
List<Item> items = customItemRepository.findItemByColorOrGrade();
|
||||
|
||||
assertFalse("No items found", items.isEmpty());
|
||||
assertEquals("There should be only one item", 1, items.size());
|
||||
|
||||
Item item = items.get(0);
|
||||
|
||||
assertEquals("this item do not have red color", "red", item.getColor());
|
||||
assertEquals("this item does not belong to D grade", "D", item.getGrade());
|
||||
}
|
||||
}
|
||||
package com.baeldung.jpa.criteria;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jpa.criteria.Item;
|
||||
import com.baeldung.jpa.criteria.CustomItemRepository;
|
||||
|
||||
public class CustomItemRepositoryIntegrationTest {
|
||||
|
||||
CustomItemRepository customItemRepository = new CustomItemRepositoryImpl();
|
||||
|
||||
@Test
|
||||
public void givenItems_whenFindItemsByColorAndGrade_thenReturnItems() {
|
||||
|
||||
List<Item> items = customItemRepository.findItemsByColorAndGrade();
|
||||
|
||||
assertFalse("No items found", items.isEmpty());
|
||||
assertEquals("There should be only one item", 1, items.size());
|
||||
|
||||
Item item = items.get(0);
|
||||
|
||||
assertEquals("this item do not have blue color", "blue", item.getColor());
|
||||
assertEquals("this item does not belong to A grade", "A", item.getGrade());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenItems_whenFindItemByColorOrGrade_thenReturnItems() {
|
||||
|
||||
List<Item> items = customItemRepository.findItemByColorOrGrade();
|
||||
|
||||
assertFalse("No items found", items.isEmpty());
|
||||
assertEquals("There should be only one item", 1, items.size());
|
||||
|
||||
Item item = items.get(0);
|
||||
|
||||
assertEquals("this item do not have red color", "red", item.getColor());
|
||||
assertEquals("this item does not belong to D grade", "D", item.getGrade());
|
||||
}
|
||||
}
|
|
@ -1,16 +1,12 @@
|
|||
# Relevant Articles
|
||||
|
||||
- [A Guide to SqlResultSetMapping](http://www.baeldung.com/jpa-sql-resultset-mapping)
|
||||
- [A Guide to Stored Procedures with JPA](http://www.baeldung.com/jpa-stored-procedures)
|
||||
- [A Guide to SqlResultSetMapping](https://www.baeldung.com/jpa-sql-resultset-mapping)
|
||||
- [A Guide to Stored Procedures with JPA](https://www.baeldung.com/jpa-stored-procedures)
|
||||
- [Fixing the JPA error “java.lang.String cannot be cast to Ljava.lang.String;”](https://www.baeldung.com/jpa-error-java-lang-string-cannot-be-cast)
|
||||
- [JPA Entity Graph](https://www.baeldung.com/jpa-entity-graph)
|
||||
- [JPA 2.2 Support for Java 8 Date/Time Types](https://www.baeldung.com/jpa-java-time)
|
||||
- [Converting Between LocalDate and SQL Date](https://www.baeldung.com/java-convert-localdate-sql-date)
|
||||
- [Combining JPA And/Or Criteria Predicates](https://www.baeldung.com/jpa-and-or-criteria-predicates)
|
||||
- [Types of JPA Queries](https://www.baeldung.com/jpa-queries)
|
||||
- [JPA/Hibernate Projections](https://www.baeldung.com/jpa-hibernate-projections)
|
||||
- [Composite Primary Keys in JPA](https://www.baeldung.com/jpa-composite-primary-keys)
|
||||
- [Defining JPA Entities](https://www.baeldung.com/jpa-entities)
|
||||
- [JPA @Basic Annotation](https://www.baeldung.com/jpa-basic-annotation)
|
||||
- [Default Column Values in JPA](https://www.baeldung.com/jpa-default-column-values)
|
||||
- [Persisting Enums in JPA](https://www.baeldung.com/jpa-persisting-enums-in-jpa)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.util;
|
||||
package com.baeldung.jpa.convertdates;
|
||||
|
||||
import javax.persistence.AttributeConverter;
|
||||
import javax.persistence.Converter;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.util;
|
||||
package com.baeldung.jpa.entity;
|
||||
|
||||
public enum Gender {
|
||||
MALE,
|
|
@ -14,8 +14,6 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.baeldung.util.Gender;
|
||||
|
||||
@Entity
|
||||
@Table(name="STUDENT")
|
||||
public class Student {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.jpa.entity;
|
||||
package com.baeldung.jpa.primarykeys;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.jpa.entity;
|
||||
package com.baeldung.jpa.primarykeys;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.jpa.entity;
|
||||
package com.baeldung.jpa.primarykeys;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.jpa.entity;
|
||||
package com.baeldung.jpa.primarykeys;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.sqlresultsetmapping;
|
||||
package com.baeldung.jpa.sqlresultsetmapping;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
|
@ -7,7 +7,7 @@ import javax.persistence.*;
|
|||
name="EmployeeResult",
|
||||
entities={
|
||||
@EntityResult(
|
||||
entityClass = com.baeldung.sqlresultsetmapping.Employee.class,
|
||||
entityClass = com.baeldung.jpa.sqlresultsetmapping.Employee.class,
|
||||
fields={@FieldResult(name="id",column="employeeNumber"),
|
||||
@FieldResult(name="name", column="name")}
|
||||
)
|
|
@ -1,18 +1,18 @@
|
|||
package com.baeldung.sqlresultsetmapping;
|
||||
package com.baeldung.jpa.sqlresultsetmapping;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@SqlResultSetMappings(value = {
|
||||
@SqlResultSetMapping(name = "ScheduleResult",
|
||||
classes = { @ConstructorResult(targetClass = com.baeldung.sqlresultsetmapping.ScheduledDay.class,
|
||||
classes = { @ConstructorResult(targetClass = com.baeldung.jpa.sqlresultsetmapping.ScheduledDay.class,
|
||||
columns = { @ColumnResult(name = "id", type = Long.class),
|
||||
@ColumnResult(name = "employeeId", type = Long.class),
|
||||
@ColumnResult(name = "dayOfWeek") }) }),
|
||||
@SqlResultSetMapping(name = "FridayEmployeeResult",
|
||||
columns = { @ColumnResult(name = "employeeId") }),
|
||||
@SqlResultSetMapping(name = "EmployeeScheduleResults",
|
||||
entities = { @EntityResult(entityClass = com.baeldung.sqlresultsetmapping.Employee.class),
|
||||
@EntityResult(entityClass = com.baeldung.sqlresultsetmapping.ScheduledDay.class)
|
||||
entities = { @EntityResult(entityClass = com.baeldung.jpa.sqlresultsetmapping.Employee.class),
|
||||
@EntityResult(entityClass = com.baeldung.jpa.sqlresultsetmapping.ScheduledDay.class)
|
||||
}) })
|
||||
@NamedNativeQuery(name = "FridayEmployees",
|
||||
query = "SELECT employeeId FROM schedule_days WHERE dayOfWeek = 'FRIDAY'",
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
<persistence-unit name="java-jpa-scheduled-day">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.sqlresultsetmapping.ScheduledDay</class>
|
||||
<class>com.baeldung.sqlresultsetmapping.Employee</class>
|
||||
<class>com.baeldung.jpa.sqlresultsetmapping.ScheduledDay</class>
|
||||
<class>com.baeldung.jpa.sqlresultsetmapping.Employee</class>
|
||||
<class>com.baeldung.jpa.basicannotation.Course</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
|
@ -115,77 +115,13 @@
|
|||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-h2-criteria">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.criteria.entity.Item</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
<property name="javax.persistence.sql-load-script-source"
|
||||
value="item.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-query-types">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.querytypes.UserEntity</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
<property name="javax.persistence.sql-load-script-source"
|
||||
value="users.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="entity-default-values">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.defaultvalues.User</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-entity-definition">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.entity.Student</class>
|
||||
<class>com.baeldung.jpa.entity.Book</class>
|
||||
<class>com.baeldung.jpa.entity.BookId</class>
|
||||
<class>com.baeldung.jpa.entity.Account</class>
|
||||
<class>com.baeldung.jpa.entity.AccountId</class>
|
||||
<class>com.baeldung.jpa.primarykeys.Book</class>
|
||||
<class>com.baeldung.jpa.primarykeys.BookId</class>
|
||||
<class>com.baeldung.jpa.primarykeys.Account</class>
|
||||
<class>com.baeldung.jpa.primarykeys.AccountId</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
|
@ -203,25 +139,4 @@
|
|||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="jpa-projections">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.projections.Product</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver"
|
||||
value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url"
|
||||
value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="show_sql" value="true" />
|
||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
||||
value="false" />
|
||||
<property name="javax.persistence.sql-load-script-source"
|
||||
value="products_jpa.sql" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
|
@ -16,8 +16,6 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.util.Gender;
|
||||
|
||||
public class StudentEntityIntegrationTest {
|
||||
|
||||
private EntityManagerFactory emf;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.jpa.entity;
|
||||
package com.baeldung.jpa.primarykeys;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@ -7,6 +7,10 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
|
||||
import com.baeldung.jpa.primarykeys.Account;
|
||||
import com.baeldung.jpa.primarykeys.AccountId;
|
||||
import com.baeldung.jpa.primarykeys.Book;
|
||||
import com.baeldung.jpa.primarykeys.BookId;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.sqlresultsetmapping;
|
||||
package com.baeldung.jpa.sqlresultsetmapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
12
pom.xml
12
pom.xml
|
@ -544,7 +544,11 @@
|
|||
<module>lucene</module>
|
||||
|
||||
<module>mapstruct</module>
|
||||
<module>maven</module>
|
||||
<!-- <module>maven-all/compiler-plugin-java-9</module> --> <!-- We haven't upgraded to java 9. -->
|
||||
<module>maven-all/maven</module>
|
||||
<module>maven-all/maven-war-plugin</module>
|
||||
<module>maven-all/profiles</module>
|
||||
<module>maven-all/versions-maven-plugin</module>
|
||||
<module>maven-archetype</module>
|
||||
<!-- <module>maven-polyglot/maven-polyglot-json-app</module> --> <!-- Not a maven project -->
|
||||
<module>maven-polyglot/maven-polyglot-json-extension</module>
|
||||
|
@ -1279,7 +1283,11 @@
|
|||
<module>lucene</module>
|
||||
|
||||
<module>mapstruct</module>
|
||||
<module>maven</module>
|
||||
<!-- <module>maven-all/compiler-plugin-java-9</module> --> <!-- We haven't upgraded to java 9. -->
|
||||
<module>maven-all/maven</module>
|
||||
<module>maven-all/maven-war-plugin</module>
|
||||
<module>maven-all/profiles</module>
|
||||
<module>maven-all/versions-maven-plugin</module>
|
||||
<!-- <module>maven-java-11</module> --> <!-- we haven't upgraded to Java 11 -->
|
||||
<module>maven-archetype</module>
|
||||
<!-- <module>maven-polyglot/maven-polyglot-json-app</module> --> <!-- Not a maven project -->
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
## Hamcrest
|
||||
|
||||
This module contains articles about Hamcrest
|
||||
|
||||
### Relevant articles
|
||||
- [Hamcrest Text Matchers](https://www.baeldung.com/hamcrest-text-matchers)
|
||||
- [Hamcrest File Matchers](https://www.baeldung.com/hamcrest-file-matchers)
|
||||
- [Hamcrest Object Matchers](https://www.baeldung.com/hamcrest-object-matchers)
|
||||
- [Hamcrest Bean Matchers](https://www.baeldung.com/hamcrest-bean-matchers)
|
||||
- [Hamcrest Number Matchers](https://www.baeldung.com/hamcrest-number-matchers)
|
||||
- [Hamcrest Common Core Matchers](https://www.baeldung.com/hamcrest-core-matchers)
|
||||
- [Hamcrest Custom Matchers](https://www.baeldung.com/hamcrest-custom-matchers)
|
|
@ -0,0 +1,29 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>hamcrest</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<hamcrest.version>2.0.0.0</hamcrest.version>
|
||||
</properties>
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest.objectmatchers;
|
||||
|
||||
public class City extends Location {
|
||||
String name;
|
|
@ -0,0 +1,4 @@
|
|||
package com.baeldung.hamcrest.objectmatchers;
|
||||
|
||||
public class Location {
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest;
|
||||
|
||||
import com.baeldung.hamcrest.objectmatchers.City;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
@ -8,13 +9,7 @@ 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.Matchers.*;
|
||||
import static org.hamcrest.beans.PropertyUtil.getPropertyDescriptor;
|
||||
import static org.hamcrest.beans.PropertyUtil.propertyDescriptorsFor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest;
|
||||
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -145,7 +145,6 @@ public class HamcrestCoreMatchersUnitTest {
|
|||
@Test
|
||||
public void givenString_WhenContainsStringIgnoringCase_ThenCorrect() {
|
||||
|
||||
|
||||
// GIVEN
|
||||
String testString = "hamcrest core";
|
||||
|
||||
|
@ -164,7 +163,6 @@ public class HamcrestCoreMatchersUnitTest {
|
|||
assertThat(list, hasItem(isA(String.class)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTestInput_WhenUsingHasItemsInCollection() {
|
||||
|
||||
|
@ -223,7 +221,6 @@ public class HamcrestCoreMatchersUnitTest {
|
|||
assertThat(testString, either(startsWith("Bael")).or(containsString("Core")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTestInput_WhenUsingEveryItemForMatchInCollection() {
|
||||
|
|
@ -1,22 +1,13 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest;
|
||||
|
||||
import static org.hamcrest.core.StringContains.containsString;
|
||||
import static org.hamcrest.io.FileMatchers.aFileNamed;
|
||||
import static org.hamcrest.io.FileMatchers.aFileWithAbsolutePath;
|
||||
import static org.hamcrest.io.FileMatchers.aFileWithCanonicalPath;
|
||||
import static org.hamcrest.io.FileMatchers.aFileWithSize;
|
||||
import static org.hamcrest.io.FileMatchers.aReadableFile;
|
||||
import static org.hamcrest.io.FileMatchers.aWritableFile;
|
||||
import static org.hamcrest.io.FileMatchers.anExistingDirectory;
|
||||
import static org.hamcrest.io.FileMatchers.anExistingFile;
|
||||
import static org.hamcrest.io.FileMatchers.anExistingFileOrDirectory;
|
||||
import static org.hamcrest.number.OrderingComparison.greaterThan;
|
||||
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.hamcrest.io.FileMatchers.*;
|
||||
import static org.hamcrest.number.OrderingComparison.greaterThan;
|
||||
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class HamcrestFileUnitTest {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -6,15 +6,7 @@ import java.math.BigDecimal;
|
|||
import java.time.LocalDate;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.closeTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.comparesEqualTo;
|
||||
import static org.hamcrest.Matchers.notANumber;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class HamcrestNumberUnitTest {
|
||||
|
|
@ -1,14 +1,11 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest;
|
||||
|
||||
import com.baeldung.hamcrest.objectmatchers.City;
|
||||
import com.baeldung.hamcrest.objectmatchers.Location;
|
||||
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;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class HamcrestObjectUnitTest {
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.StringContains.containsString;
|
||||
import static org.hamcrest.core.StringContains.containsStringIgnoringCase;
|
||||
|
@ -16,8 +18,6 @@ import static org.hamcrest.text.MatchesPattern.matchesPattern;
|
|||
import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HamcrestTextUnitTest {
|
||||
|
||||
@Test
|
|
@ -1,10 +1,10 @@
|
|||
package org.baeldung.hamcrest;
|
||||
package com.baeldung.hamcrest.custommatchers;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.baeldung.hamcrest.custommatchers.IsDivisibleBy.divisibleBy;
|
||||
import static org.baeldung.hamcrest.custommatchers.IsOnlyDigits.onlyDigits;
|
||||
import static org.baeldung.hamcrest.custommatchers.IsUppercase.uppercase;
|
||||
import static com.baeldung.hamcrest.custommatchers.IsDivisibleBy.divisibleBy;
|
||||
import static com.baeldung.hamcrest.custommatchers.IsOnlyDigits.onlyDigits;
|
||||
import static com.baeldung.hamcrest.custommatchers.IsUppercase.uppercase;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.hamcrest.custommatchers;
|
||||
package com.baeldung.hamcrest.custommatchers;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.hamcrest.custommatchers;
|
||||
package com.baeldung.hamcrest.custommatchers;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.hamcrest.custommatchers;
|
||||
package com.baeldung.hamcrest.custommatchers;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
|
@ -1,5 +1,7 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Mockito’s Java 8 Features](http://www.baeldung.com/mockito-2-java-8)
|
||||
- [Lazy Verification with Mockito 2](http://www.baeldung.com/mockito-2-lazy-verification)
|
||||
- [Mockito’s Java 8 Features](https://www.baeldung.com/mockito-2-java-8)
|
||||
- [Lazy Verification with Mockito 2](https://www.baeldung.com/mockito-2-lazy-verification)
|
||||
- [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception)
|
||||
- [Quick Guide to BDDMockito](https://www.baeldung.com/bdd-mockito)
|
||||
- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy)
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
package org.baeldung.bddmockito;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
package com.baeldung.mockito.bddmockito;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -9,6 +6,9 @@ import org.junit.Test;
|
|||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
|
||||
public class BDDMockitoUnitTest {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.bddmockito;
|
||||
package com.baeldung.mockito.bddmockito;
|
||||
|
||||
public interface PhoneBookRepository {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.bddmockito;
|
||||
package com.baeldung.mockito.bddmockito;
|
||||
|
||||
public class PhoneBookService {
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
package com.baeldung.mockito.java8;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.List;
|
||||
package com.baeldung.mockito.lazyverification;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.exceptions.base.MockitoAssertionError;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.VerificationCollector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class LazyVerificationUnitTest {
|
||||
|
||||
@Test
|
|
@ -1,11 +1,4 @@
|
|||
package org.baeldung.mockito.misusing;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
package com.baeldung.mockito.spy;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
@ -13,6 +6,13 @@ import org.mockito.Mockito;
|
|||
import org.mockito.exceptions.misusing.NotAMockException;
|
||||
import org.mockito.internal.progress.ThreadSafeMockingProgress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class MockitoMisusingUnitTest {
|
||||
|
||||
@After
|
|
@ -1,9 +1,4 @@
|
|||
package org.baeldung.mockito.spy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
package com.baeldung.mockito.spy;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -11,6 +6,11 @@ import org.mockito.Mockito;
|
|||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MockitoSpyUnitTest {
|
||||
|
|
@ -4,23 +4,13 @@
|
|||
|
||||
|
||||
### Relevant Articles:
|
||||
- [Mockito Verify Cookbook](http://www.baeldung.com/mockito-verify)
|
||||
- [Mockito When/Then Cookbook](http://www.baeldung.com/mockito-behavior)
|
||||
- [Mockito – Using Spies](http://www.baeldung.com/mockito-spy)
|
||||
- [Getting Started with Mockito @Mock, @Spy, @Captor and @InjectMocks](http://www.baeldung.com/mockito-annotations)
|
||||
- [Mockito’s Mock Methods](http://www.baeldung.com/mockito-mock-methods)
|
||||
- [Introduction to PowerMock](http://www.baeldung.com/intro-to-powermock)
|
||||
- [Mocking Exception Throwing using Mockito](http://www.baeldung.com/mockito-exceptions)
|
||||
- [Mocking Void Methods with Mockito](http://www.baeldung.com/mockito-void-methods)
|
||||
- [Mocking of Private Methods Using PowerMock](http://www.baeldung.com/powermock-private-method)
|
||||
- [Mock Final Classes and Methods with Mockito](http://www.baeldung.com/mockito-final)
|
||||
- [Hamcrest Custom Matchers](http://www.baeldung.com/hamcrest-custom-matchers)
|
||||
- [Hamcrest Common Core Matchers](http://www.baeldung.com/hamcrest-core-matchers)
|
||||
- [Testing Callbacks with Mockito](http://www.baeldung.com/mockito-callbacks)
|
||||
- [Using Hamcrest Number Matchers](https://www.baeldung.com/hamcrest-number-matchers)
|
||||
- [Quick Guide to BDDMockito](http://www.baeldung.com/bdd-mockito)
|
||||
- [Hamcrest Bean Matchers](http://www.baeldung.com/hamcrest-bean-matchers)
|
||||
- [Hamcrest Object Matchers](http://www.baeldung.com/hamcrest-object-matchers)
|
||||
- [Hamcrest File Matchers](https://www.baeldung.com/hamcrest-file-matchers)
|
||||
- [Hamcrest Text Matchers](http://www.baeldung.com/hamcrest-text-matchers)
|
||||
- [Testing Callbacks with Mockito](http://www.baeldung.com/mockito-callbacks)
|
||||
- [Mockito Verify Cookbook](https://www.baeldung.com/mockito-verify)
|
||||
- [Mockito When/Then Cookbook](https://www.baeldung.com/mockito-behavior)
|
||||
- [Getting Started with Mockito @Mock, @Spy, @Captor and @InjectMocks](https://www.baeldung.com/mockito-annotations)
|
||||
- [Mockito’s Mock Methods](https://www.baeldung.com/mockito-mock-methods)
|
||||
- [Introduction to PowerMock](https://www.baeldung.com/intro-to-powermock)
|
||||
- [Mocking of Private Methods Using PowerMock](https://www.baeldung.com/powermock-private-method)
|
||||
- [Mocking Exception Throwing using Mockito](https://www.baeldung.com/mockito-exceptions)
|
||||
- [Mocking Void Methods with Mockito](https://www.baeldung.com/mockito-void-methods)
|
||||
- [Mock Final Classes and Methods with Mockito](https://www.baeldung.com/mockito-final)
|
||||
- [Testing Callbacks with Mockito](https://www.baeldung.com/mockito-callbacks)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.baeldung</groupId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>mockito</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>mockito</name>
|
||||
|
@ -58,12 +58,6 @@
|
|||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue