Merge branch 'master' into BAEL-20862
This commit is contained in:
commit
e4b74cda31
|
@ -28,17 +28,16 @@ class CategoryUnitTest extends GroovyTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
// http://team.baeldung.com/browse/BAEL-20687
|
||||
// void test_whenUsingTimeCategory_thenOperationOnNumber() {
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
|
||||
// use (TimeCategory) {
|
||||
// assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
|
||||
//
|
||||
// sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
|
||||
// assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
|
||||
// assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
|
||||
// }
|
||||
// }
|
||||
void test_whenUsingTimeCategory_thenOperationOnNumber() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
|
||||
use (TimeCategory) {
|
||||
assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
|
||||
|
||||
sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
|
||||
assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
|
||||
assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
|
||||
}
|
||||
}
|
||||
|
||||
void test_whenUsingDOMCategory_thenOperationOnXML() {
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@ class WebserviceManualTest extends GroovyTestCase {
|
|||
assert stories.size() == 5
|
||||
}
|
||||
|
||||
/* see BAEL-3753
|
||||
void test_whenConsumingSoap_thenReceiveResponse() {
|
||||
def url = "http://www.dataaccess.com/webservicesserver/numberconversion.wso"
|
||||
def soapClient = new SOAPClient(url)
|
||||
|
@ -90,7 +89,6 @@ class WebserviceManualTest extends GroovyTestCase {
|
|||
def words = response.NumberToWordsResponse
|
||||
assert words == "one thousand two hundred and thirty four "
|
||||
}
|
||||
*/
|
||||
|
||||
void test_whenConsumingRestGet_thenReceiveResponse() {
|
||||
def path = "/get"
|
||||
|
|
|
@ -9,6 +9,7 @@ This module contains articles about Java 9 core features
|
|||
- [Iterate Through a Range of Dates in Java](https://www.baeldung.com/java-iterate-date-range)
|
||||
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
|
||||
- [Immutable Set in Java](https://www.baeldung.com/java-immutable-set)
|
||||
- [Immutable ArrayList in Java](https://www.baeldung.com/java-immutable-list)
|
||||
|
||||
Note: also contains part of the code for the article
|
||||
[How to Filter a Collection in Java](https://www.baeldung.com/java-collection-filtering).
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
<version>${junit.platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -69,6 +74,7 @@
|
|||
<maven.compiler.source>1.9</maven.compiler.source>
|
||||
<maven.compiler.target>1.9</maven.compiler.target>
|
||||
<guava.version>25.1-jre</guava.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.baeldung.java9.list.immutable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ImmutableArrayListUnitTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingTheJdk_whenUnmodifiableListIsCreated_thenNotModifiable() {
|
||||
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = Collections.unmodifiableList(list);
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingTheJava9_whenUnmodifiableListIsCreated_thenNotModifiable() {
|
||||
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = List.of(list.toArray(new String[]{}));
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingGuava_whenUnmodifiableListIsCreated_thenNotModifiable() {
|
||||
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = ImmutableList.copyOf(list);
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingGuavaBuilder_whenUnmodifiableListIsCreated_thenNoLongerModifiable() {
|
||||
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
|
||||
final ImmutableList<String> unmodifiableList = ImmutableList.<String>builder().addAll(list).build();
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingCommonsCollections_whenUnmodifiableListIsCreated_thenNotModifiable() {
|
||||
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = ListUtils.unmodifiableList(list);
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
}
|
|
@ -3,9 +3,8 @@
|
|||
This module contains articles about the Java ArrayList collection
|
||||
|
||||
### Relevant Articles:
|
||||
- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list)
|
||||
- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist)
|
||||
- [Add Multiple Items to an Java ArrayList](http://www.baeldung.com/java-add-items-array-list)
|
||||
- [Guide to the Java ArrayList](https://www.baeldung.com/java-arraylist)
|
||||
- [Add Multiple Items to an Java ArrayList](https://www.baeldung.com/java-add-items-array-list)
|
||||
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
|
||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||
- [Removing an Element From an ArrayList](https://www.baeldung.com/java-arraylist-remove-element)
|
||||
|
|
|
@ -15,42 +15,11 @@ public class CoreJavaCollectionsUnitTest {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CoreJavaCollectionsUnitTest.class);
|
||||
|
||||
|
||||
// tests -
|
||||
|
||||
@Test
|
||||
public final void givenUsingTheJdk_whenArrayListIsSynchronized_thenCorrect() {
|
||||
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> list = new ArrayList<>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> synchronizedList = Collections.synchronizedList(list);
|
||||
LOG.debug("Synchronized List is: " + synchronizedList);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingTheJdk_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = Collections.unmodifiableList(list);
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingGuava_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = ImmutableList.copyOf(list);
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingGuavaBuilder_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||
final ImmutableList<String> unmodifiableList = ImmutableList.<String>builder().addAll(list).build();
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public final void givenUsingCommonsCollections_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||
final List<String> unmodifiableList = ListUtils.unmodifiableList(list);
|
||||
unmodifiableList.add("four");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -642,7 +642,6 @@
|
|||
<module>spring-boot-modules</module>
|
||||
<module>spring-boot-angular</module>
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-boot-camel</module>
|
||||
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-client</module>
|
||||
<module>spring-boot-config-jpa-error</module>
|
||||
|
@ -654,10 +653,9 @@
|
|||
<module>spring-boot-jasypt</module>
|
||||
<module>spring-boot-kotlin</module>
|
||||
<module>spring-boot-libraries</module>
|
||||
<module>spring-boot-logging-log4j2</module>
|
||||
<module>spring-boot-mvc-2</module>
|
||||
<module>spring-boot-nashorn</module>
|
||||
<module>spring-boot-parent</module>
|
||||
<module>spring-boot-performance</module>
|
||||
<module>spring-boot-property-exp</module>
|
||||
|
||||
<module>spring-boot-rest</module>
|
||||
|
@ -1168,7 +1166,6 @@
|
|||
<module>spring-boot-modules</module>
|
||||
<module>spring-boot-angular</module>
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-boot-camel</module>
|
||||
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-client</module>
|
||||
<module>spring-boot-config-jpa-error</module>
|
||||
|
@ -1180,11 +1177,10 @@
|
|||
<module>spring-boot-jasypt</module>
|
||||
<module>spring-boot-kotlin</module>
|
||||
<module>spring-boot-libraries</module>
|
||||
<module>spring-boot-logging-log4j2</module>
|
||||
<module>spring-boot-mvc</module>
|
||||
<module>spring-boot-mvc-2</module>
|
||||
<module>spring-boot-nashorn</module>
|
||||
<module>spring-boot-parent</module>
|
||||
<module>spring-boot-performance</module>
|
||||
<module>spring-boot-property-exp</module>
|
||||
|
||||
<module>spring-boot-rest</module>
|
||||
|
|
|
@ -15,15 +15,17 @@
|
|||
|
||||
<modules>
|
||||
<module>spring-boot-admin</module>
|
||||
<module>spring-boot-custom-starter</module>
|
||||
<module>spring-boot-artifacts</module>
|
||||
<module>spring-boot-autoconfiguration</module>
|
||||
<module>spring-boot-camel</module>
|
||||
<module>spring-boot-custom-starter</module>
|
||||
<module>spring-boot-crud</module>
|
||||
<module>spring-boot-data</module>
|
||||
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-keycloak</module>
|
||||
<module>spring-boot-logging-log4j2</module>
|
||||
<module>spring-boot-mvc-birt</module>
|
||||
<module>spring-boot-performance</module>
|
||||
<module>spring-boot-nashorn</module>
|
||||
<module>spring-boot-properties</module>
|
||||
<module>spring-boot-springdoc</module>
|
||||
<module>spring-boot-testing</module>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<name>spring-boot-camel</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
||||
<artifactId>spring-boot-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
|
@ -13,7 +13,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
|
@ -11,7 +11,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
|
@ -3,14 +3,17 @@ package com.baeldung.models;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Tweet")
|
||||
public class Tweet {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
|
@ -18,7 +21,8 @@ public class Tweet {
|
|||
private String tweet;
|
||||
private String owner;
|
||||
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
|
||||
private Set<String> likes = new HashSet();
|
||||
@CollectionTable(name = "Tweet_Likes")
|
||||
private Set<String> likes = new HashSet<>();
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
|
|
|
@ -1,29 +1,5 @@
|
|||
package com.baeldung.relationships;
|
||||
|
||||
import static org.springframework.util.Assert.isTrue;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import com.baeldung.AppConfig;
|
||||
import com.baeldung.data.repositories.TweetRepository;
|
||||
import com.baeldung.data.repositories.UserRepository;
|
||||
|
@ -31,6 +7,30 @@ import com.baeldung.models.AppUser;
|
|||
import com.baeldung.models.Tweet;
|
||||
import com.baeldung.security.AppUserPrincipal;
|
||||
import com.baeldung.util.DummyContentUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.util.Assert.isTrue;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
|
@ -54,10 +54,22 @@ public class SpringDataWithSecurityIntegrationTest {
|
|||
tweetRepository.saveAll(DummyContentUtil.generateDummyTweets(appUsers));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
tweetRepository.deleteAll();
|
||||
userRepository.deleteAll();
|
||||
/**
|
||||
* This is to ensure the tables are dropped in proper order.
|
||||
* After the Spring Boot 2.2.2 upgrade, DDL statements generated automatically try to drop Tweet table first.
|
||||
* As a result we get org.h2.jdbc.JdbcSQLSyntaxErrorException because Tweet_Likes table depends on Tweet.
|
||||
*
|
||||
* @see <a href="https://stackoverflow.com/questions/59364212/integrationtest-isolation-fails-in-springboot-2-2-2-release-error-dopping-table">
|
||||
* StackOverflow#59364212
|
||||
* </a>
|
||||
* @see <a href="https://stackoverflow.com/questions/59561551/hibernate-h2-specify-drop-table-order">
|
||||
* StackOverflow#59561551
|
||||
* </a>
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
JdbcTemplate jdbcTemplate = ctx.getBean(JdbcTemplate.class);
|
||||
JdbcTestUtils.dropTables(jdbcTemplate, "Tweet_Likes", "Tweet");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue