Remove use of the (protected) java.util.Calendar class in SDG causing problems when building/running with JDK/JRE 16.
Resolves gh-497.
This commit is contained in:
@@ -19,9 +19,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -92,15 +92,15 @@ public class GemfireTemplateIntegrationTests {
|
||||
@Resource(name = "Users")
|
||||
private Region<String, User> users;
|
||||
|
||||
protected static User newUser(String username) {
|
||||
private static User newUser(String username) {
|
||||
return newUser(username, true);
|
||||
}
|
||||
|
||||
protected static User newUser(String username, Boolean active) {
|
||||
return newUser(username, String.format("%1$s@companyx.com", username), Calendar.getInstance(), active);
|
||||
private static User newUser(String username, Boolean active) {
|
||||
return newUser(username, String.format("%1$s@companyx.com", username), Instant.now(), active);
|
||||
}
|
||||
|
||||
protected static User newUser(String username, String email, Calendar since, Boolean active) {
|
||||
private static User newUser(String username, String email, Instant since, Boolean active) {
|
||||
|
||||
User user = new User(username);
|
||||
|
||||
@@ -111,11 +111,11 @@ public class GemfireTemplateIntegrationTests {
|
||||
return user;
|
||||
}
|
||||
|
||||
protected String getKey(User user) {
|
||||
private String getKey(User user) {
|
||||
return user != null ? user.getUsername() : null;
|
||||
}
|
||||
|
||||
protected User getUser(String username) {
|
||||
private User getUser(String username) {
|
||||
|
||||
for (User user : TEST_USERS) {
|
||||
if (user.getUsername().equals(username)) {
|
||||
@@ -126,7 +126,7 @@ public class GemfireTemplateIntegrationTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<User> getUsers(String... usernames) {
|
||||
private List<User> getUsers(String... usernames) {
|
||||
|
||||
List<String> usernameList = Arrays.asList(usernames);
|
||||
List<User> users = new ArrayList<>(usernames.length);
|
||||
@@ -140,15 +140,15 @@ public class GemfireTemplateIntegrationTests {
|
||||
return users;
|
||||
}
|
||||
|
||||
protected Map<String, User> getUsersAsMap(String... usernames) {
|
||||
private Map<String, User> getUsersAsMap(String... usernames) {
|
||||
return getUsersAsMap(getUsers(usernames));
|
||||
}
|
||||
|
||||
protected Map<String, User> getUsersAsMap(User... users) {
|
||||
private Map<String, User> getUsersAsMap(User... users) {
|
||||
return getUsersAsMap(Arrays.asList(users));
|
||||
}
|
||||
|
||||
protected Map<String, User> getUsersAsMap(Iterable<User> users) {
|
||||
private Map<String, User> getUsersAsMap(Iterable<User> users) {
|
||||
|
||||
Map<String, User> userMap = new HashMap<>();
|
||||
|
||||
@@ -159,7 +159,7 @@ public class GemfireTemplateIntegrationTests {
|
||||
return userMap;
|
||||
}
|
||||
|
||||
protected void assertNullEquals(Object value1, Object value2) {
|
||||
private void assertNullEquals(Object value1, Object value2) {
|
||||
assertThat(Objects.equals(value1, value2)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.time.Month;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -73,7 +72,7 @@ public class LocalOnlyClientCacheIntegrationTests {
|
||||
public void putAndGetPersonIsSuccessful() {
|
||||
|
||||
Person jonDoe = Person.newPerson("Jon", "Doe",
|
||||
Person.newBirthDate(1974, Calendar.MAY, 5), Gender.MALE);
|
||||
Person.newBirthDate(1974, Month.MAY, 5), Gender.MALE);
|
||||
|
||||
assertThat(this.people).hasSize(0);
|
||||
assertThat(this.people.put(jonDoe.getId(), jonDoe));
|
||||
|
||||
@@ -13,20 +13,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.gemfire.test.model.Person.newBirthDate;
|
||||
import static org.springframework.data.gemfire.test.model.Person.newPerson;
|
||||
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.CacheFactory;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
@@ -34,10 +37,6 @@ import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.query.Index;
|
||||
import org.apache.geode.cache.query.QueryService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -54,7 +53,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link DefinedIndexesApplicationListener}.
|
||||
* Integration Tests for {@link DefinedIndexesApplicationListener}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -102,10 +101,10 @@ public class DefinedIndexesIntegrationTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
put(people, newPerson("Jon", "Doe", newBirthDate(1989, Calendar.NOVEMBER, 11), Gender.MALE));
|
||||
put(people, newPerson("Jane", "Doe", newBirthDate(1991, Calendar.APRIL, 4), Gender.FEMALE));
|
||||
put(people, newPerson("Pie", "Doe", newBirthDate(2008, Calendar.JUNE, 21), Gender.FEMALE));
|
||||
put(people, newPerson("Cookie", "Doe", newBirthDate(2008, Calendar.AUGUST, 14), Gender.FEMALE));
|
||||
put(people, newPerson("Jon", "Doe", newBirthDate(1989, Month.NOVEMBER, 11), Gender.MALE));
|
||||
put(people, newPerson("Jane", "Doe", newBirthDate(1991, Month.APRIL, 4), Gender.FEMALE));
|
||||
put(people, newPerson("Pie", "Doe", newBirthDate(2008, Month.JUNE, 21), Gender.FEMALE));
|
||||
put(people, newPerson("Cookie", "Doe", newBirthDate(2008, Month.AUGUST, 14), Gender.FEMALE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.repository.sample;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Calendar;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class User implements Comparable<User> {
|
||||
|
||||
private Boolean active = true;
|
||||
|
||||
private Calendar since;
|
||||
private Instant since;
|
||||
|
||||
private String email;
|
||||
|
||||
@@ -71,11 +72,16 @@ public class User implements Comparable<User> {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public void setSince(final Calendar since) {
|
||||
@Deprecated
|
||||
public void setSince(Calendar since) {
|
||||
setSince(Instant.ofEpochMilli(since.getTimeInMillis()));
|
||||
}
|
||||
|
||||
public void setSince(Instant since) {
|
||||
this.since = since;
|
||||
}
|
||||
|
||||
public Calendar getSince() {
|
||||
public Instant getSince() {
|
||||
return this.since;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.repository.sample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -21,22 +20,22 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The RepositoryQueriesTest class is a test suite of test cases testing the GemFire Query capability of Spring Data
|
||||
@@ -46,24 +45,26 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.3.3
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("userRepositoryQueriesIntegrationTest.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class UserRepositoryQueriesIntegrationTest {
|
||||
|
||||
@Resource(name = "Users")
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Region users;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
protected static void assertQueryResults(final Iterable<User> actualUsers, final String... expectedUsernames) {
|
||||
private static void assertQueryResults(Iterable<User> actualUsers, String... expectedUsernames) {
|
||||
|
||||
assertNotNull("The query did not return any results!", actualUsers);
|
||||
|
||||
List<String> actualUsernames = new ArrayList<String>(expectedUsernames.length);
|
||||
List<String> actualUsernames = new ArrayList<>(expectedUsernames.length);
|
||||
|
||||
for (User actualUser : actualUsers) {
|
||||
actualUsernames.add(actualUser.getUsername());
|
||||
@@ -73,28 +74,32 @@ public class UserRepositoryQueriesIntegrationTest {
|
||||
assertTrue(actualUsernames.containsAll(Arrays.asList(expectedUsernames)));
|
||||
}
|
||||
|
||||
protected static User createUser(final String username) {
|
||||
private static User createUser(String username) {
|
||||
return createUser(username, true);
|
||||
}
|
||||
|
||||
protected static User createUser(final String username, final Boolean active) {
|
||||
return createUser(username, active, Calendar.getInstance(), String.format("%1$s@xcompany.com", username));
|
||||
private static User createUser(String username, Boolean active) {
|
||||
return createUser(username, active, Instant.now(), String.format("%1$s@xcompany.com", username));
|
||||
}
|
||||
|
||||
protected static User createUser(final String username, final Boolean active, final Calendar since, final String email) {
|
||||
private static User createUser(String username, Boolean active, Instant since, String email) {
|
||||
|
||||
User user = new User(username);
|
||||
|
||||
user.setActive(active);
|
||||
user.setEmail(email);
|
||||
user.setSince(since);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
protected static int toIntValue(final Integer value) {
|
||||
return (value == null ? 0 : value);
|
||||
}
|
||||
private static int toIntValue(final Integer value) {
|
||||
return value != null ? value : 0;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
assertNotNull("The 'Users' GemFire Cache Region cannot be null!", users);
|
||||
|
||||
if (users.isEmpty()) {
|
||||
@@ -115,6 +120,7 @@ public class UserRepositoryQueriesIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testMultiResultQueries() {
|
||||
|
||||
List<User> activeUsers = userRepository.findDistinctByActiveTrue();
|
||||
|
||||
assertQueryResults(activeUsers, "blumj", "blums", "handyj", "doej");
|
||||
@@ -126,28 +132,22 @@ public class UserRepositoryQueriesIntegrationTest {
|
||||
List<User> blumUsers = userRepository.findDistinctByUsernameLike("blum%");
|
||||
|
||||
assertQueryResults(blumUsers, "blumj", "blums", "blume");
|
||||
|
||||
/*
|
||||
List<User> nonHandyUsers = userRepository.findDistinctByUsernameNotLike("handy%");
|
||||
|
||||
assertQueryResults(nonHandyUsers, "blumj", "blums", "blume", "bloomr", "doej", "doep", "doec");
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonCollectionNonEntityResultQueries() {
|
||||
Integer count = userRepository.countUsersByUsernameLike("doe%");
|
||||
@Test
|
||||
public void testNonCollectionNonEntityResultQueries() {
|
||||
|
||||
assertEquals(3, toIntValue(count));
|
||||
Integer count = userRepository.countUsersByUsernameLike("doe%");
|
||||
|
||||
count = userRepository.countUsersByUsernameLike("handy%");
|
||||
assertEquals(3, toIntValue(count));
|
||||
|
||||
assertEquals(2, toIntValue(count));
|
||||
count = userRepository.countUsersByUsernameLike("handy%");
|
||||
|
||||
count = userRepository.countUsersByUsernameLike("smith%");
|
||||
assertEquals(2, toIntValue(count));
|
||||
|
||||
assertNotNull(count);
|
||||
assertEquals(0, toIntValue(count));
|
||||
}
|
||||
count = userRepository.countUsersByUsernameLike("smith%");
|
||||
|
||||
assertNotNull(count);
|
||||
assertEquals(0, toIntValue(count));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
@@ -32,6 +32,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.CacheClosedException;
|
||||
import org.apache.geode.cache.CacheFactory;
|
||||
@@ -40,10 +44,6 @@ import org.apache.geode.cache.CacheLoaderException;
|
||||
import org.apache.geode.cache.LoaderHelper;
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -267,20 +267,21 @@ public class SpringContextBootstrappingInitializerIntegrationTest {
|
||||
private DataSource userDataSource;
|
||||
|
||||
protected static User createUser(String username) {
|
||||
return createUser(username, true, Calendar.getInstance(), String.format("%1$s@xcompay.com", username));
|
||||
return createUser(username, true, Instant.now(), String.format("%1$s@xcompay.com", username));
|
||||
}
|
||||
|
||||
protected static User createUser(String username, Boolean active) {
|
||||
return createUser(username, active, Calendar.getInstance(), String.format("%1$s@xcompay.com", username));
|
||||
return createUser(username, active, Instant.now(), String.format("%1$s@xcompay.com", username));
|
||||
}
|
||||
|
||||
protected static User createUser(String username, Boolean active, Calendar since) {
|
||||
protected static User createUser(String username, Boolean active, Instant since) {
|
||||
return createUser(username, active, since, String.format("%1$s@xcompay.com", username));
|
||||
}
|
||||
|
||||
protected static User createUser(String username, Boolean active, Calendar since, String email) {
|
||||
protected static User createUser(String username, Boolean active, Instant since, String email) {
|
||||
|
||||
User user = new User(username);
|
||||
|
||||
user.setActive(active);
|
||||
user.setEmail(email);
|
||||
user.setSince(since);
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.test.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -68,14 +69,15 @@ public class Person implements Comparable<Person>, Serializable {
|
||||
|
||||
public static Date newBirthDate(int year, int month, int dayOfMonth) {
|
||||
|
||||
Calendar birthDate = Calendar.getInstance();
|
||||
return new Date(LocalDate.of(year, month, dayOfMonth)
|
||||
.atStartOfDay()
|
||||
.atZone(ZoneOffset.systemDefault())
|
||||
.toInstant()
|
||||
.toEpochMilli());
|
||||
}
|
||||
|
||||
birthDate.clear();
|
||||
birthDate.set(Calendar.YEAR, year);
|
||||
birthDate.set(Calendar.MONTH, month);
|
||||
birthDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||
|
||||
return birthDate.getTime();
|
||||
public static Date newBirthDate(int year, Month month, int dayOfMonth) {
|
||||
return newBirthDate(year, month.getValue(), dayOfMonth);
|
||||
}
|
||||
|
||||
public static Person newPerson(String firstName, String lastName, Date birthDate, Gender gender) {
|
||||
|
||||
Reference in New Issue
Block a user