julia_v_iluhina

Untitled

Oct 22nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. public class SmartCollectionFoundByConditionElement extends AbstractSmartElement {
  2.  
  3.     @Override
  4.     public WebElement fetchWrappedEntity() {
  5.         SmartElement element = null;
  6.         /*
  7.             зачем переменная
  8.         */
  9. *********************************
  10. @Override
  11.     public WebElement fetchWrappedEntity() {
  12.         WebElement element = null;
  13.  
  14.         try {
  15.             element = parentCollection.getWrappedEntity().get(index);
  16.         } catch (SmartСollectionIndexOutOfBoundsException e) {
  17.         /*
  18.             что тут за эксепшен надо ловить
  19.             вместо какого эксепшена мы собрались кидать SmartСollectionIndexOutOfBoundsException?
  20.         */
  21.         }
  22.             throw new SmartСollectionIndexOutOfBoundsException(element.toString());
  23.             /*
  24.                 стоп-стоп
  25.                 что мы ищем - описывается - самим лейзи-элементом = this
  26.  
  27.                 как думаешь - в чем разница -
  28.                 this.toString() или element.toString()
  29.                 ?
  30.             */
  31.         }
  32.     return element;
  33.     }
  34. ********************************************
  35. public abstract class AbstractCondition<V>  implements Condition<V>, DescribesResult {
  36.  
  37.  ....
  38.  
  39.     public V apply(SmartEntity<V> smartEntity) {
  40.         this.smartEntity = smartEntity;
  41.         V wrappedEntity = smartEntity.getWrappedEntity();
  42.  
  43.         if (check(wrappedEntity)) {
  44.             return wrappedEntity;
  45.         } else {
  46.             throw new WebDriverAssertionException(getClass().getSimpleName());
  47.         }
  48.         /*
  49.             а если после if-блока
  50.             сразу без всяких else
  51.             кидать исключение
  52.  
  53.             будет хуже?
  54.  
  55.             мы же вели попали в if-блок
  56.             мы по return выйдем
  57.  
  58.             соответственно - можно обойтись без else
  59.         */
  60.  
  61.     }
  62. ***********************************
  63.     public class SmartFilteredByConditionCollection extends AbstractSmartCollection {
  64.  
  65.        ...
  66.         @Override
  67.         public List<WebElement> getWrappedEntity() {
  68.             List<WebElement> innerCollection = new ArrayList<>();
  69.  
  70.             for (SmartElement smartElement:collection) {
  71.                 try {
  72.                     if (condition.apply(smartElement) != null) {
  73.                         innerCollection.add(smartElement);
  74.                     }
  75.                 } catch (IndexOutOfBoundsException | WebDriverException e) {
  76.                 }
  77.                 /*
  78.                     зато тут ловишь IndexOutOfBoundsException )
  79.                     странно)
  80.                 */
  81.             }
  82.  
  83.             return innerCollection;
  84.         }
  85.     }
  86. ********************************************
  87.  public V until(Condition<V> condition, long timeout) {
  88.      ...
  89.             } catch (IndexOutOfBoundsException | WebDriverException e) {
  90.                 lastError = e;
  91.             }
  92.             /*
  93.                      и тут ловишь IndexOutOfBoundsException )
  94.             */
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment