Skip to content

Commit

Permalink
Removed method constraints for MonetayrAmount.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsticks committed Oct 12, 2013
1 parent edabff1 commit 90fe55c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 125 deletions.
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>${impl.groupId}</groupId>
<artifactId>${impl.artifactId}</artifactId>
<groupId>org.javamoney.ri</groupId>
<artifactId>jsr354-ri</artifactId>
<version>${impl.version}</version>
<type>${impl.packageType}</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.test-audit</groupId>
Expand Down
128 changes: 5 additions & 123 deletions src/main/java/org/javamoney/tck/tests/MonetaryAmountClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,134 +34,16 @@ public void testAmountClasses() {

public void testAmountClass(Class type) {
ClassTester.testImplementsInterface(type, MonetaryAmount.class);
ClassTester.testImmutable(type);
ClassTester.testSerializable(type);
ClassTester.testComparable(type);
ClassTester.testHasPublicMethod(type, type,
"add", MonetaryAmount.class);
ClassTester.testHasNotPublicMethod(type, type,
"add", Number.class);
ClassTester.testHasPublicMethod(type, type,
"subtract", MonetaryAmount.class);
ClassTester.testHasNotPublicMethod(type, type,
"subtract", Number.class);
ClassTester.testHasNotPublicMethod(type, byte.class,
"byteValue");
ClassTester.testHasNotPublicMethod(type, Byte.class,
"byteValue");
ClassTester.testHasNotPublicMethod(type, int.class,
"intValue");
ClassTester.testHasNotPublicMethod(type, Integer.class,
"intValue");
ClassTester.testHasNotPublicMethod(type, int.class,
"intValueExact");
ClassTester.testHasNotPublicMethod(type, Integer.class,
"intValueExact");
ClassTester.testHasNotPublicMethod(type, short.class,
"shortValue");
ClassTester.testHasNotPublicMethod(type, Short.class,
"shortValue");
ClassTester.testHasNotPublicMethod(type, short.class,
"shortValueExact");
ClassTester.testHasNotPublicMethod(type, Short.class,
"shortValueExact");
ClassTester.testHasNotPublicMethod(type, float.class,
"floatValue");
ClassTester.testHasNotPublicMethod(type, Float.class,
"floatValue");
ClassTester.testHasPublicMethod(type, double.class,
"doubleValue");
ClassTester.testHasPublicMethod(type, long.class,
"longValue");
ClassTester.testHasPublicMethod(type, long.class,
"longValueExact");
ClassTester.testHasPublicMethod(type, Number.class,
"asNumber");
// ClassTester.testHasPublicMethod(type, Number.class,
// "asType");
// ClassTester.testHasPublicMethod(type, Number.class,
// "asType", Class.class);
// ClassTester.testHasPublicMethod(type, Object.class,
// "asType", Class.class, MonetaryAdjuster.class);

ClassTester.testHasPublicMethod(type, type,
"abs");
// ClassTester.testHasPublicStaticMethod(type, type,
// "from", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, type,
"divide", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, type,
"divide", Number.class);
// ClassTester.testHasPublicMethod(type, MonetaryAmount[].class,
// "divideAndRemainder", MonetaryAmount.class);
// ClassTester.testHasPublicMethod(type, type,
// "divideAndRemainder", Number.class);
ClassTester.testHasPublicMethod(type, type,
"divideToIntegralValue", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, type,
"divideToIntegralValue", Number.class);
ClassTester.testHasPublicMethod(type, Class.class,
"getNumberType");
ClassTester.testHasPublicMethod(type, int.class,
"getPrecision");
ClassTester.testHasPublicMethod(type, int.class,
"getScale");
ClassTester.testHasPublicMethod(type, boolean.class,
"isEqualTo", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, boolean.class,
"isGreaterThan", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, boolean.class,
"isGreaterThanOrEqualTo", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, boolean.class,
"isLessThan", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, boolean.class,
"isLessThanOrEqualTo", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, boolean.class,
"isNegative");
ClassTester.testHasPublicMethod(type, boolean.class,
"isNegativeOrZero");

ClassTester.testHasPublicMethod(type, boolean.class,
"isNotEqualTo", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, boolean.class,
"isPositive");
ClassTester.testHasPublicMethod(type, boolean.class,
"isPositiveOrZero");
ClassTester.testHasPublicMethod(type, boolean.class,
"isZero");
ClassTester.testHasPublicMethod(type, type,
"multiply", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, type,
"multiply", Number.class);
ClassTester.testHasPublicMethod(type, type,
"negate");
ClassTester.testHasPublicMethod(type, type,
"plus");
ClassTester.testHasPublicMethod(type, type,
"pow", int.class);
ClassTester.testHasPublicMethod(type, type,
"remainder", MonetaryAmount.class);
ClassTester.testHasPublicMethod(type, type,
"remainder", Number.class);
ClassTester.testHasPublicMethod(type, type,
"scaleByPowerOfTen", int.class);
ClassTester.testHasPublicMethod(type, int.class,
"signum");
ClassTester.testHasPublicMethod(type, String.class,
"toEngineeringString");
ClassTester.testHasPublicMethod(type, String.class,
"toPlainString");
ClassTester.testHasPublicMethod(type, type,
"ulp");
ClassTester.testHasPublicMethod(type, type,
"with", Number.class);
ClassTester.testHasPublicMethod(type, type,
"with", MonetaryAdjuster.class);
ClassTester.testImmutableOpt(type);
ClassTester.testSerializableOpt(type);
ClassTester.testHasPublicStaticMethodOpt(type, type,
"from", MonetaryAdjuster.class);

MonetaryAmount amt = (MonetaryAmount) TCKTestSetup
.getTestConfiguration().create(type,
"CHF", Double.valueOf(1.50d));
ClassTester.testSerializable(amt);
ClassTester.testSerializableOpt(amt);
}

}
84 changes: 84 additions & 0 deletions src/main/java/org/javamoney/tck/util/ClassTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import java.lang.reflect.Modifier;
import java.util.Arrays;

import javax.money.MonetaryAdjuster;

import junit.framework.Assert;

import org.javamoney.tck.TCKValidationException;

public class ClassTester {

private static final StringBuffer warnings = new StringBuffer();

private ClassTester() {

}
Expand Down Expand Up @@ -124,6 +128,29 @@ public static void testHasPublicMethod(Class type, Class returnType,
for (Method m : current.getDeclaredMethods()) {
if (returnType.equals(returnType) &&
m.getName().equals(name) &&
((m.getModifiers() & Modifier.PUBLIC) != 0) &&
Arrays.equals(m.getParameterTypes(), paramTypes)) {
return;
}
}
current = current.getSuperclass();
}
throw new TCKValidationException(
"Class must implement method " + name + '('
+ Arrays.toString(paramTypes) + "): "
+ returnType.getName() + ", but does not: "
+ type.getName());
}

public static void testHasPublicStaticMethod(Class type, Class returnType,
String name, Class... paramTypes) {
Class current = type;
while (current != null) {
for (Method m : current.getDeclaredMethods()) {
if (returnType.equals(returnType) &&
m.getName().equals(name) &&
((m.getModifiers() & Modifier.PUBLIC) != 0) &&
((m.getModifiers() & Modifier.STATIC) != 0) &&
Arrays.equals(m.getParameterTypes(), paramTypes)) {
return;
}
Expand Down Expand Up @@ -166,6 +193,63 @@ public static void assertValue(Object value, String methodName,
InvocationTargetException {
Method m = instance.getClass().getDeclaredMethod(methodName);
Assert.assertEquals(value, m.invoke(instance));
}

public static boolean testImmutableOpt(Class type) {
try {
testImmutable(type);
return true;
} catch (Exception e) {
warnings.append("Recommendation failed: Class should be immutable: "
+ type.getName() + ", details: " + e.getMessage() + "\n");
return false;
}
}

public static boolean testSerializableOpt(Class type) {
try {
testSerializable(type);
return true;
} catch (Exception e) {
warnings.append("Recommendation failed: Class should be serializable: "
+ type.getName() + ", details: " + e.getMessage() + "\n");
return false;
}
}

public static boolean testHasPublicStaticMethodOpt(Class type,
Class returnType,
String methodName, Class... paramTypes) {
try {
testHasPublicStaticMethod(type, returnType, methodName, paramTypes);
return true;
} catch (Exception e) {
warnings.append("Recommendation failed: Missing method [public static "
+ methodName
+ '('
+ Arrays.toString(paramTypes) + "):" + returnType.getName()
+ "] on: "
+ type.getName() + "\n");
return false;
}
}

public static boolean testSerializableOpt(Object instance) {
try {
testSerializable(instance);
return true;
} catch (Exception e) {
warnings.append("Recommendation failed: Class is serializable, but serialization failed: "
+ instance.getClass().getName() + "\n");
return false;
}
}

public static void resetWarnings() {
warnings.setLength(0);
}

public static String getWarnings() {
return warnings.toString();
}
}

0 comments on commit 90fe55c

Please sign in to comment.