Remove use of Comparator to ease ECJ compilation

This commit is contained in:
Andy Clement
2014-03-06 13:27:28 -08:00
parent ee3b3acc2f
commit 9346b7749b
4 changed files with 25 additions and 36 deletions

View File

@@ -29,7 +29,6 @@ import org.springsource.loaded.test.infra.ResultException;
import org.springsource.loaded.testgen.ExploreAllChoicesRunner;
import org.springsource.loaded.testgen.GenerativeSpringLoadedTest;
import org.springsource.loaded.testgen.RejectedChoice;
import org.springsource.loaded.testgen.ToStringComparator;
/**
@@ -84,7 +83,10 @@ public class FieldGetAnnotationTest extends GenerativeSpringLoadedTest {
Field[] fields = ReflectiveInterceptor.jlClassGetDeclaredFields(targetClass);
//To be deterministic we must sort these fields in a predictable fashion:
Arrays.sort(fields, new ToStringComparator());
sort(fields);
// Arrays.sort(fields, new ToStringComparator());
field = choice(fields);
toStringValue.append(field);

View File

@@ -29,7 +29,6 @@ import org.springsource.loaded.test.infra.ResultException;
import org.springsource.loaded.testgen.ExploreAllChoicesRunner;
import org.springsource.loaded.testgen.GenerativeSpringLoadedTest;
import org.springsource.loaded.testgen.RejectedChoice;
import org.springsource.loaded.testgen.ToStringComparator;
/**
@@ -93,7 +92,8 @@ public class MethodGetAnnotationTest extends GenerativeSpringLoadedTest {
Method[] methods = ReflectiveInterceptor.jlClassGetDeclaredMethods(targetClass);
//To be deterministic we must sort these methods in a predictable fashion:
Arrays.sort(methods, new ToStringComparator());
// Arrays.sort(methods, new ToStringComparator());
sort(methods);
method = choice(methods);
toStringValue.append(method);

View File

@@ -145,7 +145,8 @@ public abstract class GenerativeSpringLoadedTest extends GenerativeTest {
//To be deterministic we must sort these methods in a predictable fashion! Otherwise the test
//may compare results from one method in the first run with those of another method in the second
//run and fail.
Arrays.sort(methods, new ToStringComparator());
sort(methods);
// Arrays.sort(methods, new ToStringComparator());
Method method = choice(methods);
toStringValue.append(method);
return method;
@@ -169,7 +170,8 @@ public abstract class GenerativeSpringLoadedTest extends GenerativeTest {
break;
}
//To be deterministic we must sort these in a predictable fashion!
Arrays.sort(fields, new ToStringComparator());
// Arrays.sort(fields, new ToStringComparator());
sort(fields);
Field f = choice(fields);
toStringValue.append(f.getName());
try {
@@ -196,7 +198,8 @@ public abstract class GenerativeSpringLoadedTest extends GenerativeTest {
protected Constructor<?> targetConstructorFrom(Class<?> clazz) throws RejectedChoice {
Constructor<?>[] constructors = ReflectiveInterceptor.jlClassGetDeclaredConstructors(clazz);
//To be deterministic we must sort these methods in a predictable fashion!
Arrays.sort(constructors, new ToStringComparator());
//Arrays.sort(constructors, new ToStringComparator());
sort(constructors);
Constructor<?> c = choice(constructors);
toStringValue.append(c);
return c;
@@ -294,4 +297,17 @@ public abstract class GenerativeSpringLoadedTest extends GenerativeTest {
return result;
}
protected void sort(Object[] os) {
for (int i = 0; i < os.length; i++) {
for (int x = 1; x < os.length - i; x++) {
if (os[x - 1].toString().compareTo(os[x].toString())>0) {
Object temp = os[x - 1];
os[x - 1] = os[x];
os[x] = temp;
}
}
}
}
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright 2010-2012 VMware and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springsource.loaded.testgen;
import java.util.Comparator;
/**
* Can be used for comparing and sorting things based on their toString value
*/
public class ToStringComparator implements Comparator<Object> {
public int compare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
}
}