public void handleBlankCell(Parse cell, TypeAdapter a) { try { cell.addToBody(gray(a.toString(a.get()))); } catch (Exception e) { cell.addToBody(gray("error")); } }
private void compare() { if (typeAdapter.equals(expected, result)) { right(cell); } else { wrong(cell, typeAdapter.toString(result)); } }
public static TypeAdapter on(Fixture fixture, Method method, boolean isRegex) { TypeAdapter a = on(fixture, method.getReturnType()); a.target = fixture; a.method = method; a.isRegex = isRegex; return a; }
private void handleErrorInCell(TypeAdapter a, Parse cell) { try { Object result = a.invoke(); wrong(cell, a.toString(result)); } catch (IllegalAccessException e) { exception(cell, e); } catch (Exception e) { right(cell); } }
protected Map<Object, Object> cSort(List<?> list, int col) { TypeAdapter a = columnBindings[col].adapter; Map<Object, Object> result = new ConcurrentHashMap<Object, Object>(list.size()); for (Object row : list) { try { a.target = row; Object key = a.get(); bin(result, key, row); } catch (Exception e) { // surplus anything with bad keys, including null surplus.add(row); } } return result; }
/* Added by René Majewski */ @SuppressWarnings("hiding") public void run() throws Exception { Method method = method(1); Class<?> type = method.getParameterTypes()[0]; String text = cells.more.more.text(); Object args[] = {TypeAdapter.on(actor, type).parse(text)}; method.invoke(actor, args); }
public boolean equals(Object a, Object b) { int length = Array.getLength(a); if (length != Array.getLength(b)) return false; for (int i = 0; i < length; i++) { if (!componentAdapter.equals(Array.get(a, i), Array.get(b, i))) return false; } return true; }
public Object parse(String s) throws Exception { StringTokenizer t = new StringTokenizer(s, ","); Object array = Array.newInstance(componentType, t.countTokens()); for (int i = 0; t.hasMoreTokens(); i++) { Array.set(array, i, componentAdapter.parse(t.nextToken().trim())); } return array; }
protected Map<Object, Object> eSort(List<?> list, int col) { TypeAdapter a = columnBindings[col].adapter; Map<Object, Object> result = new ConcurrentHashMap<Object, Object>(list.size()); for (Object o : list) { Parse row = (Parse) o; Parse cell = row.parts.at(col); try { Object key = a.parse(cell.text()); bin(result, key, row); } catch (Exception e) { exception(cell, e); for (Parse rest = cell.more; rest != null; rest = rest.more) { ignore(rest); } } } return result; }
public String toString(Object o) { if (o == null) return ""; int length = Array.getLength(o); StringBuffer b = new StringBuffer(5 * length); for (int i = 0; i < length; i++) { b.append(componentAdapter.toString(Array.get(o, i))); if (i < (length - 1)) { b.append(", "); } } return b.toString(); }
protected void check(List<?> eList, List<?> cList) { if (eList.isEmpty()) { surplus.addAll(cList); return; } if (cList.isEmpty()) { missing.addAll(eList); return; } Parse row = (Parse) eList.remove(0); Parse cell = row.parts; Object obj = cList.remove(0); for (int i = 0; i < columnBindings.length && cell != null; i++) { TypeAdapter a = columnBindings[i].adapter; if (a != null) { a.target = obj; } check(cell, a); cell = cell.more; } check(eList, cList); }
private Object parseCell() { try { return typeAdapter.isRegex ? cell.text() : typeAdapter.parse(cell.text()); } // Ignore parse exceptions, print non-parse exceptions, // return null so that compareCellToResult tries relational matching. catch (NumberFormatException e) { } catch (ParseException e) { } catch (Exception e) { e.printStackTrace(); } return new Unparseable(); }
private void compareCellToResult(TypeAdapter a, Parse theCell) { typeAdapter = a; cell = theCell; try { result = typeAdapter.get(); expected = parseCell(); if (expected instanceof Unparseable) tryRelationalMatch(); else compare(); } catch (Exception e) { exception(cell, e); } }
protected Parse buildCells(Object row) { if (row == null) { Parse nil = new Parse("td", "null", null, null); nil.addToTag(" colspan=" + columnBindings.length); return nil; } Parse root = new Parse(null, null, null, null); Parse next = root; for (Binding columnBinding : columnBindings) { next = next.more = new Parse("td", " ", null, null); TypeAdapter a = columnBinding.adapter; if (a == null) { ignore(next); } else { try { a.target = row; next.body = gray(escape(a.toString(a.get()))); } catch (Exception e) { exception(next, e); } } } return root.more; }
public void init(Fixture target, Class<?> type) { super.init(target, type); componentType = type.getComponentType(); componentAdapter = on(target, componentType); }
public static TypeAdapter on(Fixture fixture, Field field) { TypeAdapter a = on(fixture, field.getType()); a.target = fixture; a.field = field; return a; }
public void check() throws Exception { TypeAdapter adapter = TypeAdapter.on(actor, method(0)); check(cells.more.more, adapter); }
public static TypeAdapter on(Fixture target, Class<?> type) { TypeAdapter a = adapterFor(type); a.init(target, type); return a; }