mirror of https://github.com/apache/jclouds.git
JCLOUDS-428: Address Java 8 compatibility nits
Tested with JDK 1.6.0_45, 1.7.0_45, and 1.8.0-ea-b123.
This commit is contained in:
parent
05c2986d08
commit
d5fd82500c
|
@ -54,6 +54,11 @@ public class ParseSaxTest extends BaseHandlerTest {
|
|||
ParseSax<String> createParser() {
|
||||
return factory.create(injector.getInstance(TestHandler.class));
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] runUnderJava6() {
|
||||
return TestUtils.isJava6() ? SINGLE_NO_ARG_INVOCATION : NO_INVOCATIONS;
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] runUnderJava7() {
|
||||
|
@ -61,8 +66,8 @@ public class ParseSaxTest extends BaseHandlerTest {
|
|||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] ignoreUnderJava7() {
|
||||
return TestUtils.isJava7() ? NO_INVOCATIONS : SINGLE_NO_ARG_INVOCATION;
|
||||
public Object[][] runUnderJava8() {
|
||||
return TestUtils.isJava8() ? SINGLE_NO_ARG_INVOCATION : NO_INVOCATIONS;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,7 +134,7 @@ public class ParseSaxTest extends BaseHandlerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ignoreUnderJava7", description = "see http://code.google.com/p/jclouds/issues/detail?id=795")
|
||||
@Test(dataProvider = "runUnderJava6")
|
||||
public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException() throws ExecutionException,
|
||||
InterruptedException, TimeoutException, IOException {
|
||||
|
||||
|
@ -155,7 +160,7 @@ public class ParseSaxTest extends BaseHandlerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "runUnderJava7", description = "see http://code.google.com/p/jclouds/issues/detail?id=795")
|
||||
@Test(dataProvider = "runUnderJava7")
|
||||
public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException_java7() throws ExecutionException,
|
||||
InterruptedException, TimeoutException, IOException {
|
||||
|
||||
|
@ -180,4 +185,30 @@ public class ParseSaxTest extends BaseHandlerTest {
|
|||
assertEquals(e.getCause(), input);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "runUnderJava8")
|
||||
public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException_java8() throws ExecutionException,
|
||||
InterruptedException, TimeoutException, IOException {
|
||||
|
||||
ParseSax<String> parser = createParser();
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://foohost").build();
|
||||
HttpResponse response = HttpResponse.builder().statusCode(304).message("Not Modified").build();
|
||||
Locator locator = createMock(Locator.class);
|
||||
expect(locator.getColumnNumber()).andReturn(1);
|
||||
expect(locator.getLineNumber()).andReturn(1);
|
||||
expect(locator.getPublicId()).andReturn("publicId");
|
||||
expect(locator.getSystemId()).andReturn("systemId");
|
||||
replay(locator);
|
||||
Exception input = new SAXParseException("foo", locator);
|
||||
verify(locator);
|
||||
|
||||
try {
|
||||
parser.setContext(request);
|
||||
parser.addDetailsAndPropagate(response, input);
|
||||
} catch (RuntimeException e) {
|
||||
assertEquals(e.getMessage(),
|
||||
"request: GET http://foohost HTTP/1.1; response: HTTP/1.1 304 Not Modified; error at 1:1 in document systemId; cause: org.xml.sax.SAXParseExceptionpublicId: publicId; systemId: systemId; lineNumber: 1; columnNumber: 1; foo");
|
||||
assertEquals(e.getCause(), input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,12 +139,13 @@ public class JsonTest {
|
|||
}
|
||||
|
||||
public void testMapStringObjectWithAllValidValuesOneDeep() {
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("string", "string");
|
||||
map.put("number", 1.0);
|
||||
map.put("boolean", true);
|
||||
map.put("map", ImmutableMap.of("key", "value"));
|
||||
map.put("list", ImmutableList.of("key", "value"));
|
||||
Map<String, Object> map = ImmutableMap.<String, Object>builder()
|
||||
.put("string", "string")
|
||||
.put("map", ImmutableMap.of("key", "value"))
|
||||
.put("list", ImmutableList.of("key", "value"))
|
||||
.put("boolean", true)
|
||||
.put("number", 1.0)
|
||||
.build();
|
||||
assertEquals(json.toJson(map),
|
||||
"{\"string\":\"string\",\"map\":{\"key\":\"value\"},\"list\":[\"key\",\"value\"],\"boolean\":true,\"number\":1.0}");
|
||||
Map<String, Object> map2 = json.fromJson(json.toJson(map), new TypeLiteral<Map<String, Object>>() {
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.SortedSet;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
@ -92,23 +93,55 @@ public class Reflection2Test {
|
|||
assertEquals(methodInSuper.getParameters().get(0).getType().getRawType(), Object.class);
|
||||
}
|
||||
|
||||
ImmutableSet<String> setMethods = ImmutableSet.of("add", "equals", "hashCode", "clear", "isEmpty", "contains",
|
||||
"addAll", "size", "toArray", "iterator", "remove", "removeAll", "containsAll", "retainAll");
|
||||
ImmutableSet<String> SET_METHODS = ImmutableSet.of(
|
||||
// Java 6 and 7 methods
|
||||
"add",
|
||||
"addAll",
|
||||
"clear",
|
||||
"contains",
|
||||
"containsAll",
|
||||
"equals",
|
||||
"hashCode",
|
||||
"isEmpty",
|
||||
"iterator",
|
||||
"remove",
|
||||
"removeAll",
|
||||
"retainAll",
|
||||
"size",
|
||||
"toArray",
|
||||
// Java 8 methods
|
||||
"forEach",
|
||||
"parallelStream",
|
||||
"removeIf",
|
||||
"spliterator",
|
||||
"stream");
|
||||
|
||||
ImmutableSet<String> SORTED_SET_METHODS = ImmutableSet.<String>builder()
|
||||
.addAll(SET_METHODS)
|
||||
.add("comparator")
|
||||
.add("first")
|
||||
.add("headSet")
|
||||
.add("last")
|
||||
.add("subSet")
|
||||
.add("tailSet")
|
||||
.build();
|
||||
|
||||
public void testMethods() {
|
||||
Set<String> methodNames = FluentIterable.from(methods(Set.class)).transform(invokableToName)
|
||||
.transform(toStringFunction()).toSet();
|
||||
.transform(toStringFunction())
|
||||
.filter(Predicates.not(Predicates.<String>in(SET_METHODS)))
|
||||
.toSet();
|
||||
|
||||
assertEquals(methodNames, setMethods);
|
||||
assertEquals(methodNames, ImmutableSet.<String>of());
|
||||
}
|
||||
|
||||
public void testMethodsSubClass() {
|
||||
Set<String> methodNames = FluentIterable.from(methods(SortedSet.class)).transform(invokableToName)
|
||||
.transform(toStringFunction()).toSet();
|
||||
.transform(toStringFunction())
|
||||
.filter(Predicates.not(Predicates.<String>in(SORTED_SET_METHODS)))
|
||||
.toSet();
|
||||
|
||||
assertEquals(methodNames,
|
||||
ImmutableSet.builder().add("comparator", "last", "first", "subSet", "headSet", "tailSet")
|
||||
.addAll(setMethods).build());
|
||||
assertEquals(methodNames, ImmutableSet.<String>of());
|
||||
}
|
||||
|
||||
static final Function<Invokable<?, ?>, String> invokableToName = new Function<Invokable<?, ?>, String>() {
|
||||
|
|
|
@ -26,8 +26,18 @@ public class TestUtils {
|
|||
public static final Object[][] NO_INVOCATIONS = new Object[0][0];
|
||||
public static final Object[][] SINGLE_NO_ARG_INVOCATION = { new Object[0] };
|
||||
|
||||
public static boolean isJava6() {
|
||||
System.out.println(System.getProperty("java.version", "None??"));
|
||||
return System.getProperty("java.version", "").contains("1.6.");
|
||||
}
|
||||
|
||||
public static boolean isJava7() {
|
||||
System.out.println(System.getProperty("java.version", "None??"));
|
||||
return System.getProperty("java.version", "").contains("1.7.");
|
||||
}
|
||||
|
||||
public static boolean isJava8() {
|
||||
System.out.println(System.getProperty("java.version", "None??"));
|
||||
return System.getProperty("java.version", "").contains("1.8.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue