Skip to content

Commit

Permalink
Preparer test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
LoayGhreeb committed Jul 25, 2024
1 parent 1e82f6e commit c15156e
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/test/java/com/tobiasdiez/easybind/MappedBackedListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.tobiasdiez.easybind;

import java.util.List;

import javafx.beans.Observable;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import com.tobiasdiez.easybind.SortedList.SortedList;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MappedBackedListTest {

@Test
public void testUnSortedListUpdatesWithMappedBackedList() {
ObservableList<IntegerProperty> list = FXCollections.observableArrayList(number -> new Observable[]{number});
ObservableList<Integer> mappedList = EasyBind.mapBacked(list, IntegerProperty::get);
SortedList<Integer> sortedList = new SortedList<>(mappedList);

IntegerProperty number = new SimpleIntegerProperty(1);
list.add(number);

assertEquals(1, sortedList.get(0));

number.set(2);

assertEquals(2, sortedList.get(0));
}


@Test
public void testSortedListUpdatesWithMappedBackedList() {
ObservableList<IntegerProperty> list = FXCollections.observableArrayList(number -> new Observable[]{number});
ObservableList<Integer> mappedList = EasyBind.mapBacked(list, IntegerProperty::get);
SortedList<Integer> sortedList = new SortedList<>(mappedList, Integer::compareTo);

IntegerProperty num1 = new SimpleIntegerProperty(1);
IntegerProperty num2 = new SimpleIntegerProperty(3);
IntegerProperty num3 = new SimpleIntegerProperty(2);

list.addAll(num1, num2, num3);

// list= [1, 3, 2], sortedList = [1, 2, 3]
assertEquals(List.of(1, 2, 3), sortedList);

num2.set(4);

// list = [1, 4, 2], sortedList = [1, 2, 4]
assertEquals(List.of(1, 2, 4), sortedList);
}
}

0 comments on commit c15156e

Please sign in to comment.