-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bc50001
commit fc3988b
Showing
13 changed files
with
391 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...kus/test/junit/internal/TestInfoImpl.java → ...a/io/quarkus/test/junit/TestInfoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.test.junit.internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
import com.thoughtworks.xstream.converters.collections.CollectionConverter; | ||
import com.thoughtworks.xstream.mapper.Mapper; | ||
|
||
/** | ||
* A custom List converter that always uses ArrayList for unmarshalling. | ||
* This is probably not semantically correct 100% of the time, but it's likely fine | ||
* for all the cases where we are using marshalling / unmarshalling. | ||
* | ||
* The reason for doing this is to avoid XStream causing illegal access issues | ||
* for internal JDK lists | ||
*/ | ||
public class CustomListConverter extends CollectionConverter { | ||
|
||
// if we wanted to be 100% sure, we'd list all the List.of methods, but I think it's pretty safe to say | ||
// that the JDK won't add custom implementations for the other classes | ||
|
||
private final Predicate<String> supported = new Predicate<String>() { | ||
|
||
private final Set<String> JDK_LIST_CLASS_NAMES = Set.of( | ||
List.of().getClass().getName(), | ||
List.of(Integer.MAX_VALUE).getClass().getName(), | ||
Arrays.asList(Integer.MAX_VALUE).getClass().getName(), | ||
Collections.unmodifiableList(List.of()).getClass().getName(), | ||
Collections.emptyList().getClass().getName(), | ||
List.of(Integer.MIN_VALUE, Integer.MAX_VALUE).subList(0, 1).getClass().getName()); | ||
|
||
@Override | ||
public boolean test(String className) { | ||
return JDK_LIST_CLASS_NAMES.contains(className); | ||
} | ||
}.or(new Predicate<>() { | ||
|
||
private static final String GUAVA_LISTS_PACKAGE = "com.google.common.collect.Lists"; | ||
|
||
@Override | ||
public boolean test(String className) { | ||
return className.startsWith(GUAVA_LISTS_PACKAGE); | ||
} | ||
}); | ||
|
||
public CustomListConverter(Mapper mapper) { | ||
super(mapper); | ||
} | ||
|
||
@Override | ||
public boolean canConvert(Class type) { | ||
return (type != null) && supported.test(type.getName()); | ||
} | ||
|
||
@Override | ||
protected Object createCollection(Class type) { | ||
return new ArrayList<>(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomMapConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.test.junit.internal; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.thoughtworks.xstream.converters.collections.MapConverter; | ||
import com.thoughtworks.xstream.mapper.Mapper; | ||
|
||
/** | ||
* A custom Map converter that always uses HashMap for unmarshalling. | ||
* This is probably not semantically correct 100% of the time, but it's likely fine | ||
* for all the cases where we are using marshalling / unmarshalling. | ||
* | ||
* The reason for doing this is to avoid XStream causing illegal access issues | ||
* for internal JDK maps | ||
*/ | ||
public class CustomMapConverter extends MapConverter { | ||
|
||
// if we wanted to be 100% sure, we'd list all the Set.of methods, but I think it's pretty safe to say | ||
// that the JDK won't add custom implementations for the other classes | ||
private final Set<String> SUPPORTED_CLASS_NAMES = Set.of( | ||
Map.of().getClass().getName(), | ||
Map.of(Integer.MAX_VALUE, Integer.MAX_VALUE).getClass().getName(), | ||
Collections.emptyMap().getClass().getName()); | ||
|
||
public CustomMapConverter(Mapper mapper) { | ||
super(mapper); | ||
} | ||
|
||
@Override | ||
public boolean canConvert(Class type) { | ||
return (type != null) && SUPPORTED_CLASS_NAMES.contains(type.getName()); | ||
} | ||
|
||
@Override | ||
protected Object createCollection(Class type) { | ||
return new HashMap<>(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ramework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomMapEntryConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkus.test.junit.internal; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.thoughtworks.xstream.converters.MarshallingContext; | ||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.converters.collections.MapConverter; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; | ||
import com.thoughtworks.xstream.mapper.Mapper; | ||
|
||
/** | ||
* A custom Map.Entry converter that always uses AbstractMap.SimpleEntry for unmarshalling. | ||
* This is probably not semantically correct 100% of the time, but it's likely fine | ||
* for all the cases where we are using marshalling / unmarshalling. | ||
* | ||
* The reason for doing this is to avoid XStream causing illegal access issues | ||
* for internal JDK types | ||
*/ | ||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
public class CustomMapEntryConverter extends MapConverter { | ||
|
||
private final Set<String> SUPPORTED_CLASS_NAMES = Set | ||
.of(Map.entry(Integer.MAX_VALUE, Integer.MAX_VALUE).getClass().getName()); | ||
|
||
public CustomMapEntryConverter(Mapper mapper) { | ||
super(mapper); | ||
} | ||
|
||
@Override | ||
public boolean canConvert(Class type) { | ||
return (type != null) && SUPPORTED_CLASS_NAMES.contains(type.getName()); | ||
} | ||
|
||
@Override | ||
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { | ||
var entryName = mapper().serializedClass(Map.Entry.class); | ||
var entry = (Map.Entry) source; | ||
writer.startNode(entryName); | ||
writeCompleteItem(entry.getKey(), context, writer); | ||
writeCompleteItem(entry.getValue(), context, writer); | ||
writer.endNode(); | ||
} | ||
|
||
@Override | ||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
reader.moveDown(); | ||
var key = readCompleteItem(reader, context, null); | ||
var value = readCompleteItem(reader, context, null); | ||
reader.moveUp(); | ||
return new AbstractMap.SimpleEntry(key, value); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test-framework/junit5/src/main/java/io/quarkus/test/junit/internal/CustomSetConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkus.test.junit.internal; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import com.thoughtworks.xstream.converters.collections.CollectionConverter; | ||
import com.thoughtworks.xstream.mapper.Mapper; | ||
|
||
/** | ||
* A custom Set converter that always uses HashSet for unmarshalling. | ||
* This is probably not semantically correct 100% of the time, but it's likely fine | ||
* for all the cases where we are using marshalling / unmarshalling. | ||
* | ||
* The reason for doing this is to avoid XStream causing illegal access issues | ||
* for internal JDK sets | ||
*/ | ||
public class CustomSetConverter extends CollectionConverter { | ||
|
||
// if we wanted to be 100% sure, we'd list all the Set.of methods, but I think it's pretty safe to say | ||
// that the JDK won't add custom implementations for the other classes | ||
private final Set<String> SUPPORTED_CLASS_NAMES = Set.of( | ||
Set.of().getClass().getName(), | ||
Set.of(Integer.MAX_VALUE).getClass().getName(), | ||
Collections.emptySet().getClass().getName()); | ||
|
||
public CustomSetConverter(Mapper mapper) { | ||
super(mapper); | ||
} | ||
|
||
@Override | ||
public boolean canConvert(Class type) { | ||
return (type != null) && SUPPORTED_CLASS_NAMES.contains(type.getName()); | ||
} | ||
|
||
@Override | ||
protected Object createCollection(Class type) { | ||
return new HashSet<>(); | ||
} | ||
} |
Oops, something went wrong.