Skip to content

Commit

Permalink
testcase for orphan-oss#23 - Exception selecting overloaded method in…
Browse files Browse the repository at this point in the history
… 3.1.4
  • Loading branch information
marvin-enthus committed May 17, 2016
1 parent d5f4fd8 commit f599e6f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/test/java/org/ognl/test/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
package org.ognl.test;

import junit.framework.TestSuite;

import java.util.Arrays;
import java.util.List;

import org.ognl.test.objects.*;

public class MethodTest extends OgnlTestCase
Expand Down Expand Up @@ -71,6 +75,8 @@ public class MethodTest extends OgnlTestCase
// Java 'ROOT.getTestMethods().argsTest1(Arrays.asList( ROOT.getOne() )' doesn't compile:
// --> The method argsTest(Object[]) in the type MethodTestMethods is not applicable for the arguments (List<Integer>)
{ "testMethods.argsTest3({one})", "List: [1]" },
// https://github.com/jkuhnert/ognl/issues/23 - Exception selecting overloaded method in 3.1.4
{ "testMethods.avg({ 5, 5 })", ROOT.getTestMethods().avg((List)Arrays.asList(5, 5)) },
};

public static class A
Expand Down
69 changes: 69 additions & 0 deletions src/test/java/org/ognl/test/objects/MethodTestMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,73 @@ public String argsTest3(List<Object> data) {
return "List: "+data;
}

//---------------------------------------------------------------------
// https://github.com/jkuhnert/ognl/issues/23
// 'avg' tests
//---------------------------------------------------------------------
public double avg(final Iterable<? extends Number> target) {
double total = 0;
int size = 0;
for (final Number element : target) {
total += element.doubleValue();
size++;
}
return total/size;
}

public double avg(final Number[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}

public double avg(final byte[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}

public double avg(final short[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}

public double avg(final int[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}

public double avg(final long[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}

public double avg(final float[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}

public double avg(final double[] target) {
double total = 0;
for (final Number element : target) {
total += element.doubleValue();
}
return total/target.length;
}
}

0 comments on commit f599e6f

Please sign in to comment.