sft.DisplayedContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SimpleFunctionalTest Show documentation
Show all versions of SimpleFunctionalTest Show documentation
A JUnit extension to easily adopt functional testing and acceptance testing
/*******************************************************************************
* Copyright (c) 2013, 2014 Sylvain Lézier.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sylvain Lézier - initial implementation
*******************************************************************************/
package sft;
import java.lang.reflect.Field;
import java.util.ArrayList;
public class DisplayedContext {
private final ArrayList fields;
private final Object object;
public DisplayedContext(Object object, ArrayList fields) {
this.object = object;
this.fields = fields;
}
public ArrayList getText() {
ArrayList results = new ArrayList();
for (Field field : fields) {
try {
field.setAccessible(true);
Object value = field.get(object);
if (value != null) {
results.add(value.toString());
field.set(object,null);
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return results;
}
}