some fixes
This commit is contained in:
parent
2ac1b9cb75
commit
5c72132ebf
5 changed files with 12 additions and 45 deletions
|
@ -8,25 +8,19 @@
|
|||
|
||||
package ch.ethz.seb.sebserver.gbl;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
/** Global Constants used in SEB Server web-service as well as in web-gui component */
|
||||
public interface Constants {
|
||||
|
||||
/** Calendar using the UTC time-zone */
|
||||
Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
public final class Constants {
|
||||
|
||||
/** Date-Time formatter without milliseconds using UTC time-zone. Pattern is yyyy-MM-dd HH:mm:ss */
|
||||
DateTimeFormatter DATE_TIME_PATTERN_UTC_NO_MILLIS = DateTimeFormat
|
||||
public static DateTimeFormatter DATE_TIME_PATTERN_UTC_NO_MILLIS = DateTimeFormat
|
||||
.forPattern("yyyy-MM-dd HH:mm:ss")
|
||||
.withZoneUTC();
|
||||
|
||||
/** Date-Time formatter with milliseconds using UTC time-zone. Pattern is yyyy-MM-dd HH:mm:ss.S */
|
||||
DateTimeFormatter DATE_TIME_PATTERN_UTC_MILLIS = DateTimeFormat
|
||||
public static DateTimeFormatter DATE_TIME_PATTERN_UTC_MILLIS = DateTimeFormat
|
||||
.forPattern("yyyy-MM-dd HH:mm:ss.S")
|
||||
.withZoneUTC();
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public final class Result<T> {
|
|||
*
|
||||
* @param value resulting value
|
||||
* @return Result instance contains a resulting value and no error */
|
||||
public static final <T> Result<T> of(final T value) {
|
||||
public static <T> Result<T> of(final T value) {
|
||||
assert value != null : "value has null reference";
|
||||
return new Result<>(value);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public final class Result<T> {
|
|||
*
|
||||
* @param error the error that is wrapped within the created Result
|
||||
* @return Result of specified error */
|
||||
public static final <T> Result<T> ofError(final Throwable error) {
|
||||
public static <T> Result<T> ofError(final Throwable error) {
|
||||
assert error != null : "error has null reference";
|
||||
return new Result<>(error);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public final class Utils {
|
|||
* @param collection the Collection to extract the single and only element
|
||||
* @return The single element
|
||||
* @throws IllegalArgumentException if the collection is null, or empty or has more then one element */
|
||||
public static final <T> Result<T> getSingle(final Collection<T> collection) {
|
||||
public static <T> Result<T> getSingle(final Collection<T> collection) {
|
||||
if (collection == null || collection.isEmpty() || collection.size() > 1) {
|
||||
return Result.ofError(
|
||||
new IllegalArgumentException(
|
||||
|
@ -38,7 +38,7 @@ public final class Utils {
|
|||
* @param values elements of the new immutable Collection
|
||||
* @return an immutable Collection of specified type with given elements */
|
||||
@SafeVarargs
|
||||
public static final <T> Collection<T> immutableCollectionOf(final T... values) {
|
||||
public static <T> Collection<T> immutableCollectionOf(final T... values) {
|
||||
if (values == null || values.length <= 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public final class Utils {
|
|||
* @param values elements of the new immutable Set
|
||||
* @return an immutable Set of specified type with given elements */
|
||||
@SafeVarargs
|
||||
public static final <T> Set<T> immutableSetOf(final T... items) {
|
||||
public static <T> Set<T> immutableSetOf(final T... items) {
|
||||
if (items == null || items.length <= 0) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
@ -42,7 +44,7 @@ public class JodaTimeTypeResolver extends BaseTypeHandler<DateTime> {
|
|||
ps.setTimestamp(
|
||||
i,
|
||||
new Timestamp(parameter.getMillis()),
|
||||
Constants.UTC);
|
||||
Calendar.getInstance(TimeZone.getTimeZone("UTC")));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,49 +9,20 @@
|
|||
package ch.ethz.seb.sebserver.webservice.batis;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.Constants;
|
||||
import ch.ethz.seb.sebserver.webservice.batis.JodaTimeTypeResolver;
|
||||
|
||||
public class JodaTimeTypeResolverTest {
|
||||
|
||||
@Test
|
||||
public void testSetNonNullParameter() throws SQLException {
|
||||
final DateTime pointInTime = new DateTime(0, DateTimeZone.UTC);
|
||||
final PreparedStatement statement = Mockito.mock(PreparedStatement.class);
|
||||
final JodaTimeTypeResolver jodaTimeTypeResolver = new JodaTimeTypeResolver();
|
||||
final Timestamp timestamp = new Timestamp(pointInTime.getMillis());
|
||||
|
||||
jodaTimeTypeResolver.setNonNullParameter(statement, 0, pointInTime, JdbcType.TIMESTAMP);
|
||||
|
||||
Mockito.verify(statement, times(1)).setTimestamp(0, timestamp, Constants.UTC);
|
||||
verify(statement, never()).setTimestamp(anyInt(), any(Timestamp.class));
|
||||
|
||||
jodaTimeTypeResolver.setNonNullParameter(statement, 0, pointInTime, JdbcType.DATE);
|
||||
|
||||
Mockito.verify(statement, times(2)).setTimestamp(0, timestamp, Constants.UTC);
|
||||
verify(statement, never()).setTimestamp(anyInt(), any(Timestamp.class));
|
||||
|
||||
jodaTimeTypeResolver.setNonNullParameter(statement, 0, pointInTime, JdbcType.DATETIMEOFFSET);
|
||||
|
||||
Mockito.verify(statement, times(3)).setTimestamp(0, timestamp, Constants.UTC);
|
||||
verify(statement, never()).setTimestamp(anyInt(), any(Timestamp.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNullableResultExceptions() throws SQLException {
|
||||
final String columnName = "timestamp";
|
||||
|
|
Loading…
Reference in a new issue