Skip to content

Commit

Permalink
Update the tests for generics changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed May 25, 2021
1 parent 824741b commit b5d244c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/test/java/org/glassfish/el/test/ConvertTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -26,6 +27,8 @@
import org.junit.Test;
import static org.junit.Assert.*;

import java.lang.reflect.InvocationTargetException;

/**
*
* @author kichung
Expand Down Expand Up @@ -100,10 +103,16 @@ public void testVoid() {
public void testCustom() {
elp.getELManager().addELResolver(new TypeConverter() {
@Override
public Object convertToType(ELContext context, Object obj, Class<?> type) {
public <T> T convertToType(ELContext context, Object obj, Class<T> type) {
if (obj instanceof String && type == MyBean.class) {
context.setPropertyResolved(true);
return new MyBean((String) obj);
try {
T result = type.getConstructor(String.class).newInstance(obj);
context.setPropertyResolved(true);
return result;
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
InvocationTargetException | NoSuchMethodException | SecurityException e) {
// Can't happen as MyBean has a suitable constructor
}
}
return null;
}
Expand Down

0 comments on commit b5d244c

Please sign in to comment.