Issue 647: normalized use of IllegalArgumentException

This commit is contained in:
Adrian Cole 2012-05-22 11:24:52 -06:00
parent 4c5ac30341
commit f8280ec56c
16 changed files with 297 additions and 149 deletions

View File

@ -1,11 +1,40 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.date;
import java.text.ParseException;
import java.util.Date;
/**
* converting from Date->String and vice versa.
*
* @author aled
*/
public interface DateCodec {
public Date toDate(String date) throws ParseException;
/**
* @param toParse
* text to parse
* @return parsed date
* @throws IllegalArgumentException
* if the input is invalid
*/
public Date toDate(String date) throws IllegalArgumentException;
public String toString(Date date);

View File

@ -1,6 +1,24 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.date;
import org.jclouds.date.internal.SimpleDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory;
import com.google.inject.ImplementedBy;
@ -10,7 +28,7 @@ import com.google.inject.ImplementedBy;
*
* @author aled
*/
@ImplementedBy(SimpleDateCodecFactory.class)
@ImplementedBy(DateServiceDateCodecFactory.class)
public interface DateCodecFactory {
public DateCodec rfc1123();

View File

@ -40,13 +40,23 @@ public interface DateService {
String cDateFormat();
Date cDateParse(String toParse);
/**
* @param toParse text to parse
* @return parsed date
* @throws IllegalArgumentException if the input is invalid
*/
Date cDateParse(String toParse) throws IllegalArgumentException;
String rfc822DateFormat(Date date);
String rfc822DateFormat();
Date rfc822DateParse(String toParse);
/**
* @param toParse text to parse
* @return parsed date
* @throws IllegalArgumentException if the input is invalid
*/
Date rfc822DateParse(String toParse) throws IllegalArgumentException;
String iso8601SecondsDateFormat(Date dateTime);
@ -56,14 +66,29 @@ public interface DateService {
String iso8601DateFormat();
Date iso8601DateParse(String toParse);
/**
* @param toParse text to parse
* @return parsed date
* @throws IllegalArgumentException if the input is invalid
*/
Date iso8601DateParse(String toParse) throws IllegalArgumentException;
Date iso8601SecondsDateParse(String toParse);
/**
* @param toParse text to parse
* @return parsed date
* @throws IllegalArgumentException if the input is invalid
*/
Date iso8601SecondsDateParse(String toParse) throws IllegalArgumentException;
String rfc1123DateFormat(Date date);
String rfc1123DateFormat();
Date rfc1123DateParse(String toParse);
/**
* @param toParse text to parse
* @return parsed date
* @throws IllegalArgumentException if the input is invalid
*/
Date rfc1123DateParse(String toParse) throws IllegalArgumentException;
}

View File

@ -0,0 +1,74 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.date.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import javax.inject.Singleton;
import org.jclouds.date.DateCodec;
import org.jclouds.date.DateCodecFactory;
import org.jclouds.date.DateService;
import com.google.inject.Inject;
@Singleton
public class DateServiceDateCodecFactory implements DateCodecFactory {
private final DateCodec rfc1123Codec;
@Inject
public DateServiceDateCodecFactory(DateServiceRfc1123Codec rfc1123Codec) {
this.rfc1123Codec = checkNotNull(rfc1123Codec, "rfc1123Codec");
}
@Singleton
public static class DateServiceRfc1123Codec implements DateCodec {
private final DateService dateService;
@Inject
public DateServiceRfc1123Codec(final DateService dateService) {
this.dateService = checkNotNull(dateService, "dateService");
}
@Override
public Date toDate(String date) throws IllegalArgumentException {
return dateService.rfc1123DateParse(date);
}
@Override
public String toString(Date date) {
return dateService.rfc1123DateFormat(date);
}
@Override
public String toString() {
return "rfc1123Codec [dateService=" + dateService + "]";
}
}
public DateCodec rfc1123() {
return rfc1123Codec;
}
}

View File

@ -1,41 +0,0 @@
package org.jclouds.date.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.text.ParseException;
import java.util.Date;
import org.jclouds.date.DateCodec;
import org.jclouds.date.DateCodecFactory;
import org.jclouds.date.DateService;
import com.google.inject.Inject;
public class SimpleDateCodecFactory implements DateCodecFactory {
private final DateService dateService;
private volatile DateCodec rfc1123Codec;
@Inject
public SimpleDateCodecFactory(final DateService dateService) {
this.dateService = checkNotNull(dateService, "dateService");
}
public DateCodec rfc1123() {
if (rfc1123Codec == null) {
rfc1123Codec = new DateCodec() {
@Override
public Date toDate(String date) throws ParseException {
return dateService.rfc1123DateParse(date);
}
@Override
public String toString(Date date) {
return dateService.rfc1123DateFormat(date);
}
};
}
return rfc1123Codec;
}
}

View File

@ -89,7 +89,7 @@ public class SimpleDateFormatDateService implements DateService {
try {
return cSimpleDateFormat.parse(toParse);
} catch (ParseException pe) {
throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe);
throw new IllegalArgumentException("Error parsing data at " + pe.getErrorOffset(), pe);
}
}
}
@ -112,7 +112,7 @@ public class SimpleDateFormatDateService implements DateService {
try {
return rfc822SimpleDateFormat.parse(toParse);
} catch (ParseException pe) {
throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe);
throw new IllegalArgumentException("Error parsing data at " + pe.getErrorOffset(), pe);
}
}
}
@ -141,6 +141,8 @@ public class SimpleDateFormatDateService implements DateService {
@Override
public final Date iso8601DateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
String tz = findTZ(toParse);
toParse = trimToMillis(toParse);
toParse = trimTZ(toParse);
@ -151,13 +153,15 @@ public class SimpleDateFormatDateService implements DateService {
try {
return iso8601SimpleDateFormat.parse(toParse);
} catch (ParseException pe) {
throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe);
throw new IllegalArgumentException("Error parsing data at " + pe.getErrorOffset(), pe);
}
}
}
@Override
public final Date iso8601SecondsDateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
String tz = findTZ(toParse);
toParse = trimToMillis(toParse);
toParse = trimTZ(toParse);
@ -168,7 +172,7 @@ public class SimpleDateFormatDateService implements DateService {
try {
return iso8601SecondsSimpleDateFormat.parse(toParse);
} catch (ParseException pe) {
throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe);
throw new IllegalArgumentException("Error parsing data at " + pe.getErrorOffset(), pe);
}
}
}
@ -198,12 +202,12 @@ public class SimpleDateFormatDateService implements DateService {
}
@Override
public final Date rfc1123DateParse(String toParse) {
public final Date rfc1123DateParse(String toParse) throws IllegalArgumentException {
synchronized (rfc1123SimpleDateFormat) {
try {
return rfc1123SimpleDateFormat.parse(toParse);
} catch (ParseException pe) {
throw new RuntimeException("Error parsing data at " + pe.getErrorOffset(), pe);
throw new IllegalArgumentException("Error parsing data at " + pe.getErrorOffset(), pe);
}
}
}

View File

@ -5,7 +5,6 @@ import static javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH;
import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.HttpHeaders.EXPIRES;
import java.text.ParseException;
import java.util.Date;
import java.util.Map.Entry;
@ -17,10 +16,8 @@ import org.jclouds.date.DateCodec;
import org.jclouds.date.DateCodecFactory;
import org.jclouds.io.ContentMetadataCodec.DefaultContentMetadataCodec;
import org.jclouds.logging.Logger;
import org.jclouds.util.Throwables2;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableMultimap.Builder;
import com.google.common.collect.Multimap;
@ -117,13 +114,10 @@ public interface ContentMetadataCodec {
public Date parseExpires(String expires) {
try {
return (expires != null) ? getExpiresDateCodec().toDate(expires) : null;
} catch (Exception e) {
if (Throwables2.getFirstThrowableOfType(e, ParseException.class) != null) {
logger.debug("Invalid Expires header (%s); should be in RFC-1123 format; treating as already expired: %s", expires, e.getMessage());
return new Date(0);
} else {
throw Throwables.propagate(e);
}
} catch (IllegalArgumentException e) {
logger.debug("Invalid Expires header (%s); should be in RFC-1123 format; treating as already expired: %s",
expires, e.getMessage());
return new Date(0);
}
}
}

View File

@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.jclouds.PerformanceTest;
import org.testng.annotations.BeforeTest;
@ -96,90 +95,110 @@ public class DateServiceTest extends PerformanceTest {
}
@Test
public void testIso8601DateParse() throws ExecutionException, InterruptedException {
public void testIso8601DateParse() {
Date dsDate = dateService.iso8601DateParse(testData[0].iso8601DateString);
assertEquals(dsDate, testData[0].date);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testIso8601DateParseIllegal() {
dateService.iso8601DateParse("-1");
}
@Test
public void testIso8601DateParseTz() throws ExecutionException, InterruptedException {
public void testIso8601DateParseTz() {
Date dsDate = dateService.iso8601SecondsDateParse(testData[0].iso8601DateStringTz);
assertEquals(dsDate, testData[0].date);
}
@Test
public void testIso8601SecondsDateParse() throws ExecutionException, InterruptedException {
public void testIso8601SecondsDateParse() {
Date dsDate = dateService.iso8601SecondsDateParse(testData[0].iso8601SecondsDateString);
assertEquals(dsDate, testData[0].date);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testIso8601SecondsDateParseIllegal() {
dateService.iso8601SecondsDateParse("-1");
}
@Test
public void testCDateParse() throws ExecutionException, InterruptedException {
public void testCDateParse() {
Date dsDate = dateService.cDateParse(testData[0].cDateString);
assertEquals(dsDate, testData[0].date);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testCDateParseIllegal() {
dateService.cDateParse("foo");
}
@Test
public void testRfc822DateParse() throws ExecutionException, InterruptedException {
public void testRfc822DateParse() {
Date dsDate = dateService.rfc822DateParse(testData[0].rfc822DateString);
assertEquals(dsDate, testData[0].date);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testRfc822DateParseIllegal() {
dateService.rfc822DateParse("foo");
}
@Test
public void testIso8601DateFormat() throws ExecutionException, InterruptedException {
public void testIso8601DateFormat() {
String dsString = dateService.iso8601DateFormat(testData[0].date);
assertEquals(dsString, testData[0].iso8601DateString);
}
@Test
public void testIso8601SecondsDateFormat() throws ExecutionException, InterruptedException {
public void testIso8601SecondsDateFormat() {
String dsString = dateService.iso8601SecondsDateFormat(testData[0].date);
assertEquals(dsString, testData[0].iso8601SecondsDateString);
}
@Test
public void testCDateFormat() throws ExecutionException, InterruptedException {
public void testCDateFormat() {
String dsString = dateService.cDateFormat(testData[0].date);
assertEquals(dsString, testData[0].cDateString);
}
@Test
public void testRfc822DateFormat() throws ExecutionException, InterruptedException {
public void testRfc822DateFormat() {
String dsString = dateService.rfc822DateFormat(testData[0].date);
assertEquals(dsString, testData[0].rfc822DateString);
}
@Test
void testIso8601DateFormatResponseTime() throws ExecutionException, InterruptedException {
void testIso8601DateFormatResponseTime() {
for (int i = 0; i < LOOP_COUNT; i++)
dateService.iso8601DateFormat();
}
@Test
void testFromSeconds() throws ExecutionException, InterruptedException {
void testFromSeconds() {
long seconds = 1254008225;
Date date = dateService.fromSeconds(seconds);
assertEquals(dateService.iso8601SecondsDateFormat(date), "2009-09-26T23:37:05Z");
}
@Test
void testTz() throws ExecutionException, InterruptedException {
void testTz() {
assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T02:14:13-04:00").getTime(), 1306390453000l);
}
@Test
void testTzNoT() throws ExecutionException, InterruptedException {
void testTzNoT() {
assertEquals(dateService.iso8601DateParse("2011-05-25 16:12:21.656+0000").getTime(), 1306339941656l);
}
@Test
void testRfc822DateFormatResponseTime() throws ExecutionException, InterruptedException {
void testRfc822DateFormatResponseTime() {
for (int i = 0; i < LOOP_COUNT; i++)
dateService.rfc822DateFormat();
}
@Test
void testCDateFormatResponseTime() throws ExecutionException, InterruptedException {
void testCDateFormatResponseTime() {
for (int i = 0; i < LOOP_COUNT; i++)
dateService.cDateFormat();
}
@ -212,7 +231,7 @@ public class DateServiceTest extends PerformanceTest {
}
@Test
void testParseIso8601DateSerialResponseTime() throws ExecutionException, InterruptedException {
void testParseIso8601DateSerialResponseTime() {
for (int i = 0; i < LOOP_COUNT; i++)
dateService.iso8601DateParse(testData[0].iso8601DateString);
}

View File

@ -0,0 +1,65 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.date.internal;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.util.Date;
import org.jclouds.date.DateCodec;
import org.jclouds.date.internal.DateServiceDateCodecFactory.DateServiceRfc1123Codec;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author aled
*
*/
@Test(testName = "DateServiceDateCodecFactoryTest")
public class DateServiceDateCodecFactoryTest {
private DateServiceDateCodecFactory simpleDateCodecFactory;
private DateCodec rfc1123Codec;
@BeforeMethod
public void setUp() {
simpleDateCodecFactory = new DateServiceDateCodecFactory(new DateServiceRfc1123Codec(
new SimpleDateFormatDateService()));
rfc1123Codec = simpleDateCodecFactory.rfc1123();
}
@Test
public void testCodecForRfc1123() {
Date date = new Date(1000);
assertEquals(rfc1123Codec.toDate(rfc1123Codec.toString(date)), date);
assertEquals(rfc1123Codec.toDate("Thu, 01 Dec 1994 16:00:00 GMT"), new Date(786297600000L));
}
@Test
public void testCodecForRfc1123ThrowsParseExceptionWhenMalformed() {
try {
rfc1123Codec.toDate("wrong");
fail();
} catch (IllegalArgumentException e) {
}
}
}

View File

@ -1,44 +0,0 @@
package org.jclouds.date.internal;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.text.ParseException;
import java.util.Date;
import org.jclouds.date.DateCodec;
import org.jclouds.util.Throwables2;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SimpleDateCodecFactoryTest {
private SimpleDateCodecFactory simpleDateCodecFactory;
private DateCodec rfc1123Codec;
@BeforeMethod
public void setUp() throws Exception {
simpleDateCodecFactory = new SimpleDateCodecFactory(new SimpleDateFormatDateService());
rfc1123Codec = simpleDateCodecFactory.rfc1123();
}
@Test
public void testCodecForRfc1123() throws Exception {
Date date = new Date(1000);
assertEquals(rfc1123Codec.toDate(rfc1123Codec.toString(date)), date);
assertEquals(rfc1123Codec.toDate("Thu, 01 Dec 1994 16:00:00 GMT"), new Date(786297600000L));
}
@Test
public void testCodecForRfc1123ThrowsParseExceptionWhenMalformed() throws Exception {
try {
rfc1123Codec.toDate("wrong");
fail();
} catch (Exception e) {
if (Throwables2.getFirstThrowableOfType(e, ParseException.class) == null) {
throw e;
}
}
}
}

View File

@ -34,7 +34,8 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.date.internal.SimpleDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory.DateServiceRfc1123Codec;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.BaseJettyTest;
import org.jclouds.http.HttpCommand;
@ -47,8 +48,8 @@ import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.http.internal.HttpWire;
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
import org.jclouds.io.ContentMetadataCodec;
import org.jclouds.io.Payloads;
import org.jclouds.io.ContentMetadataCodec.DefaultContentMetadataCodec;
import org.jclouds.io.Payloads;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -116,7 +117,7 @@ public class BackoffLimitedRetryHandlerTest {
BackoffLimitedRetryHandler backoff = new BackoffLimitedRetryHandler();
HttpUtils utils = new HttpUtils(0, 500, 1, 1);
ContentMetadataCodec contentMetadataCodec = new DefaultContentMetadataCodec(
new SimpleDateCodecFactory(new SimpleDateFormatDateService()));
new DateServiceDateCodecFactory(new DateServiceRfc1123Codec(new SimpleDateFormatDateService())));
RedirectionRetryHandler retry = new RedirectionRetryHandler(uriBuilderProvider, backoff);
JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService(utils,
contentMetadataCodec, execService,

View File

@ -49,7 +49,8 @@ import org.jclouds.apis.ApiMetadata;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.SingleThreaded;
import org.jclouds.concurrent.config.ConfiguresExecutorService;
import org.jclouds.date.internal.SimpleDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory.DateServiceRfc1123Codec;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpCommandExecutorService;
import org.jclouds.http.HttpRequest;
@ -123,7 +124,7 @@ public abstract class BaseRestClientExpectTest<S> {
protected String provider = "mock";
protected ContentMetadataCodec contentMetadataCodec = new DefaultContentMetadataCodec(
new SimpleDateCodecFactory(new SimpleDateFormatDateService()));
new DateServiceDateCodecFactory(new DateServiceRfc1123Codec(new SimpleDateFormatDateService())));
/**
* Override this to supply alternative bindings for use in the test. This is commonly used to

View File

@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
@ -32,7 +31,8 @@ import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.internal.SimpleDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory.DateServiceRfc1123Codec;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.encryption.internal.JCECrypto;
import org.jclouds.http.HttpRequest;
@ -72,10 +72,10 @@ public class ConvertToGaeRequestTest {
}
@BeforeTest
void setupClient() throws MalformedURLException {
void setupClient() {
endPoint = URI.create("http://localhost:80/foo");
req = new ConvertToGaeRequest(new HttpUtils(0, 0, 0, 0), new DefaultContentMetadataCodec(
new SimpleDateCodecFactory(new SimpleDateFormatDateService())));
new DateServiceDateCodecFactory(new DateServiceRfc1123Codec(new SimpleDateFormatDateService()))));
}

View File

@ -24,7 +24,6 @@ import static org.easymock.EasyMock.replay;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
@ -34,7 +33,8 @@ import java.util.List;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.internal.SimpleDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory;
import org.jclouds.date.internal.DateServiceDateCodecFactory.DateServiceRfc1123Codec;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.encryption.internal.JCECrypto;
import org.jclouds.http.HttpResponse;
@ -68,10 +68,10 @@ public class ConvertToJcloudsResponseTest {
}
@BeforeTest
void setupClient() throws MalformedURLException {
void setupClient() {
endPoint = URI.create("http://localhost:80/foo");
req = new ConvertToJcloudsResponse(new DefaultContentMetadataCodec(
new SimpleDateCodecFactory(new SimpleDateFormatDateService())));
req = new ConvertToJcloudsResponse(new DefaultContentMetadataCodec(new DateServiceDateCodecFactory(
new DateServiceRfc1123Codec(new SimpleDateFormatDateService()))));
}
@Test

View File

@ -111,6 +111,8 @@ public class JodaDateService implements DateService {
}
public final Date iso8601DateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
String tz = findTZ(toParse);
toParse = trimToMillis(toParse);
toParse = trimTZ(toParse);
@ -121,6 +123,8 @@ public class JodaDateService implements DateService {
}
public final Date iso8601SecondsDateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
String tz = findTZ(toParse);
toParse = trimToMillis(toParse);
toParse = trimTZ(toParse);

View File

@ -21,7 +21,6 @@ package org.jclouds.date.joda;
import static org.testng.Assert.assertEquals;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import org.jclouds.date.DateService;
import org.jclouds.date.DateServiceTest;
@ -56,14 +55,14 @@ public class JodaDateServiceTest extends DateServiceTest {
@Override
@Test
public void testRfc822DateFormat() throws ExecutionException, InterruptedException {
public void testRfc822DateFormat() {
String dsString = dateService.rfc822DateFormat(testData[0].date);
assertEquals(dsString, testData[0].rfc822DateString);
}
@Override
@Test(enabled = false)
public void testRfc822DateParse() throws ExecutionException, InterruptedException {
public void testRfc822DateParse() {
Date dsDate = dateService.rfc822DateParse(testData[0].rfc822DateString);
assertEquals(dsDate, testData[0].date);
}