X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=test%2Fnet%2Fsf%2Fopenrocket%2Ffile%2Frocksim%2FRocksimTestBase.java;h=a23ee73a200f1a816f344f71219e861ac5803a8d;hb=f8f9a3cc430a2d4893de6157e483889439f33cc3;hp=394d385fb34964411ea873cdcbd638bc6e2aa012;hpb=50f171ab51eae5c91117ebdc9b7a0d43d764ddb5;p=debian%2Fopenrocket diff --git a/test/net/sf/openrocket/file/rocksim/RocksimTestBase.java b/test/net/sf/openrocket/file/rocksim/RocksimTestBase.java index 394d385f..a23ee73a 100644 --- a/test/net/sf/openrocket/file/rocksim/RocksimTestBase.java +++ b/test/net/sf/openrocket/file/rocksim/RocksimTestBase.java @@ -3,102 +3,95 @@ */ package net.sf.openrocket.file.rocksim; -import junit.framework.TestCase; - import java.lang.reflect.Field; +import java.util.List; +import junit.framework.TestCase; import net.sf.openrocket.rocketcomponent.RocketComponent; /** * A base class for the Rocksim tests. Includes code from the junitx.addons project. */ public abstract class RocksimTestBase extends TestCase { - - /** - * Test constructor. - * - * @param name the name of the test to run. - */ - public RocksimTestBase(String name) { - super(name); - } - - public void assertContains (RocketComponent child, RocketComponent[] components) { - for (int i = 0; i < components.length; i++) { - if (components[i].equals(child)) { - return; - } - } - fail("Component array did not contain child."); - } - - /** - * Returns the value of the field on the specified object. The name - * parameter is a String specifying the simple name of the - * desired field.

- * - * The object is first searched for any matching field. If no matching - * field is found, the superclasses are recursively searched. - * - * @exception NoSuchFieldException if a field with the specified name is - * not found. - */ - public static Object getField(Object object, - String name) - throws NoSuchFieldException { - if (object == null) { - throw new IllegalArgumentException("Invalid null object argument"); - } - for (Class cls = object.getClass(); - cls != null; - cls = cls.getSuperclass()) { - try { - Field field = cls.getDeclaredField(name); - field.setAccessible(true); - return field.get(object); - } catch (Exception ex) { - /* in case of an exception, we will throw a new - * NoSuchFieldException object */ - ; - } - } - throw new NoSuchFieldException("Could get value for field " + - object.getClass().getName() + "." + name); - } - - /** - * Returns the value of the field on the specified class. The name - * parameter is a String specifying the simple name of the - * desired field.

- * - * The class is first searched for any matching field. If no matching - * field is found, the superclasses are recursively searched. - * - * @exception NoSuchFieldException if a field with the specified name is - * not found. - */ - public static Object getField(Class cls, - String name) - throws NoSuchFieldException { - if (cls == null) { - throw new IllegalArgumentException("Invalid null cls argument"); - } - Class base = cls; - while (base != null) { - try { - Field field = base.getDeclaredField(name); - field.setAccessible(true); - return field.get(base); - } catch (Exception ex) { - /* in case of an exception, we will throw a new - * NoSuchFieldException object */ - ; - } - base = base.getSuperclass(); - } - throw new NoSuchFieldException("Could get value for static field " + - cls.getName() + "." + name); - } - + + /** + * Test constructor. + * + * @param name the name of the test to run. + */ + public RocksimTestBase(String name) { + super(name); + } + + public void assertContains(RocketComponent child, List components) { + assertTrue("Components did not contain child", components.contains(child)); + } + + /** + * Returns the value of the field on the specified object. The name + * parameter is a String specifying the simple name of the + * desired field.

+ * + * The object is first searched for any matching field. If no matching + * field is found, the superclasses are recursively searched. + * + * @exception NoSuchFieldException if a field with the specified name is + * not found. + */ + public static Object getField(Object object, + String name) + throws NoSuchFieldException { + if (object == null) { + throw new IllegalArgumentException("Invalid null object argument"); + } + for (Class cls = object.getClass(); cls != null; cls = cls.getSuperclass()) { + try { + Field field = cls.getDeclaredField(name); + field.setAccessible(true); + return field.get(object); + } catch (Exception ex) { + /* in case of an exception, we will throw a new + * NoSuchFieldException object */ + ; + } + } + throw new NoSuchFieldException("Could get value for field " + + object.getClass().getName() + "." + name); + } + + /** + * Returns the value of the field on the specified class. The name + * parameter is a String specifying the simple name of the + * desired field.

+ * + * The class is first searched for any matching field. If no matching + * field is found, the superclasses are recursively searched. + * + * @exception NoSuchFieldException if a field with the specified name is + * not found. + */ + public static Object getField(Class cls, + String name) + throws NoSuchFieldException { + if (cls == null) { + throw new IllegalArgumentException("Invalid null cls argument"); + } + Class base = cls; + while (base != null) { + try { + Field field = base.getDeclaredField(name); + field.setAccessible(true); + return field.get(base); + } catch (Exception ex) { + /* in case of an exception, we will throw a new + * NoSuchFieldException object */ + ; + } + base = base.getSuperclass(); + } + throw new NoSuchFieldException("Could get value for static field " + + cls.getName() + "." + name); + } + }