@Test
  public void firstNAdd() {
    Transformers.<MyObject>firstN(Properties.constant(1)).transform(fromList, toList);

    fromList.add(new MyObject("x"));
    fromList.add(0, new MyObject("y"));

    assertEquals("[y]", toList.toString());
  }
  @Test
  public void listFilterInitial() {
    fromList.add(new MyObject("a"));
    fromList.add(new MyObject("b"));

    Transformers.listFilter(IS_A).transform(fromList, toList);

    assertEquals("[a]", "" + toList);
  }
  @Test
  public void filterInitial() {
    from.add(new MyObject("a"));
    from.add(new MyObject("b"));

    Transformers.filter(IS_A).transform(from, to);

    assertEquals("[a]", "" + to);
  }
  @Test
  public void targetHasNoMoreThanNElements() {
    ObservableSingleItemList<MyObject> targetList = new ObservableSingleItemList<>();
    fromList.add(new MyObject("x"));

    Transformers.<MyObject>firstN(Properties.constant(1)).transform(fromList, targetList);
    fromList.add(0, new MyObject("y"));

    assertEquals("[y]", targetList.toString());
  }
  @Test
  public void firstNInitial() {
    fromList.add(new MyObject("a"));
    fromList.add(new MyObject("b"));
    fromList.add(new MyObject("c"));

    Transformers.<MyObject>firstN(Properties.constant(2)).transform(fromList, toList);

    assertEquals("[a, b]", toList.toString());
  }
 private Transformer<ObservableCollection<MyObject>, ObservableList<MyObject>>
     createSortTransformer() {
   return Transformers.sortBy(
       new Function<MyObject, ReadableProperty<String>>() {
         @Override
         public Property<String> apply(MyObject input) {
           return input.name;
         }
       });
 }
  @Test
  public void addFirstHandling() {
    Transformers.<MyObject, MyObject, MyObject>addFirst(new MyObject("z"))
        .transform(fromList, toList);

    fromList.add(new MyObject("a"));
    fromList.add(new MyObject("c"));
    fromList.add(new MyObject("b"));

    assertEquals("[z, a, c, b]", toList.toString());
  }
  @Test
  public void filterHandling() {
    Transformers.filter(IS_A).transform(from, to);
    MyObject objectB = new MyObject("b");

    from.add(new MyObject("a"));
    from.add(objectB);
    from.remove(objectB);

    assertEquals("[a]", "" + to);
  }
Beispiel #9
0
 /** TODO run tests in parallel */
 public static void compareFromDifferentFoldersByExtension(
     final File sourceFolder,
     final File targetFolder,
     final String extension,
     final ResourcePostProcessor processor)
     throws IOException {
   compareFromDifferentFolders(
       sourceFolder,
       targetFolder,
       new WildcardFileFilter("*." + extension),
       Transformers.noOpTransformer(),
       processor);
 }
 @Before
 public void setup() {
   from = new ObservableArrayList<>();
   to = new ObservableArrayList<>();
   select =
       Transformers.selectList(
           new Function<Integer, String>() {
             @Override
             public String apply(Integer input) {
               return Integer.toString(input);
             }
           });
 }
  @Test
  public void firstNRemove() {
    fromList.add(new MyObject("a"));
    fromList.add(new MyObject("b"));
    fromList.add(new MyObject("c"));

    Transformers.<MyObject>firstN(Properties.constant(1)).transform(fromList, toList);

    fromList.remove(2);
    fromList.remove(0);

    assertEquals("[b]", toList.toString());
  }
 private Transformation<ObservableCollection<MyObject>, ObservableCollection<MyObject>>
     initForFlattenTest() {
   to.add(new MyObject("b"));
   to.add(new MyObject("c"));
   Function<MyObject, ObservableCollection<MyObject>> selector =
       new Function<MyObject, ObservableCollection<MyObject>>() {
         @Override
         public ObservableCollection<MyObject> apply(MyObject source) {
           return to;
         }
       };
   return Transformers.flatten(selector).transform(from, to);
 }
  @Test
  public void flattenWithTransformer() {
    Function<MyObject, ObservableCollection<String>> f =
        new Function<MyObject, ObservableCollection<String>>() {
          @Override
          public ObservableCollection<String> apply(MyObject input) {
            ObservableHashSet<String> s = new ObservableHashSet<>();
            s.add(input.name.get() + "1");
            s.add(input.name.get() + "2");
            return s;
          }
        };

    Transformer<ObservableCollection<String>, ObservableCollection<MyObject>> t =
        Transformers.oneToOne(
            new Function<String, MyObject>() {
              @Override
              public MyObject apply(String input) {
                return new MyObject(input);
              }
            },
            new Function<MyObject, String>() {
              @Override
              public String apply(MyObject input) {
                return input.name.get();
              }
            });

    Transformer<ObservableCollection<MyObject>, ObservableCollection<MyObject>> flatten =
        Transformers.flatten(f, t);
    from.add(new MyObject("a"));

    flatten.transform(from, to);
    assertTrue(to.size() == 2);

    from.add(new MyObject("b"));
    assertTrue(to.size() == 4);
  }
Beispiel #14
0
 /**
  * Compares files with the same name from sourceFolder against it's counterpart in targetFolder,
  * but allows source and target files to have different extensions. TODO run tests in parallel
  */
 public static void compareFromDifferentFoldersByName(
     final File sourceFolder,
     final File targetFolder,
     final String srcExtension,
     final String targetExtension,
     final ResourcePostProcessor processor)
     throws IOException {
   compareFromDifferentFolders(
       sourceFolder,
       targetFolder,
       new WildcardFileFilter("*." + srcExtension),
       Transformers.extensionTransformer("css"),
       processor);
 }
  @Test
  public void firstNdecreaseN() {
    fromList.add(new MyObject("a"));
    fromList.add(new MyObject("b"));
    fromList.add(new MyObject("c"));

    ValueProperty<Integer> prop = new ValueProperty<>(2);

    Transformers.<MyObject>firstN(prop).transform(fromList, toList);

    prop.set(0);

    assertEquals("[]", toList.toString());
  }
  @Test
  public void addPlaceHolderIfEmpty() {
    Transformers.withPlaceHoldersIfEmpty(
            new Supplier<MyObject>() {
              @Override
              public MyObject get() {
                return new MyObject("p");
              }
            })
        .transform(fromList, toList);

    assertEquals("[p]", toList.toString());

    fromList.add(new MyObject("z"));
    assertEquals("[z]", toList.toString());

    fromList.clear();
    assertEquals("[p]", toList.toString());
  }
Beispiel #17
0
 /**
  * Process and compare all the files from the sourceFolder and compare them with the files from
  * the targetFolder.
  */
 public static void compareFromDifferentFolders(
     final File sourceFolder, final File targetFolder, final ResourcePreProcessor processor)
     throws IOException {
   compareFromDifferentFolders(
       sourceFolder, targetFolder, TrueFileFilter.TRUE, Transformers.noOpTransformer(), processor);
 }